New: Artist History Modal in Artist Details Page

This commit is contained in:
Qstick 2017-12-13 22:38:27 -05:00
parent 0981260887
commit 7e4a8c8ff7
17 changed files with 659 additions and 96 deletions

View file

@ -31,6 +31,7 @@ namespace Lidarr.Api.V1.History
GetResourcePaged = GetHistory;
Get["/since"] = x => GetHistorySince();
Get["/artist"] = x => GetArtistHistory();
Post["/failed"] = x => MarkAsFailed();
}
@ -109,6 +110,38 @@ namespace Lidarr.Api.V1.History
return _historyService.Since(date, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
}
private List<HistoryResource> GetArtistHistory()
{
var queryArtistId = Request.Query.ArtistId;
var queryAlbumId = Request.Query.AlbumId;
var queryEventType = Request.Query.EventType;
if (!queryArtistId.HasValue)
{
throw new BadRequestException("artistId is missing");
}
int artistId = Convert.ToInt32(queryArtistId.Value);
HistoryEventType? eventType = null;
var includeArtist = Request.GetBooleanQueryParameter("includeArtist");
var includeAlbum = Request.GetBooleanQueryParameter("includeAlbum");
var includeTrack = Request.GetBooleanQueryParameter("includeTrack");
if (queryEventType.HasValue)
{
eventType = (HistoryEventType)Convert.ToInt32(queryEventType.Value);
}
if (queryAlbumId.HasValue)
{
int albumId = Convert.ToInt32(queryAlbumId.Value);
return _historyService.GetByAlbum(artistId, albumId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
}
return _historyService.GetByArtist(artistId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
}
private Response MarkAsFailed()
{
var id = (int)Request.Form.Id;

View file

@ -14,6 +14,8 @@ namespace NzbDrone.Core.History
History MostRecentForAlbum(int albumId);
History MostRecentForDownloadId(string downloadId);
List<History> FindByDownloadId(string downloadId);
List<History> GetByArtist(int artistId, HistoryEventType? eventType);
List<History> GetByAlbum(int artistId, int albumId, HistoryEventType? eventType);
List<History> FindDownloadHistory(int idArtistId, QualityModel quality);
void DeleteForArtist(int artistId);
List<History> Since(DateTime date, HistoryEventType? eventType);
@ -48,6 +50,36 @@ namespace NzbDrone.Core.History
return Query.Where(h => h.DownloadId == downloadId);
}
public List<History> GetByArtist(int artistId, HistoryEventType? eventType)
{
var query = Query.Where(h => h.ArtistId == artistId);
if (eventType.HasValue)
{
query.AndWhere(h => h.EventType == eventType);
}
query.OrderByDescending(h => h.Date);
return query;
}
public List<History> GetByAlbum(int artistId, int albumId, HistoryEventType? eventType)
{
var query = Query.Join<History, Album>(JoinType.Inner, h => h.Album, (h, e) => h.AlbumId == e.Id)
.Where(h => h.ArtistId == artistId)
.AndWhere(h => h.AlbumId == albumId);
if (eventType.HasValue)
{
query.AndWhere(h => h.EventType == eventType);
}
query.OrderByDescending(h => h.Date);
return query;
}
public List<History> FindDownloadHistory(int idArtistId, QualityModel quality)
{
return Query.Where(h =>

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Marr.Data.QGen;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
@ -13,7 +14,7 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Profiles.Languages;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Music;
using NzbDrone.Core.Music.Events;
namespace NzbDrone.Core.History
@ -24,6 +25,8 @@ namespace NzbDrone.Core.History
History MostRecentForAlbum(int episodeId);
History MostRecentForDownloadId(string downloadId);
History Get(int historyId);
List<History> GetByArtist(int artistId, HistoryEventType? eventType);
List<History> GetByAlbum(int artistId, int albumId, HistoryEventType? eventType);
List<History> Find(string downloadId, HistoryEventType eventType);
List<History> FindByDownloadId(string downloadId);
List<History> Since(DateTime date, HistoryEventType? eventType);
@ -66,6 +69,16 @@ namespace NzbDrone.Core.History
return _historyRepository.Get(historyId);
}
public List<History> GetByArtist(int artistId, HistoryEventType? eventType)
{
return _historyRepository.GetByArtist(artistId, eventType);
}
public List<History> GetByAlbum(int artistId, int albumId, HistoryEventType? eventType)
{
return _historyRepository.GetByAlbum(artistId, albumId, eventType);
}
public List<History> Find(string downloadId, HistoryEventType eventType)
{
return _historyRepository.FindByDownloadId(downloadId).Where(c => c.EventType == eventType).ToList();