mirror of
https://github.com/azaion/missions.git
synced 2026-06-21 08:11:06 +00:00
refactor: rename project from Flights to Missions and update related components
ci/woodpecker/push/build-arm Pipeline was successful
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.
This commit is contained in:
+42
-44
@@ -1,75 +1,75 @@
|
||||
using LinqToDB;
|
||||
using Azaion.Flights.Database;
|
||||
using Azaion.Flights.Database.Entities;
|
||||
using Azaion.Flights.DTOs;
|
||||
using Azaion.Missions.Database;
|
||||
using Azaion.Missions.Database.Entities;
|
||||
using Azaion.Missions.DTOs;
|
||||
|
||||
namespace Azaion.Flights.Services;
|
||||
namespace Azaion.Missions.Services;
|
||||
|
||||
public class FlightService(AppDataConnection db)
|
||||
public class MissionService(AppDataConnection db)
|
||||
{
|
||||
public async Task<Flight> CreateFlight(CreateFlightRequest request)
|
||||
public async Task<Mission> CreateMission(CreateMissionRequest request)
|
||||
{
|
||||
var aircraftExists = await db.Aircrafts.AnyAsync(a => a.Id == request.AircraftId);
|
||||
if (!aircraftExists)
|
||||
throw new ArgumentException($"Aircraft {request.AircraftId} not found");
|
||||
var vehicleExists = await db.Vehicles.AnyAsync(v => v.Id == request.VehicleId);
|
||||
if (!vehicleExists)
|
||||
throw new ArgumentException($"Vehicle {request.VehicleId} not found");
|
||||
|
||||
var flight = new Flight
|
||||
var mission = new Mission
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CreatedDate = request.CreatedDate ?? DateTime.UtcNow,
|
||||
Name = request.Name,
|
||||
AircraftId = request.AircraftId
|
||||
VehicleId = request.VehicleId
|
||||
};
|
||||
await db.InsertAsync(flight);
|
||||
return flight;
|
||||
await db.InsertAsync(mission);
|
||||
return mission;
|
||||
}
|
||||
|
||||
public async Task<Flight> UpdateFlight(Guid id, UpdateFlightRequest request)
|
||||
public async Task<Mission> UpdateMission(Guid id, UpdateMissionRequest request)
|
||||
{
|
||||
var flight = await db.Flights.FirstOrDefaultAsync(f => f.Id == id)
|
||||
?? throw new KeyNotFoundException($"Flight {id} not found");
|
||||
var mission = await db.Missions.FirstOrDefaultAsync(m => m.Id == id)
|
||||
?? throw new KeyNotFoundException($"Mission {id} not found");
|
||||
|
||||
if (request.Name != null)
|
||||
flight.Name = request.Name;
|
||||
if (request.AircraftId.HasValue)
|
||||
mission.Name = request.Name;
|
||||
if (request.VehicleId.HasValue)
|
||||
{
|
||||
var aircraftExists = await db.Aircrafts.AnyAsync(a => a.Id == request.AircraftId.Value);
|
||||
if (!aircraftExists)
|
||||
throw new ArgumentException($"Aircraft {request.AircraftId} not found");
|
||||
flight.AircraftId = request.AircraftId.Value;
|
||||
var vehicleExists = await db.Vehicles.AnyAsync(v => v.Id == request.VehicleId.Value);
|
||||
if (!vehicleExists)
|
||||
throw new ArgumentException($"Vehicle {request.VehicleId} not found");
|
||||
mission.VehicleId = request.VehicleId.Value;
|
||||
}
|
||||
|
||||
await db.UpdateAsync(flight);
|
||||
return flight;
|
||||
await db.UpdateAsync(mission);
|
||||
return mission;
|
||||
}
|
||||
|
||||
public async Task<Flight> GetFlight(Guid id)
|
||||
public async Task<Mission> GetMission(Guid id)
|
||||
{
|
||||
var flight = await db.Flights.FirstOrDefaultAsync(f => f.Id == id)
|
||||
?? throw new KeyNotFoundException($"Flight {id} not found");
|
||||
return flight;
|
||||
var mission = await db.Missions.FirstOrDefaultAsync(m => m.Id == id)
|
||||
?? throw new KeyNotFoundException($"Mission {id} not found");
|
||||
return mission;
|
||||
}
|
||||
|
||||
public async Task<PaginatedResponse<Flight>> GetFlights(GetFlightsQuery query)
|
||||
public async Task<PaginatedResponse<Mission>> GetMissions(GetMissionsQuery query)
|
||||
{
|
||||
var q = db.Flights.AsQueryable();
|
||||
var q = db.Missions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(query.Name))
|
||||
q = q.Where(f => f.Name.ToLower().Contains(query.Name.ToLower()));
|
||||
q = q.Where(m => m.Name.ToLower().Contains(query.Name.ToLower()));
|
||||
if (query.FromDate.HasValue)
|
||||
q = q.Where(f => f.CreatedDate >= query.FromDate.Value);
|
||||
q = q.Where(m => m.CreatedDate >= query.FromDate.Value);
|
||||
if (query.ToDate.HasValue)
|
||||
q = q.Where(f => f.CreatedDate <= query.ToDate.Value);
|
||||
q = q.Where(m => m.CreatedDate <= query.ToDate.Value);
|
||||
|
||||
var totalCount = await q.CountAsync();
|
||||
|
||||
var items = await q
|
||||
.OrderByDescending(f => f.CreatedDate)
|
||||
.OrderByDescending(m => m.CreatedDate)
|
||||
.Skip((query.Page - 1) * query.PageSize)
|
||||
.Take(query.PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return new PaginatedResponse<Flight>
|
||||
return new PaginatedResponse<Mission>
|
||||
{
|
||||
Items = items,
|
||||
TotalCount = totalCount,
|
||||
@@ -78,16 +78,14 @@ public class FlightService(AppDataConnection db)
|
||||
};
|
||||
}
|
||||
|
||||
public async Task DeleteFlight(Guid id)
|
||||
public async Task DeleteMission(Guid id)
|
||||
{
|
||||
var flight = await db.Flights.FirstOrDefaultAsync(f => f.Id == id)
|
||||
?? throw new KeyNotFoundException($"Flight {id} not found");
|
||||
var mission = await db.Missions.FirstOrDefaultAsync(m => m.Id == id)
|
||||
?? throw new KeyNotFoundException($"Mission {id} not found");
|
||||
|
||||
await db.MapObjects.DeleteAsync(m => m.FlightId == id);
|
||||
await db.GpsCorrections.DeleteAsync(g => g.FlightId == id);
|
||||
await db.Orthophotos.DeleteAsync(o => o.FlightId == id);
|
||||
await db.MapObjects.DeleteAsync(o => o.MissionId == id);
|
||||
|
||||
var waypointIds = await db.Waypoints.Where(w => w.FlightId == id).Select(w => w.Id).ToListAsync();
|
||||
var waypointIds = await db.Waypoints.Where(w => w.MissionId == id).Select(w => w.Id).ToListAsync();
|
||||
if (waypointIds.Count > 0)
|
||||
{
|
||||
var mediaIds = await db.Media.Where(m => m.WaypointId != null && waypointIds.Contains(m.WaypointId!.Value))
|
||||
@@ -103,7 +101,7 @@ public class FlightService(AppDataConnection db)
|
||||
await db.Media.DeleteAsync(m => m.WaypointId != null && waypointIds.Contains(m.WaypointId!.Value));
|
||||
}
|
||||
|
||||
await db.Waypoints.DeleteAsync(w => w.FlightId == id);
|
||||
await db.Flights.DeleteAsync(f => f.Id == id);
|
||||
await db.Waypoints.DeleteAsync(w => w.MissionId == id);
|
||||
await db.Missions.DeleteAsync(m => m.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
+92
-60
@@ -1,17 +1,21 @@
|
||||
using Azaion.Flights.Database;
|
||||
using Azaion.Flights.Database.Entities;
|
||||
using Azaion.Flights.DTOs;
|
||||
using System.Data;
|
||||
using Azaion.Missions.Database;
|
||||
using Azaion.Missions.Database.Entities;
|
||||
using Azaion.Missions.DTOs;
|
||||
|
||||
namespace Azaion.Flights.Services;
|
||||
namespace Azaion.Missions.Services;
|
||||
|
||||
public class AircraftService(AppDataConnection db)
|
||||
public class VehicleService(AppDataConnection db)
|
||||
{
|
||||
public async Task<Aircraft> CreateAircraft(CreateAircraftRequest request)
|
||||
// B12 (Option A): "exactly one default vehicle" is the user-visible truth.
|
||||
// Every code path that sets is_default=true clears existing defaults and
|
||||
// assigns the new default inside a Serializable transaction so two
|
||||
// concurrent default-set ops cannot leave 0 or 2 defaults. The DB-level
|
||||
// partial unique index `ux_vehicles_one_default` (DatabaseMigrator) is the
|
||||
// belt-and-braces backstop if a future code path forgets the transaction.
|
||||
public async Task<Vehicle> CreateVehicle(CreateVehicleRequest request)
|
||||
{
|
||||
if (request.IsDefault)
|
||||
await db.Aircrafts.Where(a => a.IsDefault).Set(a => a.IsDefault, false).UpdateAsync();
|
||||
|
||||
var aircraft = new Aircraft
|
||||
var vehicle = new Vehicle
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Type = request.Type,
|
||||
@@ -23,80 +27,108 @@ public class AircraftService(AppDataConnection db)
|
||||
EngineConsumptionIdle = request.EngineConsumptionIdle,
|
||||
IsDefault = request.IsDefault
|
||||
};
|
||||
await db.InsertAsync(aircraft);
|
||||
return aircraft;
|
||||
}
|
||||
|
||||
public async Task<Aircraft> UpdateAircraft(Guid id, UpdateAircraftRequest request)
|
||||
{
|
||||
var aircraft = await db.Aircrafts.FirstOrDefaultAsync(a => a.Id == id)
|
||||
?? throw new KeyNotFoundException($"Aircraft {id} not found");
|
||||
|
||||
if (request.Type.HasValue)
|
||||
aircraft.Type = request.Type.Value;
|
||||
if (request.Model != null)
|
||||
aircraft.Model = request.Model;
|
||||
if (request.Name != null)
|
||||
aircraft.Name = request.Name;
|
||||
if (request.FuelType.HasValue)
|
||||
aircraft.FuelType = request.FuelType.Value;
|
||||
if (request.BatteryCapacity.HasValue)
|
||||
aircraft.BatteryCapacity = request.BatteryCapacity.Value;
|
||||
if (request.EngineConsumption.HasValue)
|
||||
aircraft.EngineConsumption = request.EngineConsumption.Value;
|
||||
if (request.EngineConsumptionIdle.HasValue)
|
||||
aircraft.EngineConsumptionIdle = request.EngineConsumptionIdle.Value;
|
||||
if (request.IsDefault.HasValue)
|
||||
if (request.IsDefault)
|
||||
{
|
||||
if (request.IsDefault.Value)
|
||||
await db.Aircrafts.Where(a => a.IsDefault).Set(a => a.IsDefault, false).UpdateAsync();
|
||||
aircraft.IsDefault = request.IsDefault.Value;
|
||||
await using var tx = await db.BeginTransactionAsync(IsolationLevel.Serializable);
|
||||
await db.Vehicles.Where(v => v.IsDefault).Set(v => v.IsDefault, false).UpdateAsync();
|
||||
await db.InsertAsync(vehicle);
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await db.InsertAsync(vehicle);
|
||||
}
|
||||
|
||||
await db.UpdateAsync(aircraft);
|
||||
return aircraft;
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public async Task<Aircraft> GetAircraft(Guid id)
|
||||
public async Task<Vehicle> UpdateVehicle(Guid id, UpdateVehicleRequest request)
|
||||
{
|
||||
var aircraft = await db.Aircrafts.FirstOrDefaultAsync(a => a.Id == id)
|
||||
?? throw new KeyNotFoundException($"Aircraft {id} not found");
|
||||
return aircraft;
|
||||
var vehicle = await db.Vehicles.FirstOrDefaultAsync(v => v.Id == id)
|
||||
?? throw new KeyNotFoundException($"Vehicle {id} not found");
|
||||
|
||||
if (request.Type.HasValue)
|
||||
vehicle.Type = request.Type.Value;
|
||||
if (request.Model != null)
|
||||
vehicle.Model = request.Model;
|
||||
if (request.Name != null)
|
||||
vehicle.Name = request.Name;
|
||||
if (request.FuelType.HasValue)
|
||||
vehicle.FuelType = request.FuelType.Value;
|
||||
if (request.BatteryCapacity.HasValue)
|
||||
vehicle.BatteryCapacity = request.BatteryCapacity.Value;
|
||||
if (request.EngineConsumption.HasValue)
|
||||
vehicle.EngineConsumption = request.EngineConsumption.Value;
|
||||
if (request.EngineConsumptionIdle.HasValue)
|
||||
vehicle.EngineConsumptionIdle = request.EngineConsumptionIdle.Value;
|
||||
|
||||
if (request.IsDefault is true)
|
||||
{
|
||||
await using var tx = await db.BeginTransactionAsync(IsolationLevel.Serializable);
|
||||
await db.Vehicles.Where(v => v.IsDefault && v.Id != id).Set(v => v.IsDefault, false).UpdateAsync();
|
||||
vehicle.IsDefault = true;
|
||||
await db.UpdateAsync(vehicle);
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (request.IsDefault is false)
|
||||
vehicle.IsDefault = false;
|
||||
await db.UpdateAsync(vehicle);
|
||||
}
|
||||
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public async Task<List<Aircraft>> GetAircrafts(GetAircraftsQuery query)
|
||||
public async Task<Vehicle> GetVehicle(Guid id)
|
||||
{
|
||||
var q = db.Aircrafts.AsQueryable();
|
||||
var vehicle = await db.Vehicles.FirstOrDefaultAsync(v => v.Id == id)
|
||||
?? throw new KeyNotFoundException($"Vehicle {id} not found");
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public async Task<List<Vehicle>> GetVehicles(GetVehiclesQuery query)
|
||||
{
|
||||
var q = db.Vehicles.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(query.Name))
|
||||
q = q.Where(a => a.Name.ToLower().Contains(query.Name.ToLower()));
|
||||
q = q.Where(v => v.Name.ToLower().Contains(query.Name.ToLower()));
|
||||
if (query.IsDefault.HasValue)
|
||||
q = q.Where(a => a.IsDefault == query.IsDefault.Value);
|
||||
q = q.Where(v => v.IsDefault == query.IsDefault.Value);
|
||||
|
||||
return await q.OrderBy(a => a.Name).ToListAsync();
|
||||
return await q.OrderBy(v => v.Name).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAircraft(Guid id)
|
||||
public async Task DeleteVehicle(Guid id)
|
||||
{
|
||||
var hasFlights = await db.Flights.AnyAsync(f => f.AircraftId == id);
|
||||
if (hasFlights)
|
||||
throw new InvalidOperationException($"Aircraft {id} is referenced by flights");
|
||||
var hasMissions = await db.Missions.AnyAsync(m => m.VehicleId == id);
|
||||
if (hasMissions)
|
||||
throw new InvalidOperationException($"Vehicle {id} is referenced by missions");
|
||||
|
||||
var aircraft = await db.Aircrafts.FirstOrDefaultAsync(a => a.Id == id)
|
||||
?? throw new KeyNotFoundException($"Aircraft {id} not found");
|
||||
var vehicle = await db.Vehicles.FirstOrDefaultAsync(v => v.Id == id)
|
||||
?? throw new KeyNotFoundException($"Vehicle {id} not found");
|
||||
|
||||
await db.Aircrafts.DeleteAsync(a => a.Id == id);
|
||||
await db.Vehicles.DeleteAsync(v => v.Id == id);
|
||||
}
|
||||
|
||||
public async Task SetDefault(Guid id, SetDefaultRequest request)
|
||||
{
|
||||
var aircraft = await db.Aircrafts.FirstOrDefaultAsync(a => a.Id == id)
|
||||
?? throw new KeyNotFoundException($"Aircraft {id} not found");
|
||||
var vehicle = await db.Vehicles.FirstOrDefaultAsync(v => v.Id == id)
|
||||
?? throw new KeyNotFoundException($"Vehicle {id} not found");
|
||||
|
||||
if (request.IsDefault)
|
||||
await db.Aircrafts.Where(a => a.IsDefault).Set(a => a.IsDefault, false).UpdateAsync();
|
||||
|
||||
aircraft.IsDefault = request.IsDefault;
|
||||
await db.UpdateAsync(aircraft);
|
||||
{
|
||||
await using var tx = await db.BeginTransactionAsync(IsolationLevel.Serializable);
|
||||
await db.Vehicles.Where(v => v.IsDefault && v.Id != id).Set(v => v.IsDefault, false).UpdateAsync();
|
||||
vehicle.IsDefault = true;
|
||||
await db.UpdateAsync(vehicle);
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
vehicle.IsDefault = false;
|
||||
await db.UpdateAsync(vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-17
@@ -1,22 +1,21 @@
|
||||
using Azaion.Flights.Database;
|
||||
using Azaion.Flights.Database.Entities;
|
||||
using Azaion.Flights.DTOs;
|
||||
using Azaion.Flights.Enums;
|
||||
using Azaion.Missions.Database;
|
||||
using Azaion.Missions.Database.Entities;
|
||||
using Azaion.Missions.DTOs;
|
||||
|
||||
namespace Azaion.Flights.Services;
|
||||
namespace Azaion.Missions.Services;
|
||||
|
||||
public class WaypointService(AppDataConnection db)
|
||||
{
|
||||
public async Task<Waypoint> CreateWaypoint(Guid flightId, CreateWaypointRequest request)
|
||||
public async Task<Waypoint> CreateWaypoint(Guid missionId, CreateWaypointRequest request)
|
||||
{
|
||||
var flightExists = await db.Flights.AnyAsync(f => f.Id == flightId);
|
||||
if (!flightExists)
|
||||
throw new KeyNotFoundException($"Flight {flightId} not found");
|
||||
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(),
|
||||
FlightId = flightId,
|
||||
MissionId = missionId,
|
||||
Lat = request.GeoPoint?.Lat,
|
||||
Lon = request.GeoPoint?.Lon,
|
||||
Mgrs = request.GeoPoint?.Mgrs,
|
||||
@@ -29,9 +28,9 @@ public class WaypointService(AppDataConnection db)
|
||||
return waypoint;
|
||||
}
|
||||
|
||||
public async Task<Waypoint> UpdateWaypoint(Guid flightId, Guid waypointId, UpdateWaypointRequest request)
|
||||
public async Task<Waypoint> UpdateWaypoint(Guid missionId, Guid waypointId, UpdateWaypointRequest request)
|
||||
{
|
||||
var waypoint = await db.Waypoints.FirstOrDefaultAsync(w => w.FlightId == flightId && w.Id == waypointId)
|
||||
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;
|
||||
@@ -46,17 +45,17 @@ public class WaypointService(AppDataConnection db)
|
||||
return waypoint;
|
||||
}
|
||||
|
||||
public async Task<List<Waypoint>> GetWaypoints(Guid flightId)
|
||||
public async Task<List<Waypoint>> GetWaypoints(Guid missionId)
|
||||
{
|
||||
return await db.Waypoints
|
||||
.Where(w => w.FlightId == flightId)
|
||||
.Where(w => w.MissionId == missionId)
|
||||
.OrderBy(w => w.OrderNum)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteWaypoint(Guid flightId, Guid waypointId)
|
||||
public async Task DeleteWaypoint(Guid missionId, Guid waypointId)
|
||||
{
|
||||
var waypoint = await db.Waypoints.FirstOrDefaultAsync(w => w.FlightId == flightId && w.Id == 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();
|
||||
@@ -69,7 +68,6 @@ public class WaypointService(AppDataConnection db)
|
||||
await db.Annotations.DeleteAsync(a => mediaIds.Contains(a.MediaId));
|
||||
}
|
||||
await db.Media.DeleteAsync(m => m.WaypointId == waypointId);
|
||||
await db.GpsCorrections.DeleteAsync(g => g.WaypointId == waypointId);
|
||||
await db.Waypoints.DeleteAsync(w => w.Id == waypointId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user