Добавлен playlist shared
This commit is contained in:
37
PlaylistShared/Data/Contexts/AppDbContext.cs
Normal file
37
PlaylistShared/Data/Contexts/AppDbContext.cs
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
10
PlaylistShared/Data/Entities/ApplicationUser.cs
Normal file
10
PlaylistShared/Data/Entities/ApplicationUser.cs
Normal 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; }
|
||||
}
|
||||
14
PlaylistShared/Data/Entities/PlaylistPermissions.cs
Normal file
14
PlaylistShared/Data/Entities/PlaylistPermissions.cs
Normal 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;
|
||||
}
|
||||
23
PlaylistShared/Data/Entities/PlaylistTrack.cs
Normal file
23
PlaylistShared/Data/Entities/PlaylistTrack.cs
Normal 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; }
|
||||
}
|
||||
28
PlaylistShared/Data/Entities/SharedPlaylist.cs
Normal file
28
PlaylistShared/Data/Entities/SharedPlaylist.cs
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user