Exemplo n.º 1
0
        public async Task <QueryResultDTO <PostDTO> > Handle(GetBlogQueryCommand request, CancellationToken ct)
        {
            var query = new QueryObject()
            {
                Search          = null,
                SearchBy        = null,
                Filters         = null,
                SortBy          = "DateCreated",
                IsSortAscending = false,
                Page            = request.Page,
                PageSize        = request.PageSize
            };

            var result = await postRepository.GetQueryResultAsync(query, ct, (Post p) => new PostDTO
            {
                Id       = p.Id,
                Title    = p.Title,
                Category = p.Category == null ? null : new CategoryDTO()
                {
                    Id = p.Category.Id, Name = p.Category.Name
                },
                ShortContent = p.ShortContent,
                DateCreated  = p.DateCreated
            });

            return(new QueryResultDTO <PostDTO>()
            {
                TotalItems = result.TotalItems,
                Items = result.Items
            });
        }
 public async Task <IActionResult> GetBlogPosts(GetBlogQueryCommand command)
 {
     return(Ok(await mediator.Send(command)));
 }