diff --git a/src/Lidarr.Api.V1/Albums/AlbumModule.cs b/src/Lidarr.Api.V1/Albums/AlbumModule.cs index 889d05144..c6bd9b2f4 100644 --- a/src/Lidarr.Api.V1/Albums/AlbumModule.cs +++ b/src/Lidarr.Api.V1/Albums/AlbumModule.cs @@ -29,10 +29,12 @@ namespace Lidarr.Api.V1.Albums IHandle, IHandle { + protected readonly IArtistService _artistService; protected readonly IReleaseService _releaseService; protected readonly IAddAlbumService _addAlbumService; - public AlbumModule(IAlbumService albumService, + public AlbumModule(IArtistService artistService, + IAlbumService albumService, IAddAlbumService addAlbumService, IReleaseService releaseService, IArtistStatisticsService artistStatisticsService, @@ -44,6 +46,7 @@ namespace Lidarr.Api.V1.Albums : base(albumService, artistStatisticsService, coverMapper, upgradableSpecification, signalRBroadcaster) { + _artistService = artistService; _releaseService = releaseService; _addAlbumService = addAlbumService; @@ -69,7 +72,25 @@ namespace Lidarr.Api.V1.Albums if (!Request.Query.ArtistId.HasValue && !albumIdsQuery.HasValue && !foreignIdQuery.HasValue) { - return MapToResource(_albumService.GetAllAlbums(), false); + var albums = _albumService.GetAllAlbums(); + + var artists = _artistService.GetAllArtists().ToDictionary(x => x.ArtistMetadataId); + var releases = _releaseService.GetAllReleases().GroupBy(x => x.AlbumId).ToDictionary(x => x.Key, y => y.ToList()); + + foreach (var album in albums) + { + album.Artist = artists[album.ArtistMetadataId]; + if (releases.TryGetValue(album.Id, out var albumReleases)) + { + album.AlbumReleases = albumReleases; + } + else + { + album.AlbumReleases = new List(); + } + } + + return MapToResource(albums, false); } if (artistIdQuery.HasValue) diff --git a/src/NzbDrone.Core/Music/Services/ReleaseService.cs b/src/NzbDrone.Core/Music/Services/ReleaseService.cs index 7b86ced1a..69b33613c 100644 --- a/src/NzbDrone.Core/Music/Services/ReleaseService.cs +++ b/src/NzbDrone.Core/Music/Services/ReleaseService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Music.Events; @@ -8,6 +9,7 @@ namespace NzbDrone.Core.Music { AlbumRelease GetRelease(int id); AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false); + List GetAllReleases(); void InsertMany(List releases); void UpdateMany(List releases); void DeleteMany(List releases); @@ -40,6 +42,11 @@ namespace NzbDrone.Core.Music return _releaseRepository.FindByForeignReleaseId(foreignReleaseId, checkRedirect); } + public List GetAllReleases() + { + return _releaseRepository.All().ToList(); + } + public void InsertMany(List releases) { _releaseRepository.InsertMany(releases);