Mixes are their own concept, not playlists: they live in their own Mixes/MixItems tables, cannot be edited and never show up among the user's playlists. Each item is either a Musify track or a YouTube Music reference, so YouTube songs stream directly instead of being downloaded. A daily Hangfire job seeds the mixes from the listening history: one discovery mix, one daily mix and one per top artist. The per-user YouTube filler query was already in the working tree and rides along here because it shares files with this change.
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using ErrorOr;
|
|
using Mediator;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Musify.Application.Contracts;
|
|
using Musify.Application.Mixes.Responses;
|
|
|
|
namespace Musify.Application.Mixes
|
|
{
|
|
public record GetMixByIdQuery(long UserId, Guid MixId)
|
|
: IQuery<ErrorOr<MixApplicationResponse>>;
|
|
|
|
public class GetMixByIdQueryHandler(IDatabase database)
|
|
: IQueryHandler<GetMixByIdQuery, ErrorOr<MixApplicationResponse>>
|
|
{
|
|
public async ValueTask<ErrorOr<MixApplicationResponse>> Handle(GetMixByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var mix = await database.Mixes
|
|
.AsNoTracking()
|
|
.Include(mix => mix.Items)
|
|
.SingleOrDefaultAsync(mix => mix.Id == request.MixId && mix.UserId == request.UserId, cancellationToken);
|
|
|
|
if (mix is null)
|
|
return Error.NotFound(description: $"Mix {request.MixId} was not found");
|
|
|
|
var items = mix.Items.OrderBy(item => item.Position).ToList();
|
|
|
|
return MixApplicationResponse.FromEntity(mix, items.Count, items);
|
|
}
|
|
}
|
|
}
|