You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/src/NzbDrone.Api/History/HistoryModule.cs

58 lines
2.0 KiB

using System;
using Nancy;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download;
12 years ago
using NzbDrone.Core.History;
namespace NzbDrone.Api.History
{
public class HistoryModule : NzbDroneRestModule<HistoryResource>
12 years ago
{
private readonly IHistoryService _historyService;
private readonly IFailedDownloadService _failedDownloadService;
12 years ago
public HistoryModule(IHistoryService historyService, IFailedDownloadService failedDownloadService)
12 years ago
{
_historyService = historyService;
_failedDownloadService = failedDownloadService;
GetResourcePaged = GetHistory;
Post["/failed"] = x => MarkAsFailed();
12 years ago
}
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
12 years ago
{
var episodeId = Request.Query.EpisodeId;
12 years ago
var pagingSpec = new PagingSpec<Core.History.History>
12 years ago
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
12 years ago
};
if (pagingResource.FilterKey == "eventType")
{
var filterValue = (HistoryEventType)Convert.ToInt32(pagingResource.FilterValue);
pagingSpec.FilterExpression = v => v.EventType == filterValue;
}
if (episodeId.HasValue)
{
int i = (int)episodeId;
pagingSpec.FilterExpression = h => h.EpisodeId == i;
}
return ApplyToPage(_historyService.Paged, pagingSpec);
12 years ago
}
private Response MarkAsFailed()
{
var id = (int)Request.Form.Id;
_failedDownloadService.MarkAsFailed(id);
return new Object().AsResponse();
}
12 years ago
}
}