Добавлено управление сессиями

This commit is contained in:
FrigaT
2026-04-14 01:39:25 +03:00
parent 40ea9166d2
commit fbfc6990e6
22 changed files with 1509 additions and 51 deletions

View File

@@ -9,14 +9,16 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityR
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<SharedPlaylistEntity> SharedPlaylists => Set<SharedPlaylistEntity>();
public DbSet<TrackAdditionLogEntity> TrackAdditionLogs => Set<TrackAdditionLogEntity>();
public DbSet<SharedPlaylist> SharedPlaylists => Set<SharedPlaylist>();
public DbSet<TrackAdditionLog> TrackAdditionLogs => Set<TrackAdditionLog>();
public DbSet<UserSession> UserSessions => Set<UserSession>();
public DbSet<TrackRemovalLog> TrackRemovalLogs => Set<TrackRemovalLog>();
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<SharedPlaylistEntity>(entity =>
builder.Entity<SharedPlaylist>(entity =>
{
entity.HasKey(e => e.Id);
entity.HasIndex(e => e.ShareToken).IsUnique();
@@ -29,7 +31,18 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityR
entity.Property(e => e.Title).IsRequired().HasMaxLength(255);
});
builder.Entity<TrackAdditionLogEntity>(entity =>
builder.Entity<UserSession>(entity =>
{
entity.HasKey(e => e.SessionId);
entity.Property(e => e.SessionId).HasMaxLength(449);
entity.HasIndex(e => e.AssociatedUserId);
entity.HasOne(e => e.User)
.WithMany()
.HasForeignKey(e => e.AssociatedUserId)
.OnDelete(DeleteBehavior.SetNull);
});
builder.Entity<TrackAdditionLog>(entity =>
{
entity.HasKey(e => e.Id);
entity.HasIndex(e => new { e.SharedPlaylistId, e.TrackId });
@@ -41,6 +54,28 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityR
.WithMany()
.HasForeignKey(e => e.AddedByUserId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne(e => e.Session)
.WithMany(s => s.TrackAdditionLogs)
.HasForeignKey(e => e.SessionId)
.OnDelete(DeleteBehavior.Restrict);
});
builder.Entity<TrackRemovalLog>(entity =>
{
entity.HasKey(e => e.Id);
entity.HasIndex(e => new { e.SharedPlaylistId, e.TrackId });
entity.HasOne(e => e.SharedPlaylist)
.WithMany()
.HasForeignKey(e => e.SharedPlaylistId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.RemovedByUser)
.WithMany()
.HasForeignKey(e => e.RemovedByUserId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne(e => e.Session)
.WithMany(s => s.TrackRemovalLogs)
.HasForeignKey(e => e.SessionId)
.OnDelete(DeleteBehavior.Restrict);
});
}
}