mirror of
https://github.com/azaion/missions.git
synced 2026-06-21 12:21:07 +00:00
2840ccb9b6
ci/woodpecker/push/build-arm Pipeline was successful
This commit transitions the project from Azaion.Flights to Azaion.Missions, updating namespaces, DTOs, services, and database entities accordingly. The Docker configuration and entry points have been modified to reflect the new project structure. Additionally, the README and documentation have been updated to clarify the ongoing renaming process and its implications. All references to flights have been replaced with missions, ensuring consistency across the codebase.
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using Azaion.Missions.Database;
|
|
using Azaion.Missions.Database.Entities;
|
|
using Azaion.Missions.DTOs;
|
|
|
|
namespace Azaion.Missions.Services;
|
|
|
|
public class WaypointService(AppDataConnection db)
|
|
{
|
|
public async Task<Waypoint> CreateWaypoint(Guid missionId, CreateWaypointRequest request)
|
|
{
|
|
var missionExists = await db.Missions.AnyAsync(m => m.Id == missionId);
|
|
if (!missionExists)
|
|
throw new KeyNotFoundException($"Mission {missionId} not found");
|
|
|
|
var waypoint = new Waypoint
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
MissionId = missionId,
|
|
Lat = request.GeoPoint?.Lat,
|
|
Lon = request.GeoPoint?.Lon,
|
|
Mgrs = request.GeoPoint?.Mgrs,
|
|
WaypointSource = request.WaypointSource,
|
|
WaypointObjective = request.WaypointObjective,
|
|
OrderNum = request.OrderNum,
|
|
Height = request.Height
|
|
};
|
|
await db.InsertAsync(waypoint);
|
|
return waypoint;
|
|
}
|
|
|
|
public async Task<Waypoint> UpdateWaypoint(Guid missionId, Guid waypointId, UpdateWaypointRequest request)
|
|
{
|
|
var waypoint = await db.Waypoints.FirstOrDefaultAsync(w => w.MissionId == missionId && w.Id == waypointId)
|
|
?? throw new KeyNotFoundException($"Waypoint {waypointId} not found");
|
|
|
|
waypoint.Lat = request.GeoPoint?.Lat;
|
|
waypoint.Lon = request.GeoPoint?.Lon;
|
|
waypoint.Mgrs = request.GeoPoint?.Mgrs;
|
|
waypoint.WaypointSource = request.WaypointSource;
|
|
waypoint.WaypointObjective = request.WaypointObjective;
|
|
waypoint.OrderNum = request.OrderNum;
|
|
waypoint.Height = request.Height;
|
|
|
|
await db.UpdateAsync(waypoint);
|
|
return waypoint;
|
|
}
|
|
|
|
public async Task<List<Waypoint>> GetWaypoints(Guid missionId)
|
|
{
|
|
return await db.Waypoints
|
|
.Where(w => w.MissionId == missionId)
|
|
.OrderBy(w => w.OrderNum)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task DeleteWaypoint(Guid missionId, Guid waypointId)
|
|
{
|
|
var waypoint = await db.Waypoints.FirstOrDefaultAsync(w => w.MissionId == missionId && w.Id == waypointId)
|
|
?? throw new KeyNotFoundException($"Waypoint {waypointId} not found");
|
|
|
|
var mediaIds = await db.Media.Where(m => m.WaypointId == waypointId).Select(m => m.Id).ToListAsync();
|
|
if (mediaIds.Count > 0)
|
|
{
|
|
var annotationIds = await db.Annotations.Where(a => mediaIds.Contains(a.MediaId))
|
|
.Select(a => a.Id).ToListAsync();
|
|
if (annotationIds.Count > 0)
|
|
await db.Detections.DeleteAsync(d => annotationIds.Contains(d.AnnotationId));
|
|
await db.Annotations.DeleteAsync(a => mediaIds.Contains(a.MediaId));
|
|
}
|
|
await db.Media.DeleteAsync(m => m.WaypointId == waypointId);
|
|
await db.Waypoints.DeleteAsync(w => w.Id == waypointId);
|
|
}
|
|
}
|