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

fixes #1452
pull/2/head
Taloth Saldono 8 years ago
parent 4bf3ef45b0
commit 713e109bc9

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

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

@ -17,15 +17,26 @@ namespace NzbDrone.Api
public static class PagingResourceMapper 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, Page = pagingResource.Page,
PageSize = pagingSpec.PageSize, PageSize = pagingResource.PageSize,
SortKey = pagingSpec.SortKey, SortKey = pagingResource.SortKey,
SortDirection = pagingSpec.SortDirection, SortDirection = pagingResource.SortDirection,
}; };
if (pagingResource.SortKey == null)
{
pagingSpec.SortKey = defaultSortKey;
if(pagingResource.SortDirection == SortDirection.Default)
{
pagingSpec.SortDirection = defaultSortDirection;
}
}
return pagingSpec;
} }
} }
} }

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

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

@ -8,6 +8,20 @@ namespace NzbDrone.Core.Test.Datastore.PagingSpecExtensionsTests
{ {
public class ToSortDirectionFixture 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] [Test]
public void should_convert_ascending_to_asc() public void should_convert_ascending_to_asc()
{ {

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

Loading…
Cancel
Save