2013-03-21 04:02:57 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-05-02 07:50:34 +02:00
|
|
|
|
using System.ComponentModel;
|
2013-03-21 04:02:57 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Nancy;
|
2013-05-01 02:25:33 +02:00
|
|
|
|
using NzbDrone.Api.Episodes;
|
2013-03-21 04:02:57 +01:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-05-02 07:50:34 +02:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-03-21 04:02:57 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Missing
|
|
|
|
|
{
|
|
|
|
|
public class MissingModule : NzbDroneApiModule
|
|
|
|
|
{
|
2013-04-01 08:22:16 +02:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-03-21 04:02:57 +01:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
public MissingModule(IEpisodeService episodeService)
|
2013-03-21 04:02:57 +01:00
|
|
|
|
: base("/missing")
|
|
|
|
|
{
|
|
|
|
|
_episodeService = episodeService;
|
|
|
|
|
Get["/"] = x => GetMissingEpisodes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetMissingEpisodes()
|
|
|
|
|
{
|
|
|
|
|
bool includeSpecials;
|
|
|
|
|
Boolean.TryParse(PrimitiveExtensions.ToNullSafeString(Request.Query.IncludeSpecials), out includeSpecials);
|
|
|
|
|
|
2013-05-02 07:50:34 +02:00
|
|
|
|
int pageSize;
|
|
|
|
|
Int32.TryParse(PrimitiveExtensions.ToNullSafeString(Request.Query.PageSize), out pageSize);
|
|
|
|
|
if (pageSize == 0) pageSize = 20;
|
2013-05-01 02:25:33 +02:00
|
|
|
|
|
2013-05-02 07:50:34 +02:00
|
|
|
|
int page;
|
|
|
|
|
Int32.TryParse(PrimitiveExtensions.ToNullSafeString(Request.Query.Page), out page);
|
|
|
|
|
if (page == 0) page = 1;
|
|
|
|
|
|
|
|
|
|
var sortKey = PrimitiveExtensions.ToNullSafeString(Request.Query.SortKey)
|
|
|
|
|
.Equals("SeriesTitle", StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
? "SeriesTitle"
|
|
|
|
|
: "AirDate";
|
|
|
|
|
|
|
|
|
|
var sortDirection = PrimitiveExtensions.ToNullSafeString(Request.Query.SortDir)
|
|
|
|
|
.Equals("Asc", StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
? ListSortDirection.Ascending
|
|
|
|
|
: ListSortDirection.Descending;
|
|
|
|
|
|
|
|
|
|
var pagingSpec = new PagingSpec<Episode>
|
|
|
|
|
{
|
|
|
|
|
Page = page,
|
|
|
|
|
PageSize = pageSize,
|
|
|
|
|
SortKey = sortKey,
|
|
|
|
|
SortDirection = sortDirection
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = _episodeService.EpisodesWithoutFiles(pagingSpec, includeSpecials);
|
|
|
|
|
|
|
|
|
|
return Mapper.Map<PagingSpec<Episode>, PagingResource<EpisodeResource>>(result).AsResponse();
|
2013-03-21 04:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|