Exemplo n.º 1
0
        public async Task <PostCreateResponse> PostCreate(
            [FromBody] PostCreateRequest request,
            [FromServices] RegistrationService registrationService
            )
        {
            using var transaction = transactionManager.BeginTransaction();
            var now      = DateTimeOffset.Now;
            var playerId = await registrationService.RegisterAsync(request.DeviceId, request.PlayerUid, request.Name, now);

            var res = new PostCreateResponse
            {
                // TODO: 難読化
                Id = playerId,
            };
            await transaction.Commit();

            return(res);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddMessage(PostCreateRequest message)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var result = new PostCreateResponse {
                Succeeded = true
            };

            var user = _aspNetUser.GetUserEmail();

            var post = new Post(message.Message, user);

            if (!post.IsCommand())
            {
                var response = await _postService.PostMessage(post);

                if (!response.Succeeded)
                {
                    foreach (var error in response.ResponseResult.Errors.Messages)
                    {
                        AddOperationError(error);
                    }
                }
                result = response;
            }

            var posts = await _postService.GetPosts();

            await _hub.Clients.All.SendAsync("ReceiveMessage", posts);

            if (post.IsCommand())
            {
                _producerService.Produce(post).ConfigureAwait(false);
            }

            return(CustomResponse(result));
        }