Created
September 24, 2019 10:24
-
-
Save ntakouris/4c9847ed45c61d33772d35ccb09d32da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet(ApiRoutes.Posts.GetAll)] | |
[Cached(600)] | |
public async Task<IActionResult> GetAll([FromQuery] GetAllPostsQuery query, [FromQuery]PaginationQuery paginationQuery) | |
{ | |
var pagination = _mapper.Map<PaginationFilter>(paginationQuery); | |
var filter = _mapper.Map<GetAllPostsFilter>(query); | |
var posts = await _postService.GetPostsAsync(filter, pagination); | |
var postsResponse = _mapper.Map<List<PostResponse>>(posts); | |
if (pagination == null || pagination.PageNumber < 1 || pagination.PageSize < 1) | |
{ | |
return Ok(new PagedResponse<PostResponse>(postsResponse)); | |
} | |
var paginationResponse = PaginationHelpers.CreatePaginatedResponse(_uriService, pagination, postsResponse); | |
return Ok(paginationResponse); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment