mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-25 22:37:27 -04:00
1a4fb6e7bb
* Update BlacklistService * Update HistoryService, HistoryRepo and History * Update UI in Blacklists to movies * set the movie model so the movie title prints in blacklist * Would be working if I implemented the Event Handler for MovieFileDeleted
72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
using System;
|
|
using Nancy;
|
|
using NzbDrone.Api.Extensions;
|
|
using NzbDrone.Api.Movie;
|
|
using NzbDrone.Core.Datastore;
|
|
using NzbDrone.Core.DecisionEngine;
|
|
using NzbDrone.Core.Download;
|
|
using NzbDrone.Core.History;
|
|
|
|
namespace NzbDrone.Api.History
|
|
{
|
|
public class HistoryModule : NzbDroneRestModule<HistoryResource>
|
|
{
|
|
private readonly IHistoryService _historyService;
|
|
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
|
|
private readonly IFailedDownloadService _failedDownloadService;
|
|
|
|
public HistoryModule(IHistoryService historyService,
|
|
IQualityUpgradableSpecification qualityUpgradableSpecification,
|
|
IFailedDownloadService failedDownloadService)
|
|
{
|
|
_historyService = historyService;
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
|
_failedDownloadService = failedDownloadService;
|
|
GetResourcePaged = GetHistory;
|
|
|
|
Post["/failed"] = x => MarkAsFailed();
|
|
}
|
|
|
|
protected HistoryResource MapToResource(Core.History.History model)
|
|
{
|
|
var resource = model.ToResource();
|
|
resource.Movie = model.Movie.ToResource();
|
|
|
|
if (model.Movie != null)
|
|
{
|
|
resource.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(model.Movie.Profile.Value, model.Quality);
|
|
}
|
|
|
|
return resource;
|
|
}
|
|
|
|
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
|
|
{
|
|
var movieId = Request.Query.MovieId;
|
|
|
|
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, Core.History.History>("date", SortDirection.Descending);
|
|
|
|
if (pagingResource.FilterKey == "eventType")
|
|
{
|
|
var filterValue = (HistoryEventType)Convert.ToInt32(pagingResource.FilterValue);
|
|
pagingSpec.FilterExpression = v => v.EventType == filterValue;
|
|
}
|
|
|
|
if (movieId.HasValue)
|
|
{
|
|
int i = (int)movieId;
|
|
pagingSpec.FilterExpression = h => h.MovieId == i;
|
|
}
|
|
|
|
return ApplyToPage(_historyService.Paged, pagingSpec, MapToResource);
|
|
}
|
|
|
|
private Response MarkAsFailed()
|
|
{
|
|
var id = (int)Request.Form.Id;
|
|
_failedDownloadService.MarkAsFailed(id);
|
|
return new object().AsResponse();
|
|
}
|
|
}
|
|
}
|