feat(backend): expose track duration and listen count in track response

This commit is contained in:
2026-07-14 13:54:12 +02:00
parent afac7d5dd5
commit 2e866075a2
3 changed files with 13 additions and 1 deletions
@@ -5,14 +5,20 @@ namespace Musify.Application.Tracks.Responses
public record TrackApplicationResponse( public record TrackApplicationResponse(
Guid Id, Guid Id,
string Title, string Title,
int Duration,
int ListensCount,
DateTime CreatedAt, DateTime CreatedAt,
DateTime UpdatedAt) DateTime UpdatedAt)
{ {
public static TrackApplicationResponse FromEntity(Track track) public static TrackApplicationResponse FromEntity(Track track)
{ {
var count = track.ListeningHistories.Count(x => x.TrackId == track.Id);
return new TrackApplicationResponse( return new TrackApplicationResponse(
track.Id, track.Id,
track.Title, track.Title,
track.Duration,
count,
track.CreatedAt, track.CreatedAt,
track.UpdatedAt); track.UpdatedAt);
} }
+5 -1
View File
@@ -1,7 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Musify.Domain.Abstractions; using Musify.Domain.Abstractions;
using Musify.Domain.ValueObjects; using Musify.Domain.ValueObjects;
@@ -21,6 +20,9 @@ namespace Musify.Domain.Entities
[MaxLength(50)] [MaxLength(50)]
public required string NormalizedTitle { get; set; } public required string NormalizedTitle { get; set; }
[Required]
public int Duration { get; set; }
[Required] [Required]
[MaxLength(64)] [MaxLength(64)]
public required string OriginalPictureName { get; set; } public required string OriginalPictureName { get; set; }
@@ -65,6 +67,8 @@ namespace Musify.Domain.Entities
public ICollection<PlayListHasTrack> PlayListTracks { get; set; } = new List<PlayListHasTrack>(); public ICollection<PlayListHasTrack> PlayListTracks { get; set; } = new List<PlayListHasTrack>();
public ICollection<ListeningHistory> ListeningHistories { get; set; } = new List<ListeningHistory>();
[NotMapped] [NotMapped]
[MemberNotNullWhen(true, nameof(SmallPictureName)) ] [MemberNotNullWhen(true, nameof(SmallPictureName)) ]
[MemberNotNullWhen(true, nameof(MediumPictureName)) ] [MemberNotNullWhen(true, nameof(MediumPictureName)) ]
+2
View File
@@ -37,5 +37,7 @@ namespace Musify.Domain.Entities
public ICollection<UserHasTrack> UserTracks { get; set; } = new List<UserHasTrack>(); public ICollection<UserHasTrack> UserTracks { get; set; } = new List<UserHasTrack>();
public ICollection<PlayList> PlayLists { get; set; } = new List<PlayList>(); public ICollection<PlayList> PlayLists { get; set; } = new List<PlayList>();
public ICollection<ListeningHistory> ListeningHistories { get; set; } = new List<ListeningHistory>();
} }
} }