public ActionResult <PostListResponse> Search([FromQuery] PostSearchRequest searchRequest) { var posts = _posts.Search(searchRequest); var postCount = _posts.Count(searchRequest); return(PostListResponse.Create(searchRequest, posts, postCount)); }
public async Task <PostListResponse> GetPostListAsync(int board, int count, string after, CancellationToken cancellationToken) { ValidateStrictlyPostiveInteger(board, nameof(board)); ValidateStrictlyPostiveInteger(count, nameof(count)); count = Math.Min(count, 50); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Format(_postListAfterEndpoint, board, _appId, count, _locale.Value, after)); HttpResponseMessage response = await _http.SendAsync(request, cancellationToken); if (!response.IsSuccessStatusCode) { await HandleNonSuccessStatusCodeAsync(response); } string responseText = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseText) || string.IsNullOrWhiteSpace(responseText)) { throw new UnkownErrorException(); } dynamic responseTextDynamic = JsonConvert.DeserializeObject <dynamic>(responseText); if (responseTextDynamic == null || (responseTextDynamic != null && responseTextDynamic["data"] == null)) { throw new UnkownErrorException(); } PostListResponse postListResponse = JsonConvert.DeserializeObject <PostListResponse>(responseText); if (postListResponse == null) { throw new UnmappableResponseException(); } return(postListResponse); }