Fixed api blacklist, history, wanted/missing and wanted/cutoff requiring sortKey, now defaulting to an appropriate value (airDateUtc/date desc for most).

fixes #1452
This commit is contained in:
Taloth Saldono 2016-09-10 23:05:34 +02:00
parent 4bf3ef45b0
commit 713e109bc9
7 changed files with 40 additions and 38 deletions

View File

@ -17,13 +17,7 @@ namespace NzbDrone.Api.Blacklist
private PagingResource<BlacklistResource> GetBlacklist(PagingResource<BlacklistResource> pagingResource)
{
var pagingSpec = new PagingSpec<Core.Blacklisting.Blacklist>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
var pagingSpec = pagingResource.MapToPagingSpec<BlacklistResource, Core.Blacklisting.Blacklist>("id", SortDirection.Ascending);
return ApplyToPage(_blacklistService.Paged, pagingSpec, BlacklistResourceMapper.MapToResource);
}

View File

@ -47,13 +47,7 @@ namespace NzbDrone.Api.History
{
var episodeId = Request.Query.EpisodeId;
var pagingSpec = new PagingSpec<Core.History.History>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, Core.History.History>("date", SortDirection.Descending);
if (pagingResource.FilterKey == "eventType")
{

View File

@ -17,15 +17,26 @@ namespace NzbDrone.Api
public static class PagingResourceMapper
{
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingSpec)
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingResource, string defaultSortKey = "Id", SortDirection defaultSortDirection = SortDirection.Ascending)
{
return new PagingSpec<TModel>
var pagingSpec = new PagingSpec<TModel>
{
Page = pagingSpec.Page,
PageSize = pagingSpec.PageSize,
SortKey = pagingSpec.SortKey,
SortDirection = pagingSpec.SortDirection,
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection,
};
if (pagingResource.SortKey == null)
{
pagingSpec.SortKey = defaultSortKey;
if(pagingResource.SortDirection == SortDirection.Default)
{
pagingSpec.SortDirection = defaultSortDirection;
}
}
return pagingSpec;
}
}
}

View File

@ -23,13 +23,7 @@ namespace NzbDrone.Api.Wanted
private PagingResource<EpisodeResource> GetCutoffUnmetEpisodes(PagingResource<EpisodeResource> pagingResource)
{
var pagingSpec = new PagingSpec<Episode>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
var pagingSpec = pagingResource.MapToPagingSpec<EpisodeResource, Episode>("airDateUtc", SortDirection.Descending);
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{

View File

@ -19,13 +19,7 @@ namespace NzbDrone.Api.Wanted
private PagingResource<EpisodeResource> GetMissingEpisodes(PagingResource<EpisodeResource> pagingResource)
{
var pagingSpec = new PagingSpec<Episode>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
var pagingSpec = pagingResource.MapToPagingSpec<EpisodeResource, Episode>("airDateUtc", SortDirection.Descending);
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{

View File

@ -8,6 +8,20 @@ namespace NzbDrone.Core.Test.Datastore.PagingSpecExtensionsTests
{
public class ToSortDirectionFixture
{
[Test]
public void should_convert_default_to_asc()
{
var pagingSpec = new PagingSpec<Episode>
{
Page = 1,
PageSize = 10,
SortDirection = SortDirection.Default,
SortKey = "AirDate"
};
pagingSpec.ToSortDirection().Should().Be(Marr.Data.QGen.SortDirection.Asc);
}
[Test]
public void should_convert_ascending_to_asc()
{

View File

@ -17,6 +17,7 @@ namespace NzbDrone.Core.Datastore
public enum SortDirection
{
Default,
Ascending,
Descending
}