1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Add play count to song best api

This commit is contained in:
asesidaa 2022-09-19 01:25:19 +08:00
parent 45947f0492
commit fdbeb3b4bb
2 changed files with 13 additions and 1 deletions

View File

@ -14,6 +14,8 @@ public class SongBestData
public Difficulty Difficulty { get; set; } public Difficulty Difficulty { get; set; }
public int PlayCount { get; set; }
public uint BestScore { get; set; } public uint BestScore { get; set; }
public uint BestRate { get; set; } public uint BestRate { get; set; }

View File

@ -10,10 +10,14 @@ public class PlayDataController : BaseController<PlayDataController>
private readonly ISongBestDatumService songBestDatumService; private readonly ISongBestDatumService songBestDatumService;
public PlayDataController(IUserDatumService userDatumService, ISongBestDatumService songBestDatumService) private readonly ISongPlayDatumService songPlayDatumService;
public PlayDataController(IUserDatumService userDatumService, ISongBestDatumService songBestDatumService,
ISongPlayDatumService songPlayDatumService)
{ {
this.userDatumService = userDatumService; this.userDatumService = userDatumService;
this.songBestDatumService = songBestDatumService; this.songBestDatumService = songBestDatumService;
this.songPlayDatumService = songPlayDatumService;
} }
[HttpGet("{baid}")] [HttpGet("{baid}")]
@ -26,6 +30,12 @@ public class PlayDataController : BaseController<PlayDataController>
} }
var songBestRecords = await songBestDatumService.GetAllSongBestAsModel(baid); var songBestRecords = await songBestDatumService.GetAllSongBestAsModel(baid);
var songPlayLogs = await songPlayDatumService.GetSongPlayDatumByBaid(baid);
foreach (var songBestData in songBestRecords)
{
songBestData.PlayCount = songPlayLogs.Count(datum => datum.SongId == songBestData.SongId &&
datum.Difficulty == songBestData.Difficulty);
}
var favoriteSongs = await userDatumService.GetFavoriteSongIds(baid); var favoriteSongs = await userDatumService.GetFavoriteSongIds(baid);
var favoriteSet = favoriteSongs.ToHashSet(); var favoriteSet = favoriteSongs.ToHashSet();
foreach (var songBestRecord in songBestRecords.Where(songBestRecord => favoriteSet.Contains(songBestRecord.SongId))) foreach (var songBestRecord in songBestRecords.Where(songBestRecord => favoriteSet.Contains(songBestRecord.SongId)))