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.
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using ErrorOr;
|
|
using Mediator;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Musify.Application.Contracts;
|
|
using Musify.Application.Mixes.Responses;
|
|
|
|
namespace Musify.Application.Mixes
|
|
{
|
|
public record GetMixesByUserIdQuery(long UserId)
|
|
: IQuery<ErrorOr<IReadOnlyList<MixApplicationResponse>>>;
|
|
|
|
public class GetMixesByUserIdQueryHandler(IDatabase database)
|
|
: IQueryHandler<GetMixesByUserIdQuery, ErrorOr<IReadOnlyList<MixApplicationResponse>>>
|
|
{
|
|
public async ValueTask<ErrorOr<IReadOnlyList<MixApplicationResponse>>> Handle(GetMixesByUserIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var entries = await database.Mixes
|
|
.AsNoTracking()
|
|
.Where(mix => mix.UserId == request.UserId)
|
|
.OrderBy(mix => mix.Position)
|
|
.Select(mix => new
|
|
{
|
|
Mix = mix,
|
|
ItemCount = mix.Items.Count,
|
|
CoverItems = mix.Items
|
|
.OrderBy(item => item.Position)
|
|
.Take(MixApplicationResponse.CoverItemCount)
|
|
.ToList()
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return entries
|
|
.Select(entry => MixApplicationResponse.FromEntity(entry.Mix, entry.ItemCount, entry.CoverItems))
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|