public override async Task <SynchronizeChallengeResponse> SynchronizeChallenge(SynchronizeChallengeRequest request, ServerCallContext context) { var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>(); if (!await _challengeService.ChallengeExistsAsync(challengeId)) { throw context.NotFoundRpcException("Challenge not found."); } var challenge = await _challengeService.FindChallengeAsync(challengeId); var result = await _challengeService.SynchronizeChallengeAsync(challenge, new UtcNowDateTimeProvider()); if (result.IsValid) { var response = new SynchronizeChallengeResponse { Challenge = ChallengeProfile.Map(result.Response) }; return(context.Ok(response)); } throw context.FailedPreconditionRpcException(result); }
public override async Task <CreateChallengeResponse> CreateChallenge(CreateChallengeRequest request, ServerCallContext context) { // TODO: Validation... var result = await _challengeService.CreateChallengeAsync( new ChallengeName(request.Name), request.Game.ToEnumeration <Game>(), new BestOf(request.BestOf), new Entries(request.Entries), new ChallengeDuration(TimeSpan.FromDays(request.Duration)), new UtcNowDateTimeProvider(), new Scoring(request.Scoring.Items.OrderBy(item => item.Order).ToDictionary(item => item.StatName, item => item.StatWeighting))); if (result.IsValid) { var response = new CreateChallengeResponse { Challenge = ChallengeProfile.Map(result.Response) }; return(context.Ok(response)); } throw context.FailedPreconditionRpcException(result); }
public static async Task PublishChallengeStartedIntegrationEventAsync(this IServiceBusPublisher publisher, IChallenge challenge) { var integrationEvent = new ChallengeStartedIntegrationEvent { Challenge = ChallengeProfile.Map(challenge) }; await publisher.PublishAsync(integrationEvent); }
public static async Task PublishChallengeSynchronizedIntegrationEventAsync(this IServiceBusPublisher publisher, IChallenge challenge) { var integrationEvent = new ChallengeSynchronizedIntegrationEvent { ChallengeId = challenge.Id, Scoreboard = { challenge.Participants.Select(participant => ChallengeProfile.Map(challenge, participant)) } }; await publisher.PublishAsync(integrationEvent); }
public override async Task <SnapshotChallengeParticipantResponse> SnapshotChallengeParticipant( SnapshotChallengeParticipantRequest request, ServerCallContext context ) { var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>(); if (!await _challengeService.ChallengeExistsAsync(challengeId)) { throw context.NotFoundRpcException("Challenge not found."); } var challenge = await _challengeService.FindChallengeAsync(challengeId); var result = await _challengeService.SnapshotChallengeParticipantAsync( challenge, request.GamePlayerId.ParseStringId <PlayerId>(), new UtcNowDateTimeProvider(), scoring => request.Matches.Select( match => new Match( new GameUuid(match.GameUuid), new DateTimeProvider(match.GameCreatedAt.ToDateTime()), match.GameDuration.ToTimeSpan(), scoring.Map(match.Stats), new UtcNowDateTimeProvider())) .ToImmutableHashSet()); if (result.IsValid) { var response = new SnapshotChallengeParticipantResponse { Participant = ChallengeProfile.Map(challenge, result.Response) }; return(context.Ok(response)); } throw context.FailedPreconditionRpcException(result); }
public override async Task <RegisterChallengeParticipantResponse> RegisterChallengeParticipant( RegisterChallengeParticipantRequest request, ServerCallContext context ) { var httpContext = context.GetHttpContext(); var userId = httpContext.GetUserId(); var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>(); if (!await _challengeService.ChallengeExistsAsync(challengeId)) { throw context.NotFoundRpcException("Challenge not found."); } var challenge = await _challengeService.FindChallengeAsync(challengeId); var result = await _challengeService.RegisterChallengeParticipantAsync( challenge, userId, request.ParticipantId.ParseEntityId <ParticipantId>(), request.GamePlayerId.ParseStringId <PlayerId>(), new UtcNowDateTimeProvider()); if (result.IsValid) { var response = new RegisterChallengeParticipantResponse { Participant = ChallengeProfile.Map(challenge, result.Response) }; return(context.Ok(response)); } throw context.FailedPreconditionRpcException(result); }