mirror of
https://github.com/azaion/missions.git
synced 2026-06-21 09:51:07 +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:
+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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user