Skip to content

Commit 98bf371

Browse files
committed
Expand API for datafield usage.
1 parent 68765d4 commit 98bf371

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/LocationApiRouteBuilderExtensions.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SkredvarselGarminWeb.Endpoints.Models;
2+
3+
public class DetailedWarningsForLocationResponse
4+
{
5+
public required string RegionId { get; set; }
6+
public required IEnumerable<DetailedAvalancheWarning> Warnings { get; set; }
7+
}

0 commit comments

Comments
 (0)