@@ -19,105 +19,61 @@ public static void MapEndpoints(this WebApplication app)
1919 . WithApiVersionSet ( apiVersionSet ) ;
2020
2121 group . MapGet ( "/longestdownwardtrend" ,
22- async Task < Results < Ok < LongestDownwardTrendResponse > , NoContent ,
23- BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
22+ async Task < Results < Ok < LongestDownwardTrendResponse > , NoContent , BadRequest > >
2423 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
2524 {
26- try
27- {
28- var result = await service . GetLongestDownwardTrend ( fromDate , toDate ) . ConfigureAwait ( false ) ;
29-
30- if ( result is null )
31- {
32- return TypedResults . NoContent ( ) ;
33- }
25+ var result = await service . GetLongestDownwardTrend ( fromDate , toDate ) . ConfigureAwait ( false ) ;
3426
35- return TypedResults . Ok ( new LongestDownwardTrendResponse ( result . Value ) ) ;
36- }
37- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . TooManyRequests )
38- {
39- return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
40- }
41- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
42- {
43- return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
44- }
45- catch ( HttpRequestException )
27+ if ( result is null )
4628 {
47- return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
29+ return TypedResults . NoContent ( ) ;
4830 }
31+
32+ return TypedResults . Ok ( new LongestDownwardTrendResponse ( result . Value ) ) ;
4933 } )
5034 . WithDescription ( "Get longest downward trend in days between given dates" )
5135 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
5236 . ProducesProblem ( ( int ) HttpStatusCode . Unauthorized )
5337 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
5438
5539 group . MapGet ( "/highestradingvolume" ,
56- async Task < Results < Ok < HighestTradingVolumeResponse > , NoContent ,
57- BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
40+ async Task < Results < Ok < HighestTradingVolumeResponse > , NoContent , BadRequest > >
5841 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
5942 {
60- try
61- {
62- var result = await service . GetHighestTradingVolume ( fromDate , toDate ) . ConfigureAwait ( false ) ;
63- if ( result is null )
64- {
65- return TypedResults . NoContent ( ) ;
66- }
67- return TypedResults . Ok ( new HighestTradingVolumeResponse
68- (
69- result . Value . Date ,
70- result . Value . Volume
71- ) ) ;
72- }
73- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . TooManyRequests )
74- {
75- return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
76- }
77- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
78- {
79- return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
80- }
81- catch ( HttpRequestException )
43+ var result = await service . GetHighestTradingVolume ( fromDate , toDate ) . ConfigureAwait ( false ) ;
44+
45+ if ( result is null )
8246 {
83- return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
47+ return TypedResults . NoContent ( ) ;
8448 }
49+
50+ return TypedResults . Ok ( new HighestTradingVolumeResponse
51+ (
52+ result . Value . Date ,
53+ result . Value . Volume
54+ ) ) ;
8555 } )
8656 . WithDescription ( "Get the date with the highest trading volume between given dates" )
8757 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
8858 . ProducesProblem ( ( int ) HttpStatusCode . Unauthorized )
8959 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
9060
9161 group . MapGet ( "/buyandsell" ,
92- async Task < Results < Ok < BuyAndSellResponse > , NoContent ,
93- BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
62+ async Task < Results < Ok < BuyAndSellResponse > , NoContent , BadRequest > >
9463 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
9564 {
96- try
97- {
98- var result = await service . GetBestBuyAndSellDates ( fromDate , toDate ) . ConfigureAwait ( false ) ;
99- if ( result is null )
100- {
101- return TypedResults . NoContent ( ) ;
102- }
103- return TypedResults . Ok ( new BuyAndSellResponse
104- (
105- result . Value . BuyDate ,
106- result . Value . SellDate
107- ) ) ;
108- }
109- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . TooManyRequests )
110- {
111- return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
112- }
113- catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
114- {
115- return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
116- }
117- catch ( HttpRequestException )
65+ var result = await service . GetBestBuyAndSellDates ( fromDate , toDate ) . ConfigureAwait ( false ) ;
66+
67+ if ( result is null )
11868 {
119- return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
69+ return TypedResults . NoContent ( ) ;
12070 }
71+
72+ return TypedResults . Ok ( new BuyAndSellResponse
73+ (
74+ result . Value . BuyDate ,
75+ result . Value . SellDate
76+ ) ) ;
12177 } )
12278 . WithDescription ( "Get pair of dates when it is best to buy and sell between given dates" )
12379 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
0 commit comments