chore: cringed very hard

This commit is contained in:
2025-10-01 22:44:15 +03:00
parent 40342a0e14
commit 2a29571dbf
7 changed files with 86 additions and 81 deletions

View File

@@ -11,7 +11,9 @@ namespace LctMonolith.Database.Data;
/// </summary>
public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) {
Database.EnsureCreated();
}
// Rank related entities
public DbSet<Rank> Ranks => Set<Rank>();
@@ -92,7 +94,7 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
.WithMany(m => m.ChildMissions)
.HasForeignKey(m => m.ParentMissionId)
.IsRequired(false);
// Dialogue relationship for Mission
// Dialogue relationship for Mission (optional dialogue for a mission)
b.Entity<Mission>()
.HasOne(m => m.Dialogue)
.WithOne(d => d.Mission)
@@ -171,31 +173,28 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
.WithMany(m => m.PlayerMissions)
.HasForeignKey(pm => pm.MissionId);
// Dialogue configurations
// Dialogue configurations (Mission required for Dialogue)
b.Entity<Dialogue>()
.HasOne(d => d.Mission)
.WithOne(m => m.Dialogue)
.HasForeignKey<Dialogue>(d => d.MissionId)
.IsRequired();
// DialogueMessage configurations
b.Entity<DialogueMessage>()
.HasOne(dm => dm.InitialDialogue)
// Dialogue -> DialogueMessage relationships (three distinct message slots)
b.Entity<Dialogue>()
.HasOne(d => d.InitialDialogueMessage)
.WithMany()
.HasForeignKey(dm => dm.InitialDialogueId)
.IsRequired(false)
.HasForeignKey(d => d.InitialDialogueMessageId)
.OnDelete(DeleteBehavior.Restrict);
b.Entity<DialogueMessage>()
.HasOne(dm => dm.InterimDialogue)
b.Entity<Dialogue>()
.HasOne(d => d.InterimDialogueMessage)
.WithMany()
.HasForeignKey(dm => dm.InterimDialogueId)
.IsRequired(false)
.HasForeignKey(d => d.InterimDialogueMessageId)
.OnDelete(DeleteBehavior.Restrict);
b.Entity<DialogueMessage>()
.HasOne(dm => dm.EndDialogue)
b.Entity<Dialogue>()
.HasOne(d => d.EndDialogueMessage)
.WithMany()
.HasForeignKey(dm => dm.EndDialogueId)
.IsRequired(false)
.HasForeignKey(d => d.EndDialogueMessageId)
.OnDelete(DeleteBehavior.Restrict);
// DialogueMessageResponseOption configurations
@@ -211,6 +210,18 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
.IsRequired(false)
.OnDelete(DeleteBehavior.Restrict);
// UserInventoryItem composite key & relationships
b.Entity<UserInventoryItem>()
.HasKey(ui => new { ui.UserId, ui.StoreItemId });
b.Entity<UserInventoryItem>()
.HasOne(ui => ui.User)
.WithMany(u => u.Inventory)
.HasForeignKey(ui => ui.UserId);
b.Entity<UserInventoryItem>()
.HasOne(ui => ui.StoreItem)
.WithMany(si => si.UserInventory)
.HasForeignKey(ui => ui.StoreItemId);
// Refresh token index unique
b.Entity<RefreshToken>().HasIndex(x => x.Token).IsUnique();

View File

@@ -12,36 +12,36 @@ public static class DbSeeder
{
public static async Task SeedAsync(AppDbContext db, CancellationToken ct = default)
{
await db.Database.EnsureCreatedAsync(ct);
if (!await db.Ranks.AnyAsync(ct))
{
var ranks = new List<Rank>
{
new() { Title = "Искатель", ExpNeeded = 0 },
new() { Title = "Пилот-кандидат", ExpNeeded = 500 },
new() { Title = "Принятый в экипаж", ExpNeeded = 1500 }
};
db.Ranks.AddRange(ranks);
Log.Information("Seeded {Count} ranks", ranks.Count);
}
if (!await db.Skills.AnyAsync(ct))
{
var comps = new[]
{
"Вера в дело","Стремление к большему","Общение","Аналитика","Командование","Юриспруденция","Трёхмерное мышление","Базовая экономика","Основы аэронавигации"
}.Select(n => new Skill { Title = n });
db.Skills.AddRange(comps);
Log.Information("Seeded competencies");
}
if (!await db.StoreItems.AnyAsync(ct))
{
db.StoreItems.AddRange(new StoreItem { Name = "Футболка Алабуга", Price = 100 }, new StoreItem { Name = "Брелок Буран", Price = 50 });
Log.Information("Seeded store items");
}
await db.SaveChangesAsync(ct);
// await db.Database.EnsureCreatedAsync(ct);
//
// if (!await db.Ranks.AnyAsync(ct))
// {
// var ranks = new List<Rank>
// {
// new() { Title = "Искатель", ExpNeeded = 0 },
// new() { Title = "Пилот-кандидат", ExpNeeded = 500 },
// new() { Title = "Принятый в экипаж", ExpNeeded = 1500 }
// };
// db.Ranks.AddRange(ranks);
// Log.Information("Seeded {Count} ranks", ranks.Count);
// }
//
// if (!await db.Skills.AnyAsync(ct))
// {
// var comps = new[]
// {
// "Вера в дело","Стремление к большему","Общение","Аналитика","Командование","Юриспруденция","Трёхмерное мышление","Базовая экономика","Основы аэронавигации"
// }.Select(n => new Skill { Title = n });
// db.Skills.AddRange(comps);
// Log.Information("Seeded competencies");
// }
//
// if (!await db.StoreItems.AnyAsync(ct))
// {
// db.StoreItems.AddRange(new StoreItem { Name = "Футболка Алабуга", Price = 100 }, new StoreItem { Name = "Брелок Буран", Price = 50 });
// Log.Information("Seeded store items");
// }
//
// await db.SaveChangesAsync(ct);
}
}

View File

@@ -1,21 +1,22 @@
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8081
EXPOSE 8080
ARG BUILD_CONFIGURATION=Release
ENV ASPNETCORE_URLS=http://+:8080
COPY ["LctMonolith/LctMonolith.csproj", "LctMonolith/"]
RUN dotnet restore "LctMonolith/LctMonolith.csproj"
USER app
WORKDIR "/src/LctMonolith"
RUN dotnet build "./LctMonolith.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG configuration=Release
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LctMonolith.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
WORKDIR /src
COPY ["LctMonolith.csproj", "./"]

View File

@@ -8,9 +8,9 @@ public class Dialogue
public required Mission Mission { get; set; }
public Guid InitialDialogueMessageId { get; set; }
public Dialogue? InitialDialogueMessage { get; set; }
public DialogueMessage? InitialDialogueMessage { get; set; }
public Guid InterimDialogueMessageId { get; set; }
public Dialogue? InterimDialogueMessage { get; set; }
public DialogueMessage? InterimDialogueMessage { get; set; }
public Guid EndDialogueMessageId { get; set; }
public Dialogue? EndDialogueMessage { get; set; }
public DialogueMessage? EndDialogueMessage { get; set; }
}

View File

@@ -16,12 +16,5 @@ public class DialogueMessage
public bool AllowMessageAi { get; set; }
public string MessageAiButtonText { get; set; } = string.Empty;
public Guid InitialDialogueId { get; set; }
public Dialogue? InitialDialogue { get; set; }
public Guid InterimDialogueId { get; set; }
public Dialogue? InterimDialogue { get; set; }
public Guid EndDialogueId { get; set; }
public Dialogue? EndDialogue { get; set; }
public ICollection<DialogueMessageResponseOption> DialogueMessageResponseOptions = new List<DialogueMessageResponseOption>();
}

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Port=5432;Database=lct2025_dev;Username=postgres;Password=postgres"
"Default": "Host=postgres;Port=5432;Database=lct2025_dev;Username=postgres;Password=postgres"
},
"Jwt": {
"Key": "Dev_Insecure_Key_Change_Me",

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Port=5432;Database=lct2025;Username=postgres;Password=postgres"
"Default": "Host=postgres;Port=5432;Database=lct2025;Username=postgres;Password=postgres"
},
"Jwt": {
"Key": "Dev_Insecure_Key_Change_Me",