Skip to content

Commit

Permalink
Undo Guid to Int
Browse files Browse the repository at this point in the history
  • Loading branch information
RespectMathias committed Nov 14, 2024
1 parent 3c3c816 commit 72a1b5a
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 99 deletions.
54 changes: 49 additions & 5 deletions GameLibrary/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,58 @@

namespace GameLibrary.Data;

public class ApplicationDbContext : IdentityDbContext<User, Role, int>
public class ApplicationDbContext : IdentityDbContext<User, Role, Guid>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

public DbSet<Game> Games { get; set; }
public DbSet<Review> Reviews { get; set; }
public DbSet<UserFavorite> UserFavorites { get; set; }
public DbSet<Game> Games => Set<Game>();
public DbSet<Review> Reviews => Set<Review>();
public DbSet<UserFavorite> UserFavorites => Set<UserFavorite>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Game configurations
modelBuilder.Entity<Game>(entity =>
{
entity.Property(e => e.Title).IsRequired().HasMaxLength(100);
entity.Property(e => e.Description).IsRequired().HasMaxLength(2000);
entity.Property(e => e.Genre).IsRequired().HasMaxLength(50);
entity.Property(e => e.Developer).IsRequired().HasMaxLength(100);
entity.Property(e => e.Publisher).IsRequired().HasMaxLength(100);
entity.Property(e => e.ImageUrl).HasMaxLength(500);
entity.Property(e => e.Rating).HasPrecision(3, 1);
});
// Review configurations
modelBuilder.Entity<Review>(entity =>
{
entity.HasOne(r => r.Game)
.WithMany(g => g.Reviews)
.HasForeignKey(r => r.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(r => r.User)
.WithMany(u => u.Reviews)
.HasForeignKey(r => r.UserId)
.OnDelete(DeleteBehavior.Cascade);
entity.Property(e => e.Comment).IsRequired().HasMaxLength(1000);
entity.Property(e => e.Rating).IsRequired();
entity.ToTable(t => t.HasCheckConstraint("CK_Review_Rating", "Rating >= 1 AND Rating <= 5"));
});
// UserFavorite configurations
modelBuilder.Entity<UserFavorite>(entity =>
{
entity.HasOne(uf => uf.User)
.WithMany(u => u.Favorites)
.HasForeignKey(uf => uf.UserId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(uf => uf.Game)
.WithMany(g => g.UserFavorites)
.HasForeignKey(uf => uf.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasIndex(e => new { e.UserId, e.GameId })
.IsUnique()
.HasDatabaseName("IX_UserFavorites_UserGame");
});
}
}
Binary file modified GameLibrary/Database.db-shm
Binary file not shown.
Binary file modified GameLibrary/Database.db-wal
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 72a1b5a

Please sign in to comment.