|
1 | 1 | using Microsoft.AspNetCore.Mvc; |
2 | 2 | using Microsoft.Extensions.Logging; |
| 3 | +using NetCoreStack.Common; |
3 | 4 | using NetCoreStack.Proxy.Test.Contracts; |
4 | 5 | using Newtonsoft.Json; |
5 | 6 | using System; |
@@ -33,6 +34,51 @@ public async Task<IEnumerable<Post>> GetPostsAsync() |
33 | 34 | return items; |
34 | 35 | } |
35 | 36 |
|
| 37 | + /// <summary> |
| 38 | + /// CollectionResult Direct Stream Transport - Return the client without Deserialization |
| 39 | + /// </summary> |
| 40 | + /// <returns></returns> |
| 41 | + [HttpGet(nameof(GetCollectionStream))] |
| 42 | + public async Task<CollectionResult<Post>> GetCollectionStream() |
| 43 | + { |
| 44 | + var httpRequest = new HttpRequestMessage(HttpMethod.Get, new Uri("https://jsonplaceholder.typicode.com/posts")); |
| 45 | + var response = await Factory.Client.SendAsync(httpRequest); |
| 46 | + var content = await response.Content.ReadAsStringAsync(); |
| 47 | + var items = JsonConvert.DeserializeObject<List<Post>>(content); |
| 48 | + |
| 49 | + |
| 50 | + var count = items.Count; |
| 51 | + Logger.LogDebug($"{nameof(GetPostsAsync)}, PostsCount:{items.Count}"); |
| 52 | + return new CollectionResult<Post> |
| 53 | + { |
| 54 | + Data = items, |
| 55 | + Draw = 1, |
| 56 | + TotalRecords = count, |
| 57 | + TotalRecordsFiltered = count |
| 58 | + }; |
| 59 | + } |
| 60 | + |
| 61 | + [HttpGet(nameof(GetCollectionStreams))] |
| 62 | + public IEnumerable<CollectionResult<Post>> GetCollectionStreams() |
| 63 | + { |
| 64 | + var httpRequest = new HttpRequestMessage(HttpMethod.Get, new Uri("https://jsonplaceholder.typicode.com/posts")); |
| 65 | + var response = Factory.Client.SendAsync(httpRequest).Result; |
| 66 | + var content = response.Content.ReadAsStringAsync().Result; |
| 67 | + var items = JsonConvert.DeserializeObject<List<Post>>(content); |
| 68 | + var count = items.Count; |
| 69 | + Logger.LogDebug($"{nameof(GetPostsAsync)}, PostsCount:{items.Count}"); |
| 70 | + return new List<CollectionResult<Post>> |
| 71 | + { |
| 72 | + new CollectionResult<Post> |
| 73 | + { |
| 74 | + Data = items, |
| 75 | + Draw = 1, |
| 76 | + TotalRecords = count, |
| 77 | + TotalRecordsFiltered = count |
| 78 | + } |
| 79 | + }; |
| 80 | + } |
| 81 | + |
36 | 82 | [HttpGet(nameof(GetWithReferenceType))] |
37 | 83 | public async Task GetWithReferenceType([FromQuery]SimpleModel model) |
38 | 84 | { |
|
0 commit comments