Добавлен playlist shared

This commit is contained in:
FrigaT
2026-04-11 15:41:24 +03:00
parent 8444fc5f8e
commit ba9d97239e
84 changed files with 61796 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using PlaylistShared.Data.Entities;
namespace PlaylistShared.Data.Contexts;
public class AppDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<SharedPlaylist> SharedPlaylists => Set<SharedPlaylist>();
public DbSet<PlaylistTrack> PlaylistTracks => Set<PlaylistTrack>();
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<SharedPlaylist>(entity =>
{
entity.HasIndex(p => p.ShareSlug).IsUnique();
entity.OwnsOne(p => p.Permissions, per =>
{
per.Property(x => x.View).HasColumnName("PermView");
per.Property(x => x.Add).HasColumnName("PermAdd");
per.Property(x => x.Delete).HasColumnName("PermDelete");
});
});
builder.Entity<PlaylistTrack>(entity =>
{
entity.HasOne(pt => pt.Playlist)
.WithMany(p => p.Tracks)
.HasForeignKey(pt => pt.PlaylistId)
.OnDelete(DeleteBehavior.Cascade);
});
}
}

View File

@@ -0,0 +1,10 @@
namespace PlaylistShared.Data.Entities;
public class ApplicationUser : IdentityUser
{
public string? YandexId { get; set; }
public string? AccessToken { get; set; }
public string? RefreshToken { get; set; }
public DateTime? AccessTokenExpiresAt { get; set; }
public string? AvatarUrl { get; set; }
}

View File

@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
namespace PlaylistShared.Data.Entities;
public enum AccessLevel { All, Authorized, None }
public enum DeleteAccessLevel { All, Authorized, AdderOnly, OwnerOnly }
[Owned]
public class PlaylistPermissions
{
public AccessLevel View { get; set; } = AccessLevel.All;
public AccessLevel Add { get; set; } = AccessLevel.Authorized;
public DeleteAccessLevel Delete { get; set; } = DeleteAccessLevel.OwnerOnly;
}

View File

@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace PlaylistShared.Data.Entities;
public class PlaylistTrack
{
public Guid Id { get; set; }
public Guid PlaylistId { get; set; }
public SharedPlaylist Playlist { get; set; } = null!;
public string YandexTrackId { get; set; } = null!;
public string Title { get; set; } = null!;
public string? Artist { get; set; }
public string? AlbumTitle { get; set; }
public int DurationMs { get; set; }
public string? AddedByUserId { get; set; }
[ForeignKey(nameof(AddedByUserId))]
public ApplicationUser? AddedByUser { get; set; }
public DateTime AddedAt { get; set; }
}

View File

@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PlaylistShared.Data.Entities;
public class SharedPlaylist
{
[Key]
public Guid Id { get; set; }
public string OwnerUserId { get; set; } = null!;
[ForeignKey(nameof(OwnerUserId))]
public ApplicationUser Owner { get; set; } = null!;
public string YandexPlaylistId { get; set; } = null!;
public string Title { get; set; } = null!;
public string? Description { get; set; }
[Required]
public string ShareSlug { get; set; } = null!;
public PlaylistPermissions Permissions { get; set; } = new();
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public List<PlaylistTrack> Tracks { get; set; } = new();
}