@@ -42,9 +42,56 @@ public static void MapLocationApiEndpoints(this IEndpointRouteBuilder app, AuthO
4242 } ) ;
4343 } ) ;
4444
45+ var detailedGetByLocation = app . MapGet ( "/api/detailedWarningsByLocation/{latitude}/{longitude}/{langKey}/{from}/{to}" , async (
46+ double latitude ,
47+ double longitude ,
48+ string langKey ,
49+ DateOnly from ,
50+ DateOnly to ,
51+ IForecastAreaService forecastAreaService ,
52+ IVarsomWarningService varsomWarningService ,
53+ ILavinprognoserWarningService lavinprognoserWarningService ) =>
54+ {
55+ var ( regionId , country ) = forecastAreaService . GetClosestTypeAForecastAreaForLocation ( latitude , longitude , true ) ;
56+
57+ IEnumerable < DetailedAvalancheWarning > detailedWarnings ;
58+ if ( country == Country . SE )
59+ {
60+ var seWarnings = await lavinprognoserWarningService . GetDetailedWarningsByArea ( regionId , from , to ) ;
61+ detailedWarnings = seWarnings . Select ( w => w . ToDetailedAvalancheWarning ( ) ) ;
62+ }
63+ else
64+ {
65+ var noWarnings = await varsomWarningService . GetDetailedWarningsByRegion ( regionId , langKey , from , to ) ;
66+ detailedWarnings = noWarnings . Select ( w => w . ToDetailedAvalancheWarning ( langKey ) ) ;
67+ }
68+
69+ return Results . Ok ( new DetailedWarningsForLocationResponse
70+ {
71+ RegionId = country == Country . SE ? $ "se_{ regionId } " : regionId . ToString ( ) ,
72+ Warnings = detailedWarnings ,
73+ } ) ;
74+ } ) ;
75+
76+ var regionByLocation = app . MapGet ( "/api/regionByLocation/{latitude}/{longitude}" , (
77+ double latitude ,
78+ double longitude ,
79+ bool ? includeSwedishAreas ,
80+ IForecastAreaService forecastAreaService ) =>
81+ {
82+ var ( regionId , country ) = forecastAreaService . GetClosestTypeAForecastAreaForLocation ( latitude , longitude , includeSwedishAreas ?? false ) ;
83+
84+ return Results . Ok ( new
85+ {
86+ RegionId = country == Country . SE ? $ "se_{ regionId } " : regionId . ToString ( ) ,
87+ } ) ;
88+ } ) ;
89+
4590 if ( authOptions . UseWatchAuthorization )
4691 {
4792 simpleGetByLocation . RequireAuthorization ( "Garmin" ) ;
93+ detailedGetByLocation . RequireAuthorization ( "Garmin" ) ;
94+ regionByLocation . RequireAuthorization ( "Garmin" ) ;
4895 }
4996 }
5097}
0 commit comments