public async Task <IActionResult> FetchChallengesAsync( EnumGame game = EnumGame.None, EnumChallengeState state = EnumChallengeState.None, bool includeMatches = false ) { var fetchDoxatagsRequest = new FetchDoxatagsRequest(); var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest); var fetchChallengePayoutsRequest = new FetchChallengePayoutsRequest(); var fetchChallengePayoutsResponse = await _cashierServiceClient.FetchChallengePayoutsAsync(fetchChallengePayoutsRequest); var fetchChallengesRequest = new FetchChallengesRequest { Game = game, State = state, IncludeMatches = includeMatches }; var fetchChallengesResponse = await _challengesServiceClient.FetchChallengesAsync(fetchChallengesRequest); return(this.Ok(ChallengeMapper.Map(fetchChallengesResponse.Challenges, fetchChallengePayoutsResponse.Payouts, fetchDoxatagsResponse.Doxatags))); }
public async Task <IActionResult> CreateChallengeAsync([FromBody] Requests.CreateChallengeRequest request) { var fetchDoxatagsRequest = new FetchDoxatagsRequest(); var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest); var findChallengeScoringRequest = new FindChallengeScoringRequest { Game = request.Game }; var findChallengeScoringResponse = await _gameServiceClient.FindChallengeScoringAsync(findChallengeScoringRequest); var createChallengeRequest = new CreateChallengeRequest { Name = request.Name, Game = request.Game, BestOf = request.BestOf, Entries = request.Entries, Duration = request.Duration, Scoring = findChallengeScoringResponse.Scoring }; var createChallengeResponse = await _challengesServiceClient.CreateChallengeAsync(createChallengeRequest); try { var createChallengePayoutRequest = new CreateChallengePayoutRequest { ChallengeId = createChallengeResponse.Challenge.Id, PayoutEntries = createChallengeResponse.Challenge.Entries / 2, // TODO EntryFee = new CurrencyDto { Amount = request.EntryFee.Amount, Type = request.EntryFee.Type } }; var createChallengePayoutResponse = await _cashierServiceClient.CreateChallengePayoutAsync(createChallengePayoutRequest); return(this.Ok(ChallengeMapper.Map(createChallengeResponse.Challenge, createChallengePayoutResponse.Payout, fetchDoxatagsResponse.Doxatags))); } catch (RpcException exception) { var deleteChallengeRequest = new DeleteChallengeRequest { ChallengeId = createChallengeResponse.Challenge.Id }; await _challengesServiceClient.DeleteChallengeAsync(deleteChallengeRequest); throw exception.Capture(); } }
public override async Task <FetchDoxatagsResponse> FetchDoxatags(FetchDoxatagsRequest request, ServerCallContext context) { var doxatags = await _doxatagService.FetchDoxatagsAsync(); var response = new FetchDoxatagsResponse { Doxatags = { doxatags.Select(MapDoxatag) } }; return(context.Ok(response, string.Empty)); }
public async Task <IActionResult> RegisterChallengeParticipantAsync(string challengeId) { var participantId = new ParticipantId(); var findChallengeRequest = new FindChallengeRequest { ChallengeId = challengeId }; var findChallengeResponse = await _challengesServiceClient.FindChallengeAsync(findChallengeRequest); var findPlayerGameCredentialRequest = new FindPlayerGameCredentialRequest { Game = findChallengeResponse.Challenge.Game }; var findPlayerGameCredentialResponse = await _gameServiceClient.FindPlayerGameCredentialAsync(findPlayerGameCredentialRequest); var fetchDoxatagsRequest = new FetchDoxatagsRequest(); var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest); var findChallengePayoutRequest = new FindChallengePayoutRequest { ChallengeId = challengeId }; var challengePayoutResponse = await _cashierServiceClient.FindChallengePayoutAsync(findChallengePayoutRequest); var createTransactionRequest = new CreateTransactionRequest { Custom = new CustomTransaction { Type = EnumTransactionType.Charge, Currency = challengePayoutResponse.Payout.EntryFee }, Metadata = { new Dictionary <string, string> { [nameof(ChallengeId)] = challengeId, [nameof(ParticipantId)] = participantId } } }; var createTransactionResponse = await _cashierServiceClient.CreateTransactionAsync(createTransactionRequest); try { var registerChallengeParticipantRequest = new RegisterChallengeParticipantRequest { ChallengeId = challengeId, GamePlayerId = findPlayerGameCredentialResponse.Credential.PlayerId, ParticipantId = participantId }; var participant = await _challengesServiceClient.RegisterChallengeParticipantAsync(registerChallengeParticipantRequest); return(this.Ok(ChallengeMapper.Map(challengePayoutResponse.Payout.ChallengeId, participant.Participant, fetchDoxatagsResponse.Doxatags))); } catch (RpcException exception) { var deleteTransactionRequest = new DeleteTransactionRequest { TransactionId = createTransactionResponse.Transaction.Id }; await _cashierServiceClient.DeleteTransactionAsync(deleteTransactionRequest); throw exception.Capture(); } }