TrackApplicationResponse.FromEntity counted track.ListeningHistories, but none of the queries that built a response ever Included it, so the collection was always empty and listensCount was always 0. Each query now projects the count as a correlated subquery before mapping to the response.
22 lines
575 B
C#
22 lines
575 B
C#
using Musify.Domain.Entities;
|
|
|
|
namespace Musify.Application.Tracks.Responses
|
|
{
|
|
public record TrackApplicationResponse(
|
|
Guid Id,
|
|
string Title,
|
|
int Duration,
|
|
int ListensCount,
|
|
DateTime CreatedAt,
|
|
DateTime UpdatedAt)
|
|
{
|
|
public static TrackApplicationResponse FromEntity(Track track, int listensCount) =>
|
|
new(
|
|
track.Id,
|
|
track.Title,
|
|
track.Duration,
|
|
listensCount,
|
|
track.CreatedAt,
|
|
track.UpdatedAt);
|
|
}
|
|
} |