[FA-27] Bookmark implementation
This commit is contained in:
@@ -1,11 +1,35 @@
|
||||
using FictionArchive.Service.Shared.Services.Database;
|
||||
using FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.Service.UserNovelDataService.Services;
|
||||
|
||||
public class UserNovelDataServiceDbContext : FictionArchiveDbContext
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Bookmark> Bookmarks { get; set; }
|
||||
|
||||
public UserNovelDataServiceDbContext(DbContextOptions options, ILogger<UserNovelDataServiceDbContext> logger) : base(options, logger)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Bookmark>(entity =>
|
||||
{
|
||||
// Unique constraint: one bookmark per chapter per user
|
||||
entity.HasIndex(b => new { b.UserId, b.ChapterId }).IsUnique();
|
||||
|
||||
// Index for efficient "get bookmarks for novel" queries
|
||||
entity.HasIndex(b => new { b.UserId, b.NovelId });
|
||||
|
||||
// User relationship
|
||||
entity.HasOne(b => b.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(b => b.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user