Пример #1
0
        public GetPostResponse GetPostByUrlFriendlyTitle(string urlFriendlyTitle)
        {
            var result   = _repository.GetPostByUrlFriendlyTitle(urlFriendlyTitle);
            var response = new GetPostResponse
            {
                Post    = result.IsOk ? result.Data : null,
                AllTags = ListAllTags()
            };

            return(response);
        }
Пример #2
0
        public GetPostResponse GetPostByKey(Guid postKey)
        {
            var result   = _repository.GetPostByKey(postKey);
            var response = new GetPostResponse
            {
                Post    = result.IsOk ? result.Data : null,
                AllTags = ListAllTags()
            };

            return(response);
        }
Пример #3
0
        public async Task <GetPostResponse> GetPostAsync(GetPostRequest request)
        {
            var response = new GetPostResponse();

            var entity = await _postRepository.GetPostByUrlAsync(request.Url);

            if (entity == null)
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return(response);
            }

            response.Post = _postMapper.ToModel(entity);
            return(response);
        }
        public override Task <GetPostResponse> Get(GetPostRequest request, ServerCallContext context)
        {
            var post = _postService.Get(request.Id);

            if (post is null)
            {
                return(Task.FromResult <GetPostResponse>(null));
            }
            var response = new GetPostResponse
            {
                Post = new PostModel
                {
                    Id   = post.Id, CreatedAt = new DateTimeOffset(post.CreatedAt).ToUnixTimeSeconds(),
                    Name = post.Name
                }
            };

            return(Task.FromResult(response));
        }
Пример #5
0
        public async Task <GetPostResponse> GetPostFromIdAsync(int postId, string requesterId = null)
        {
            var entity = await _postRepository.GetPostFromIdAsync(postId);

            var response = new GetPostResponse();

            if (entity == null)
            {
                _logger.LogWarning($"Post with Id {postId} not found");
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return(response);
            }

            var postModel = _postMapper.ToModel(entity, requesterId);

            response.StatusCode = (int)HttpStatusCode.OK;
            response.Post       = postModel;

            return(response);
        }
Пример #6
0
        public GetPostResponse GetPostById(GetPostByIdRequest request)
        {
            GetPostResponse response = new GetPostResponse();

            response.StatusCode = 200;
            response.Errors     = new List <string>();
            var tags        = new List <string>();
            var tagEntities = _tagRepository.GetByPostId(request.PostId);

            foreach (var tag in tagEntities)
            {
                tags.Add(tag.Content);
            }
            var post = _postRepository.GetPostById(request.PostId);

            response.Post = new PostDTO()
            {
                Post           = post,
                Tags           = tags,
                AuthorUsername = _userRepository.GetUserById(post.UserId).Username,
            };
            return(response);
        }