mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
New: Readarr 0.1
This commit is contained in:
@@ -8,7 +8,6 @@ using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.History;
|
||||
using Readarr.Api.V1.Albums;
|
||||
using Readarr.Api.V1.Artist;
|
||||
using Readarr.Api.V1.Tracks;
|
||||
using Readarr.Http;
|
||||
using Readarr.Http.Extensions;
|
||||
using Readarr.Http.REST;
|
||||
@@ -35,7 +34,7 @@ namespace Readarr.Api.V1.History
|
||||
Post("/failed", x => MarkAsFailed());
|
||||
}
|
||||
|
||||
protected HistoryResource MapToResource(NzbDrone.Core.History.History model, bool includeArtist, bool includeAlbum, bool includeTrack)
|
||||
protected HistoryResource MapToResource(NzbDrone.Core.History.History model, bool includeArtist, bool includeAlbum)
|
||||
{
|
||||
var resource = model.ToResource();
|
||||
|
||||
@@ -49,11 +48,6 @@ namespace Readarr.Api.V1.History
|
||||
resource.Album = model.Album.ToResource();
|
||||
}
|
||||
|
||||
if (includeTrack)
|
||||
{
|
||||
resource.Track = model.Track.ToResource();
|
||||
}
|
||||
|
||||
if (model.Artist != null)
|
||||
{
|
||||
resource.QualityCutoffNotMet = _upgradableSpecification.QualityCutoffNotMet(model.Artist.QualityProfile.Value, model.Quality);
|
||||
@@ -67,10 +61,9 @@ namespace Readarr.Api.V1.History
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, NzbDrone.Core.History.History>("date", SortDirection.Descending);
|
||||
var includeArtist = Request.GetBooleanQueryParameter("includeArtist");
|
||||
var includeAlbum = Request.GetBooleanQueryParameter("includeAlbum");
|
||||
var includeTrack = Request.GetBooleanQueryParameter("includeTrack");
|
||||
|
||||
var eventTypeFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "eventType");
|
||||
var albumIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "albumId");
|
||||
var bookIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "bookId");
|
||||
var downloadIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "downloadId");
|
||||
|
||||
if (eventTypeFilter != null)
|
||||
@@ -79,10 +72,10 @@ namespace Readarr.Api.V1.History
|
||||
pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue);
|
||||
}
|
||||
|
||||
if (albumIdFilter != null)
|
||||
if (bookIdFilter != null)
|
||||
{
|
||||
var albumId = Convert.ToInt32(albumIdFilter.Value);
|
||||
pagingSpec.FilterExpressions.Add(h => h.AlbumId == albumId);
|
||||
var bookId = Convert.ToInt32(bookIdFilter.Value);
|
||||
pagingSpec.FilterExpressions.Add(h => h.BookId == bookId);
|
||||
}
|
||||
|
||||
if (downloadIdFilter != null)
|
||||
@@ -91,7 +84,7 @@ namespace Readarr.Api.V1.History
|
||||
pagingSpec.FilterExpressions.Add(h => h.DownloadId == downloadId);
|
||||
}
|
||||
|
||||
return ApplyToPage(_historyService.Paged, pagingSpec, h => MapToResource(h, includeArtist, includeAlbum, includeTrack));
|
||||
return ApplyToPage(_historyService.Paged, pagingSpec, h => MapToResource(h, includeArtist, includeAlbum));
|
||||
}
|
||||
|
||||
private List<HistoryResource> GetHistorySince()
|
||||
@@ -108,46 +101,44 @@ namespace Readarr.Api.V1.History
|
||||
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);
|
||||
}
|
||||
|
||||
return _historyService.Since(date, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
|
||||
return _historyService.Since(date, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum)).ToList();
|
||||
}
|
||||
|
||||
private List<HistoryResource> GetArtistHistory()
|
||||
{
|
||||
var queryArtistId = Request.Query.ArtistId;
|
||||
var queryAlbumId = Request.Query.AlbumId;
|
||||
var queryAuthorId = Request.Query.AuthorId;
|
||||
var queryBookId = Request.Query.BookId;
|
||||
var queryEventType = Request.Query.EventType;
|
||||
|
||||
if (!queryArtistId.HasValue)
|
||||
if (!queryAuthorId.HasValue)
|
||||
{
|
||||
throw new BadRequestException("artistId is missing");
|
||||
throw new BadRequestException("authorId is missing");
|
||||
}
|
||||
|
||||
int artistId = Convert.ToInt32(queryArtistId.Value);
|
||||
int authorId = Convert.ToInt32(queryAuthorId.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)
|
||||
if (queryBookId.HasValue)
|
||||
{
|
||||
int albumId = Convert.ToInt32(queryAlbumId.Value);
|
||||
int bookId = Convert.ToInt32(queryBookId.Value);
|
||||
|
||||
return _historyService.GetByAlbum(albumId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
|
||||
return _historyService.GetByAlbum(bookId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum)).ToList();
|
||||
}
|
||||
|
||||
return _historyService.GetByArtist(artistId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum, includeTrack)).ToList();
|
||||
return _historyService.GetByArtist(authorId, eventType).Select(h => MapToResource(h, includeArtist, includeAlbum)).ToList();
|
||||
}
|
||||
|
||||
private object MarkAsFailed()
|
||||
|
||||
Reference in New Issue
Block a user