Make mission -> mission launches one-to-many
This commit is contained in:
+5
-6
@@ -12,7 +12,7 @@ using MissionControl.Data;
|
||||
namespace MissionControl.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MissionControlContext))]
|
||||
[Migration("20260727193151_Add_MissionLaunches")]
|
||||
[Migration("20260727222052_Add_MissionLaunches")]
|
||||
partial class Add_MissionLaunches
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -75,8 +75,7 @@ namespace MissionControl.Data.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MissionId")
|
||||
.IsUnique();
|
||||
b.HasIndex("MissionId");
|
||||
|
||||
b.ToTable("MissionLaunches");
|
||||
});
|
||||
@@ -84,8 +83,8 @@ namespace MissionControl.Data.Migrations
|
||||
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||
{
|
||||
b.HasOne("MissionControl.Domain.Entities.Mission", "Mission")
|
||||
.WithOne("MissionLaunch")
|
||||
.HasForeignKey("MissionControl.Domain.Entities.MissionLaunch", "MissionId")
|
||||
.WithMany("MissionLaunches")
|
||||
.HasForeignKey("MissionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
@@ -94,7 +93,7 @@ namespace MissionControl.Data.Migrations
|
||||
|
||||
modelBuilder.Entity("MissionControl.Domain.Entities.Mission", b =>
|
||||
{
|
||||
b.Navigation("MissionLaunch");
|
||||
b.Navigation("MissionLaunches");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
+1
-2
@@ -35,8 +35,7 @@ namespace MissionControl.Data.Migrations
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_MissionLaunches_MissionId",
|
||||
table: "MissionLaunches",
|
||||
column: "MissionId",
|
||||
unique: true);
|
||||
column: "MissionId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -72,8 +72,7 @@ namespace MissionControl.Data.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MissionId")
|
||||
.IsUnique();
|
||||
b.HasIndex("MissionId");
|
||||
|
||||
b.ToTable("MissionLaunches");
|
||||
});
|
||||
@@ -81,8 +80,8 @@ namespace MissionControl.Data.Migrations
|
||||
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||
{
|
||||
b.HasOne("MissionControl.Domain.Entities.Mission", "Mission")
|
||||
.WithOne("MissionLaunch")
|
||||
.HasForeignKey("MissionControl.Domain.Entities.MissionLaunch", "MissionId")
|
||||
.WithMany("MissionLaunches")
|
||||
.HasForeignKey("MissionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
@@ -91,7 +90,7 @@ namespace MissionControl.Data.Migrations
|
||||
|
||||
modelBuilder.Entity("MissionControl.Domain.Entities.Mission", b =>
|
||||
{
|
||||
b.Navigation("MissionLaunch");
|
||||
b.Navigation("MissionLaunches");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@ public class MissionControlContext(DbContextOptions<MissionControlContext> optio
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Mission>()
|
||||
.HasOne(mission => mission.MissionLaunch)
|
||||
.HasMany(mission => mission.MissionLaunches)
|
||||
.WithOne(missionLaunch => missionLaunch.Mission)
|
||||
.HasForeignKey<MissionLaunch>(missionLaunch => missionLaunch.MissionId);
|
||||
.HasForeignKey(missionLaunch => missionLaunch.MissionId)
|
||||
.IsRequired();
|
||||
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(MissionControlContext).Assembly);
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ public class Mission
|
||||
|
||||
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.UtcNow;
|
||||
|
||||
public MissionLaunch? MissionLaunch { get; set; }
|
||||
public ICollection<MissionLaunch> MissionLaunches { get; set; } = new List<MissionLaunch>();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public record MissionResponse
|
||||
|
||||
public required DateTimeOffset CreatedAt { get; init; }
|
||||
|
||||
public MissionLaunchResponse? MissionLaunch { get; set; }
|
||||
public IReadOnlyList<MissionLaunchResponse> MissionLaunches { get; set; } = [];
|
||||
|
||||
public static MissionResponse FromDomain(Mission mission) =>
|
||||
new()
|
||||
@@ -25,6 +25,6 @@ public record MissionResponse
|
||||
Description = mission.Description,
|
||||
Status = mission.Status,
|
||||
CreatedAt = mission.CreatedAt,
|
||||
MissionLaunch = mission.MissionLaunch != null ? MissionLaunchResponse.FromDomain(mission.MissionLaunch) : null,
|
||||
MissionLaunches = mission.MissionLaunches.Select(MissionLaunchResponse.FromDomain).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ListMissions(MissionControlContext dbContext)
|
||||
{
|
||||
var missions = await dbContext.Missions
|
||||
.AsNoTracking()
|
||||
.Include(m => m.MissionLaunch)
|
||||
.Include(m => m.MissionLaunches)
|
||||
.OrderByDescending(m => m.CreatedAt)
|
||||
.ToListAsync(ct);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MissionControl.Data;
|
||||
using MissionControl.Domain.Entities;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export type Mission = {
|
||||
description: string | null;
|
||||
status: MissionStatus;
|
||||
createdAt: string;
|
||||
missionLaunch: MissionLaunch | null;
|
||||
missionLaunches: MissionLaunch[];
|
||||
};
|
||||
|
||||
export type CreateMissionRequest = {
|
||||
|
||||
Reference in New Issue
Block a user