mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 23:36:39 +00:00
c354661a10
add get post requests structure - simple get
141 lines
4.6 KiB
C#
141 lines
4.6 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.OpenApi.Models;
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Satellite Provider API", Version = "v1" });
|
|
|
|
c.MapType<UploadImageRequest>(() => new OpenApiSchema
|
|
{
|
|
Type = "object",
|
|
Properties = new Dictionary<string, OpenApiSchema>
|
|
{
|
|
["timestamp"] = new() { Type = "string", Format = "date-time", Description = "Image capture timestamp" },
|
|
["image"] = new() { Type = "string", Format = "binary", Description = "Image file to upload" },
|
|
["lat"] = new() { Type = "number", Format = "double", Description = "Latitude coordinate where image was captured" },
|
|
["lon"] = new() { Type = "number", Format = "double", Description = "Longitude coordinate where image was captured" },
|
|
["height"] = new() { Type = "number", Format = "double", Description = "Height/altitude in meters where image was captured" },
|
|
["focalLength"] = new() { Type = "number", Format = "double", Description = "Camera focal length in millimeters" },
|
|
["sensorWidth"] = new() { Type = "number", Format = "double", Description = "Camera sensor width in millimeters" },
|
|
["sensorHeight"] = new() { Type = "number", Format = "double", Description = "Camera sensor height in millimeters" }
|
|
},
|
|
Required = new HashSet<string> { "timestamp", "image", "lat", "lon", "height", "focalLength", "sensorWidth", "sensorHeight" }
|
|
});
|
|
|
|
c.OperationFilter<ParameterDescriptionFilter>();
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapGet("/api/satellite/tiles/latlon", GetSatelliteTilesByLatLon)
|
|
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by latitude and longitude coordinates" });
|
|
|
|
app.MapGet("/api/satellite/tiles/mgrs", GetSatelliteTilesByMgrs)
|
|
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by MGRS coordinates" });
|
|
|
|
app.MapPost("/api/satellite/upload", UploadImage)
|
|
.Accepts<UploadImageRequest>("multipart/form-data")
|
|
.WithOpenApi(op => new(op) { Summary = "Upload image with metadata and save to /maps folder" })
|
|
.DisableAntiforgery();
|
|
|
|
app.Run();
|
|
|
|
IResult GetSatelliteTilesByLatLon(double lat, double lon, double squareSideMeters)
|
|
{
|
|
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 });
|
|
}
|
|
|
|
public record GetSatelliteTilesResponse
|
|
{
|
|
public List<SatelliteTile> Tiles { get; set; } = new();
|
|
}
|
|
|
|
public record SatelliteTile
|
|
{
|
|
public string TileId { get; set; } = string.Empty;
|
|
public byte[] ImageData { get; set; } = Array.Empty<byte>();
|
|
public double Lat { get; set; }
|
|
public double Lon { get; set; }
|
|
public int ZoomLevel { get; set; }
|
|
}
|
|
|
|
public record UploadImageRequest
|
|
{
|
|
[Required]
|
|
public DateTime Timestamp { get; set; }
|
|
|
|
[Required]
|
|
public IFormFile? Image { get; set; }
|
|
|
|
[Required]
|
|
public double Lat { get; set; }
|
|
|
|
[Required]
|
|
public double Lon { get; set; }
|
|
|
|
[Required]
|
|
public double Height { get; set; }
|
|
|
|
[Required]
|
|
public double FocalLength { get; set; }
|
|
|
|
[Required]
|
|
public double SensorWidth { get; set; }
|
|
|
|
[Required]
|
|
public double SensorHeight { get; set; }
|
|
}
|
|
|
|
public record SaveResult
|
|
{
|
|
public bool Success { get; set; }
|
|
public string? Exception { get; set; }
|
|
}
|
|
|
|
public class ParameterDescriptionFilter : IOperationFilter
|
|
{
|
|
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
|
{
|
|
if (operation.Parameters == null) return;
|
|
|
|
var parameterDescriptions = new Dictionary<string, string>
|
|
{
|
|
["lat"] = "Latitude coordinate where image was captured",
|
|
["lon"] = "Longitude coordinate where image was captured",
|
|
["mgrs"] = "MGRS coordinate string",
|
|
["squareSideMeters"] = "Square side size in meters"
|
|
};
|
|
|
|
foreach (var parameter in operation.Parameters)
|
|
{
|
|
if (parameterDescriptions.TryGetValue(parameter.Name, out var description))
|
|
{
|
|
parameter.Description = description;
|
|
}
|
|
}
|
|
}
|
|
}
|