api /api/satellite/tiles/latlon

This commit is contained in:
Anton Martynenko
2025-11-19 13:12:26 +01:00
parent b66d3a0277
commit 5974b0c589
4 changed files with 35 additions and 66 deletions
+23 -40
View File
@@ -90,8 +90,8 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.MapGet("/api/satellite/tiles/latlon", GetSatelliteTilesByLatLon) app.MapGet("/api/satellite/tiles/latlon", GetTileByLatLon)
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by latitude and longitude coordinates" }); .WithOpenApi(op => new(op) { Summary = "Get satellite tile by latitude and longitude coordinates" });
app.MapGet("/api/satellite/tiles/mgrs", GetSatelliteTilesByMgrs) app.MapGet("/api/satellite/tiles/mgrs", GetSatelliteTilesByMgrs)
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by MGRS coordinates" }); .WithOpenApi(op => new(op) { Summary = "Get satellite tiles by MGRS coordinates" });
@@ -101,9 +101,6 @@ app.MapPost("/api/satellite/upload", UploadImage)
.WithOpenApi(op => new(op) { Summary = "Upload image with metadata and save to /maps folder" }) .WithOpenApi(op => new(op) { Summary = "Upload image with metadata and save to /maps folder" })
.DisableAntiforgery(); .DisableAntiforgery();
app.MapPost("/api/satellite/tiles/download", DownloadSingleTile)
.WithOpenApi(op => new(op) { Summary = "TEMPORARY: Download single tile at specified coordinates" });
app.MapPost("/api/satellite/request", RequestRegion) app.MapPost("/api/satellite/request", RequestRegion)
.WithOpenApi(op => new(op) { Summary = "Request tiles for a region" }); .WithOpenApi(op => new(op) { Summary = "Request tiles for a region" });
@@ -118,32 +115,17 @@ app.MapGet("/api/satellite/route/{id:guid}", GetRoute)
app.Run(); app.Run();
IResult GetSatelliteTilesByLatLon(double lat, double lon, double squareSideMeters) async Task<IResult> GetTileByLatLon([FromQuery] double Latitude, [FromQuery] double Longitude, [FromQuery] int ZoomLevel, GoogleMapsDownloaderV2 downloader, ITileRepository tileRepository, ILogger<Program> logger)
{
return Results.Ok(new GetSatelliteTilesResponse());
}
IResult GetSatelliteTilesByMgrs(string mgrs, double squareSideMeters)
{
return Results.Ok(new GetSatelliteTilesResponse());
}
IResult UploadImage([FromForm] UploadImageRequest request)
{
return Results.Ok(new SaveResult { Success = false });
}
async Task<IResult> DownloadSingleTile([FromBody] DownloadTileRequest request, GoogleMapsDownloaderV2 downloader, ITileRepository tileRepository, ILogger<Program> logger)
{ {
try try
{ {
logger.LogInformation("Downloading single tile at ({Lat}, {Lon}) with zoom level {Zoom}", logger.LogInformation("Getting tile at ({Lat}, {Lon}) with zoom level {Zoom}",
request.Latitude, request.Longitude, request.ZoomLevel); Latitude, Longitude, ZoomLevel);
var downloadedTile = await downloader.DownloadSingleTileAsync( var downloadedTile = await downloader.DownloadSingleTileAsync(
request.Latitude, Latitude,
request.Longitude, Longitude,
request.ZoomLevel); ZoomLevel);
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var currentVersion = now.Year; var currentVersion = now.Year;
@@ -186,11 +168,21 @@ async Task<IResult> DownloadSingleTile([FromBody] DownloadTileRequest request, G
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "Failed to download tile"); logger.LogError(ex, "Failed to get tile");
return Results.Problem(detail: ex.Message, statusCode: 500); return Results.Problem(detail: ex.Message, statusCode: 500);
} }
} }
IResult GetSatelliteTilesByMgrs(string mgrs, double squareSideMeters)
{
return Results.Ok(new GetSatelliteTilesResponse());
}
IResult UploadImage([FromForm] UploadImageRequest request)
{
return Results.Ok(new SaveResult { Success = false });
}
async Task<IResult> RequestRegion([FromBody] RequestRegionRequest request, IRegionService regionService, ILogger<Program> logger) async Task<IResult> RequestRegion([FromBody] RequestRegionRequest request, IRegionService regionService, ILogger<Program> logger)
{ {
try try
@@ -329,18 +321,6 @@ public record SaveResult
public string? Exception { get; set; } public string? Exception { get; set; }
} }
public record DownloadTileRequest
{
[Required]
public double Latitude { get; set; }
[Required]
public double Longitude { get; set; }
[Required]
public int ZoomLevel { get; set; } = 20;
}
public record DownloadTileResponse public record DownloadTileResponse
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
@@ -388,7 +368,10 @@ public class ParameterDescriptionFilter : IOperationFilter
["lat"] = "Latitude coordinate where image was captured", ["lat"] = "Latitude coordinate where image was captured",
["lon"] = "Longitude coordinate where image was captured", ["lon"] = "Longitude coordinate where image was captured",
["mgrs"] = "MGRS coordinate string", ["mgrs"] = "MGRS coordinate string",
["squareSideMeters"] = "Square side size in meters" ["squareSideMeters"] = "Square side size in meters",
["Latitude"] = "Latitude coordinate of the tile center",
["Longitude"] = "Longitude coordinate of the tile center",
["ZoomLevel"] = "Zoom level for the tile (higher values = more detail)"
}; };
foreach (var parameter in operation.Parameters) foreach (var parameter in operation.Parameters)
@@ -1,12 +1,5 @@
namespace SatelliteProvider.IntegrationTests; namespace SatelliteProvider.IntegrationTests;
public record DownloadTileRequest
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public int ZoomLevel { get; set; }
}
public record DownloadTileResponse public record DownloadTileResponse
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
@@ -24,7 +24,7 @@ class Program
Console.WriteLine("✓ API is ready"); Console.WriteLine("✓ API is ready");
Console.WriteLine(); Console.WriteLine();
await TileTests.RunSingleTileDownloadTest(httpClient); await TileTests.RunGetTileByLatLonTest(httpClient);
await RegionTests.RunRegionProcessingTest_200m_Zoom18(httpClient); await RegionTests.RunRegionProcessingTest_200m_Zoom18(httpClient);
+11 -18
View File
@@ -10,25 +10,18 @@ public static class TileTests
PropertyNameCaseInsensitive = true PropertyNameCaseInsensitive = true
}; };
public static async Task RunSingleTileDownloadTest(HttpClient httpClient) public static async Task RunGetTileByLatLonTest(HttpClient httpClient)
{ {
Console.WriteLine("Test: Download Single Tile at Coordinates 47.461747, 37.647063"); Console.WriteLine("Test: Get Tile by Lat/Lon at Coordinates 47.461747, 37.647063");
Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("------------------------------------------------------------------");
const double latitude = 47.461747; const double latitude = 47.461747;
const double longitude = 37.647063; const double longitude = 37.647063;
const int zoomLevel = 18; const int zoomLevel = 18;
Console.WriteLine($"Downloading tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}"); Console.WriteLine($"Getting tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}");
var request = new DownloadTileRequest var response = await httpClient.GetAsync($"/api/satellite/tiles/latlon?Latitude={latitude}&Longitude={longitude}&ZoomLevel={zoomLevel}");
{
Latitude = latitude,
Longitude = longitude,
ZoomLevel = zoomLevel
};
var response = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request);
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
@@ -77,30 +70,30 @@ public static class TileTests
} }
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("✓ Tile downloaded successfully"); Console.WriteLine("✓ Tile retrieved successfully");
Console.WriteLine("✓ Tile metadata validated"); Console.WriteLine("✓ Tile metadata validated");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Testing tile reuse (downloading same tile again)..."); Console.WriteLine("Testing tile reuse (getting same tile again)...");
var response2 = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request); var response2 = await httpClient.GetAsync($"/api/satellite/tiles/latlon?Latitude={latitude}&Longitude={longitude}&ZoomLevel={zoomLevel}");
if (!response2.IsSuccessStatusCode) if (!response2.IsSuccessStatusCode)
{ {
var errorContent = await response2.Content.ReadAsStringAsync(); var errorContent = await response2.Content.ReadAsStringAsync();
throw new Exception($"Second download failed with status {response2.StatusCode}: {errorContent}"); throw new Exception($"Second request failed with status {response2.StatusCode}: {errorContent}");
} }
var tile2 = await response2.Content.ReadFromJsonAsync<DownloadTileResponse>(JsonOptions); var tile2 = await response2.Content.ReadFromJsonAsync<DownloadTileResponse>(JsonOptions);
if (tile2 == null) if (tile2 == null)
{ {
throw new Exception("No tile data returned from second download"); throw new Exception("No tile data returned from second request");
} }
Console.WriteLine($"✓ Second download returned tile ID: {tile2.Id}"); Console.WriteLine($"✓ Second request returned tile ID: {tile2.Id}");
Console.WriteLine("✓ Tile reuse functionality working"); Console.WriteLine("✓ Tile reuse functionality working");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Single Tile Download Test: PASSED"); Console.WriteLine("Get Tile by Lat/Lon Test: PASSED");
} }
} }