Upgrade to .NET 10 and finalize foundation scaffold
This commit is contained in:
61
Data/AppDbContext.cs
Normal file
61
Data/AppDbContext.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using GameList.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GameList.Data;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Player> Players => Set<Player>();
|
||||
public DbSet<Suggestion> Suggestions => Set<Suggestion>();
|
||||
public DbSet<Vote> Votes => Set<Vote>();
|
||||
public DbSet<AppState> AppState => Set<AppState>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Player>(builder =>
|
||||
{
|
||||
builder.HasKey(p => p.Id);
|
||||
builder.Property(p => p.DisplayName).HasMaxLength(64);
|
||||
builder.HasMany(p => p.Suggestions)
|
||||
.WithOne(s => s.Player!)
|
||||
.HasForeignKey(s => s.PlayerId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasMany(p => p.Votes)
|
||||
.WithOne(v => v.Player!)
|
||||
.HasForeignKey(v => v.PlayerId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Suggestion>(builder =>
|
||||
{
|
||||
builder.HasKey(s => s.Id);
|
||||
builder.Property(s => s.Name).IsRequired().HasMaxLength(100);
|
||||
builder.Property(s => s.Genre).HasMaxLength(50);
|
||||
builder.Property(s => s.Description).HasMaxLength(500);
|
||||
builder.Property(s => s.ScreenshotUrl).HasMaxLength(2048);
|
||||
builder.Property(s => s.YoutubeUrl).HasMaxLength(2048);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Vote>(builder =>
|
||||
{
|
||||
builder.HasKey(v => v.Id);
|
||||
builder.Property(v => v.Score).IsRequired();
|
||||
builder.HasIndex(v => new { v.PlayerId, v.SuggestionId }).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AppState>(builder =>
|
||||
{
|
||||
builder.HasKey(s => s.Id);
|
||||
builder.HasData(new AppState
|
||||
{
|
||||
Id = 1,
|
||||
CurrentPhase = Phase.Suggest,
|
||||
UpdatedAt = DateTimeOffset.UtcNow
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user