Drops the YouTube-backed second catalog source entirely: the Local/External split on Track/Album collapses into single concrete entities, Artist/TrackArtist/ExternalTrack/ExternalAlbum and the YouTube service/download pipeline (yt-dlp, MassTransit consumer, routing slip) are deleted, and mixes now source discovery only from local listening history. Includes the RemoveYouTubeIntegration EF Core migration and matching Worker/deploy/compose cleanup (no more yt-dlp/python/deno in the Worker image, no thumbnail-cache/YtDlp config sections).
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using ErrorOr;
|
|
using Mediator;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Application.Albums
|
|
{
|
|
public record DeleteAlbumCommand(long UserId, Guid AlbumId)
|
|
: ICommand<ErrorOr<Success>>;
|
|
|
|
public class DeleteAlbumCommandHandler(
|
|
IDatabase database,
|
|
ILogger<DeleteAlbumCommandHandler> logger)
|
|
: ICommandHandler<DeleteAlbumCommand, ErrorOr<Success>>
|
|
{
|
|
public async ValueTask<ErrorOr<Success>> Handle(DeleteAlbumCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var album = await database.Albums
|
|
.SingleOrDefaultAsync(a => a.Id == request.AlbumId, cancellationToken);
|
|
if (album is null)
|
|
{
|
|
logger.LogDebug("Album {AlbumId} not found", request.AlbumId);
|
|
return Error.NotFound();
|
|
}
|
|
|
|
if (album.OwnerUserId != request.UserId)
|
|
{
|
|
logger.LogWarning("Album {AlbumId} does not belong to user {UserId}", request.AlbumId, request.UserId);
|
|
return Error.Unauthorized();
|
|
}
|
|
|
|
database.Albums.Remove(album);
|
|
|
|
try
|
|
{
|
|
await database.SaveChangesAsync(cancellationToken);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogError(exception, "Failed to delete album {AlbumId}", request.AlbumId);
|
|
return Error.Failure(description: $"Failed to delete album {request.AlbumId}");
|
|
}
|
|
|
|
logger.LogInformation("Deleted album {AlbumId} for user {UserId}", request.AlbumId, request.UserId);
|
|
|
|
return new Success();
|
|
}
|
|
}
|
|
}
|