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).
72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
using ErrorOr;
|
|
using Mediator;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using Musify.Domain.Entities;
|
|
using Musify.Domain.ValueObjects;
|
|
using Musify.Application.Events;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Application.Tracks
|
|
{
|
|
public record DeleteTrackCommand(
|
|
long UserId,
|
|
Guid TrackId)
|
|
: ICommand<ErrorOr<Success>>;
|
|
|
|
public class DeleteTrackCommandHandler(
|
|
IDatabase database,
|
|
IEventBus eventBus,
|
|
ILogger<DeleteTrackCommandHandler> logger)
|
|
: ICommandHandler<DeleteTrackCommand, ErrorOr<Success>>
|
|
{
|
|
public async ValueTask<ErrorOr<Success>> Handle(DeleteTrackCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var track = await database.Tracks.SingleOrDefaultAsync(t => t.Id == request.TrackId, cancellationToken);
|
|
if (track is null)
|
|
{
|
|
logger.LogInformation("Track {TrackId} not found", request.TrackId);
|
|
return Error.NotFound();
|
|
}
|
|
|
|
if (track.OwnerUserId != request.UserId)
|
|
{
|
|
logger.LogWarning("User {UserId} unauthorized to delete track {TrackId}", request.UserId, request.TrackId);
|
|
return Error.Unauthorized();
|
|
}
|
|
|
|
if (track.Audio.IsInProgress)
|
|
{
|
|
logger.LogWarning("Track {TrackId} is currently being processed and cannot be deleted", request.TrackId);
|
|
return Error.Conflict(description: "Track is currently being processed and cannot be deleted");
|
|
}
|
|
|
|
track.LifeCycleStatus = LifeCycleStatus.Removing;
|
|
|
|
try
|
|
{
|
|
await eventBus.PublishAsync(
|
|
new DeleteTrackEvent(track.Id, request.UserId),
|
|
cancellationToken);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogError(exception, "Failed to publish delete track event for track {TrackId}", request.TrackId);
|
|
return Error.Failure(description: $"Failed to delete track {request.TrackId}");
|
|
}
|
|
|
|
try
|
|
{
|
|
await database.SaveChangesAsync(cancellationToken);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogError(exception, "Failed to mark track {TrackId} as processing before deletion", request.TrackId);
|
|
return Error.Failure(description: $"Failed to delete track {request.TrackId}");
|
|
}
|
|
|
|
return new Success();
|
|
}
|
|
}
|
|
}
|