Fixed: Artist/album history loading

Closes #3195
Fixes #3312
This commit is contained in:
Qstick 2023-01-24 22:27:45 -06:00
commit d37b226fd4

View file

@ -12,6 +12,7 @@ using NzbDrone.Core.Datastore;
using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.Music;
namespace Lidarr.Api.V1.History namespace Lidarr.Api.V1.History
{ {
@ -22,16 +23,19 @@ namespace Lidarr.Api.V1.History
private readonly ICustomFormatCalculationService _formatCalculator; private readonly ICustomFormatCalculationService _formatCalculator;
private readonly IUpgradableSpecification _upgradableSpecification; private readonly IUpgradableSpecification _upgradableSpecification;
private readonly IFailedDownloadService _failedDownloadService; private readonly IFailedDownloadService _failedDownloadService;
private readonly IArtistService _artistService;
public HistoryController(IHistoryService historyService, public HistoryController(IHistoryService historyService,
ICustomFormatCalculationService formatCalculator, ICustomFormatCalculationService formatCalculator,
IUpgradableSpecification upgradableSpecification, IUpgradableSpecification upgradableSpecification,
IFailedDownloadService failedDownloadService) IFailedDownloadService failedDownloadService,
IArtistService artistService)
{ {
_historyService = historyService; _historyService = historyService;
_formatCalculator = formatCalculator; _formatCalculator = formatCalculator;
_upgradableSpecification = upgradableSpecification; _upgradableSpecification = upgradableSpecification;
_failedDownloadService = failedDownloadService; _failedDownloadService = failedDownloadService;
_artistService = artistService;
} }
protected HistoryResource MapToResource(EntityHistory model, bool includeArtist, bool includeAlbum, bool includeTrack) protected HistoryResource MapToResource(EntityHistory model, bool includeArtist, bool includeAlbum, bool includeTrack)
@ -101,12 +105,24 @@ namespace Lidarr.Api.V1.History
[HttpGet("artist")] [HttpGet("artist")]
public List<HistoryResource> GetArtistHistory(int artistId, int? albumId = null, EntityHistoryEventType? eventType = null, bool includeArtist = false, bool includeAlbum = false, bool includeTrack = false) public List<HistoryResource> GetArtistHistory(int artistId, int? albumId = null, EntityHistoryEventType? eventType = null, bool includeArtist = false, bool includeAlbum = false, bool includeTrack = false)
{ {
var artist = _artistService.GetArtist(artistId);
if (albumId.HasValue) if (albumId.HasValue)
{ {
return _historyService.GetByAlbum(albumId.Value, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList(); return _historyService.GetByAlbum(albumId.Value, eventType).Select(h =>
{
h.Artist = artist;
return MapToResource(h, includeArtist, includeAlbum, includeTrack);
}).ToList();
} }
return _historyService.GetByArtist(artistId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList(); return _historyService.GetByArtist(artistId, eventType).Select(h =>
{
h.Artist = artist;
return MapToResource(h, includeArtist, includeAlbum, includeTrack);
}).ToList();
} }
[HttpPost("failed/{id}")] [HttpPost("failed/{id}")]