Track.Artist was a plain string snapshot with no identity, and UserHasTrack doubled as both "in my library" and "I own this", conflating collection membership with administrative ownership. Introduce Artist/TrackArtist to give artist credits their own identity (needed so YouTube tracks with multiple credited artists, and future renames, can be modeled), and Track.OwnerUserId to represent ownership explicitly (local tracks only, enforced by a check constraint). CreateTrack now provisions the uploader's Artist row and links it via TrackArtist; DeleteTrack authorizes against OwnerUserId instead of any UserHasTrack row.
38 lines
982 B
C#
38 lines
982 B
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using Musify.Domain.Abstractions;
|
|
|
|
namespace Musify.Domain.Entities
|
|
{
|
|
#pragma warning disable CS8618
|
|
public class Artist : IAuditable
|
|
{
|
|
[Key]
|
|
public Guid Id { get; set; } = Guid.NewGuid();
|
|
|
|
[Required]
|
|
[MaxLength(200)]
|
|
public required string Name { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(200)]
|
|
public required string NormalizedName { get; set; }
|
|
|
|
public long? UserId { get; set; }
|
|
|
|
[MaxLength(64)]
|
|
public string? ExternalId { get; set; }
|
|
|
|
[Required]
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
[Required]
|
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
[ForeignKey(nameof(UserId)) ]
|
|
public User? User { get; set; }
|
|
|
|
public ICollection<TrackArtist> TrackArtists { get; set; } = new List<TrackArtist>();
|
|
}
|
|
}
|