2013-05-03 06:53:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using NzbDrone.Api.Episodes;
|
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.History
|
|
|
|
|
{
|
|
|
|
|
public class HistoryModule : NzbDroneApiModule
|
|
|
|
|
{
|
|
|
|
|
private readonly IHistoryService _historyService;
|
|
|
|
|
|
|
|
|
|
public HistoryModule(IHistoryService historyService)
|
|
|
|
|
: base("/history")
|
|
|
|
|
{
|
|
|
|
|
_historyService = historyService;
|
|
|
|
|
Get["/"] = x => GetHistory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetHistory()
|
|
|
|
|
{
|
|
|
|
|
//TODO: common page parsing logic should be done somewhere else
|
|
|
|
|
|
|
|
|
|
int pageSize;
|
|
|
|
|
Int32.TryParse(PrimitiveExtensions.ToNullSafeString(Request.Query.PageSize), out pageSize);
|
|
|
|
|
if (pageSize == 0) pageSize = 20;
|
|
|
|
|
|
|
|
|
|
int page;
|
|
|
|
|
Int32.TryParse(PrimitiveExtensions.ToNullSafeString(Request.Query.Page), out page);
|
|
|
|
|
if (page == 0) page = 1;
|
|
|
|
|
|
2013-05-07 07:22:19 +00:00
|
|
|
|
var sortKey = PrimitiveExtensions.ToNullSafeString(Request.Query.SortKey);
|
|
|
|
|
if (String.IsNullOrEmpty(sortKey)) sortKey = "AirDate";
|
2013-05-03 06:53:32 +00:00
|
|
|
|
|
|
|
|
|
var sortDirection = PrimitiveExtensions.ToNullSafeString(Request.Query.SortDir)
|
|
|
|
|
.Equals("Asc", StringComparison.InvariantCultureIgnoreCase)
|
2013-05-07 07:22:19 +00:00
|
|
|
|
? SortDirection.Ascending
|
|
|
|
|
: SortDirection.Descending;
|
2013-05-03 06:53:32 +00:00
|
|
|
|
|
2013-05-10 22:33:04 +00:00
|
|
|
|
var pagingSpec = new PagingSpec<Core.History.History>
|
2013-05-03 06:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
Page = page,
|
|
|
|
|
PageSize = pageSize,
|
|
|
|
|
SortKey = sortKey,
|
|
|
|
|
SortDirection = sortDirection
|
|
|
|
|
};
|
|
|
|
|
|
2013-05-10 22:33:04 +00:00
|
|
|
|
var result = _historyService.Paged(pagingSpec);
|
2013-05-03 06:53:32 +00:00
|
|
|
|
|
|
|
|
|
return Mapper.Map<PagingSpec<Core.History.History>, PagingResource<HistoryResource>>(result).AsResponse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|