1- using System . Globalization ;
21using Asp . Versioning ;
3- using Microsoft . OpenApi . Any ;
42using Services ;
53
64namespace Api . Setup ;
75
86internal static class ApiEndpoints
97{
10- private static readonly OpenApiString ExampleFromDate = new ( DateTime . Now . AddMonths ( - 1 ) . ToString ( "yyyy-MM-dd" , CultureInfo . InvariantCulture ) ) ;
11- private static readonly OpenApiString ExampleToDate = new ( DateTime . Now . ToString ( "yyyy-MM-dd" , CultureInfo . InvariantCulture ) ) ;
8+ // private static readonly OpenApiString ExampleFromDate = new(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
9+ // private static readonly OpenApiString ExampleToDate = new(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
1210
1311 public static void ConfigureEndpoints ( this WebApplication app )
1412 {
@@ -21,8 +19,7 @@ public static void ConfigureEndpoints(this WebApplication app)
2119 . MapGroup ( "api/v{version:apiVersion}" )
2220 . WithApiVersionSet ( apiVersionSet ) ;
2321
24- ConfigureEndpoint ( group , "/longestdownwardtrend" ,
25- "Get longest downward trend in days between given dates" ,
22+ group . MapGet ( "/longestdownwardtrend" ,
2623 async ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
2724 {
2825 try
@@ -38,33 +35,33 @@ public static void ConfigureEndpoints(this WebApplication app)
3835 {
3936 return Results . Problem ( statusCode : ( int ? ) ex . StatusCode ) ;
4037 }
41- } ) ;
38+ } )
39+ . WithDescription ( "Get longest downward trend in days between given dates" ) ;
4240
43- ConfigureEndpoint ( group , "/highestradingvolume" ,
44- "Get the date with the highest trading volume between given dates" ,
45- async ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
46- {
47- try
41+ group . MapGet ( "/highestradingvolume" ,
42+ async ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
4843 {
49- var result = await service . GetHighestTradingVolume ( fromDate , toDate ) ;
50- if ( result is null )
44+ try
5145 {
52- return Results . NoContent ( ) ;
46+ var result = await service . GetHighestTradingVolume ( fromDate , toDate ) ;
47+ if ( result is null )
48+ {
49+ return Results . NoContent ( ) ;
50+ }
51+ return Results . Ok ( new HighestTradingVolumeResponse
52+ (
53+ result . Value . Date ,
54+ result . Value . Volume
55+ ) ) ;
5356 }
54- return Results . Ok ( new HighestTradingVolumeResponse
55- (
56- result . Value . Date ,
57- result . Value . Volume
58- ) ) ;
59- }
60- catch ( HttpRequestException ex )
61- {
62- return Results . Problem ( statusCode : ( int ? ) ex . StatusCode ) ;
63- }
64- } ) ;
57+ catch ( HttpRequestException ex )
58+ {
59+ return Results . Problem ( statusCode : ( int ? ) ex . StatusCode ) ;
60+ }
61+ } )
62+ . WithDescription ( "Get the date with the highest trading volume between given dates" ) ;
6563
66- ConfigureEndpoint ( group , "/buyandsell" ,
67- "Get pair of dates when it is best to buy and sell between given dates" ,
64+ group . MapGet ( "/buyandsell" ,
6865 async ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
6966 {
7067 try
@@ -84,20 +81,21 @@ public static void ConfigureEndpoints(this WebApplication app)
8481 {
8582 return Results . Problem ( statusCode : ( int ? ) ex . StatusCode ) ;
8683 }
87- } ) ;
84+ } )
85+ . WithDescription ( "Get pair of dates when it is best to buy and sell between given dates" ) ;
8886 }
8987
90- private static void ConfigureEndpoint ( RouteGroupBuilder group , string route , string summary , Delegate handler )
91- {
92- group . MapGet ( route , handler )
93- . WithOpenApi ( operation =>
94- {
95- operation . Summary = summary ;
96- operation . Parameters [ 0 ] . Example = ExampleFromDate ;
97- operation . Parameters [ ^ 1 ] . Example = ExampleToDate ;
98- return operation ;
99- } ) ;
100- }
88+ // private static void ConfigureEndpoint(RouteGroupBuilder group, string route, string description , Delegate handler)
89+ // {
90+ // group.MapGet(route, handler)
91+ // .WithDescription(description)
92+ // .WithOpenApi(operation =>
93+ // {
94+ // operation.Parameters[0].Example = ExampleFromDate;
95+ // operation.Parameters[^1].Example = ExampleToDate;
96+ // return operation;
97+ // });
98+ // }
10199}
102100
103101public record LongestDownwardTrendResponse ( int Days ) ;
0 commit comments