Fixed: Old API use with Ombi causing NREs

pull/2/head
Qstick 5 years ago
parent 8f72bd5e69
commit cb158028df

@ -3,28 +3,27 @@ using System.Collections.Generic;
using System.Linq;
using Nancy;
using NzbDrone.Api.Movies;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.Validation;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.SignalR;
using Radarr.Http;
namespace NzbDrone.Api.Calendar
{
public class CalendarModule : MovieModule
public class CalendarModule : RadarrRestModuleWithSignalR<MovieResource, Movie>
{
protected readonly IMovieService _moviesService;
private readonly IMapCoversToLocal _coverMapper;
public CalendarModule(IBroadcastSignalRMessage signalR,
IMovieService moviesService,
IMapCoversToLocal coverMapper)
: base(signalR, moviesService, coverMapper, "calendar")
: base(signalR, "calendar")
{
_moviesService = moviesService;
_coverMapper = coverMapper;
GetResourceAll = GetCalendar;
}
@ -46,5 +45,14 @@ namespace NzbDrone.Api.Calendar
return resources.OrderBy(e => e.InCinemas).ToList();
}
protected MovieResource MapToResource(Movie movie)
{
if (movie == null) return null;
var resource = movie.ToResource();
return resource;
}
}
}

@ -21,11 +21,11 @@ using Radarr.Http;
namespace NzbDrone.Api.Movies
{
public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Core.Movies.Movie>,
public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Movie>,
IHandle<MovieImportedEvent>,
IHandle<MovieFileDeletedEvent>,
IHandle<MovieUpdatedEvent>,
IHandle<MovieEditedEvent>,
IHandle<MovieUpdatedEvent>,
IHandle<MovieEditedEvent>,
IHandle<MovieDeletedEvent>,
IHandle<MovieRenamedEvent>,
IHandle<MediaCoversUpdatedEvent>
@ -34,7 +34,7 @@ namespace NzbDrone.Api.Movies
protected readonly IMovieService _moviesService;
private readonly IMapCoversToLocal _coverMapper;
private const string TITLE_SLUG_ROUTE = "/titleslug/(?<slug>[^/]+)";
private const string TITLE_SLUG_ROUTE = "/titleslug/(?<slug>[^/]+)";
public MovieModule(IBroadcastSignalRMessage signalRBroadcaster,
IMovieService moviesService,
@ -53,14 +53,8 @@ namespace NzbDrone.Api.Movies
_coverMapper = coverMapper;
GetResourceAll = AllMovie;
GetResourcePaged = GetMoviePaged;
GetResourceById = GetMovie;
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug; /*(options) => {
return ReqResExtensions.AsResponse(GetByTitleSlug(options.slug), Nancy.HttpStatusCode.OK);
};*/
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug;
CreateResource = AddMovie;
UpdateResource = UpdateMovie;
DeleteResource = DeleteMovie;
@ -86,65 +80,34 @@ namespace NzbDrone.Api.Movies
PutValidator.RuleFor(s => s.Path).IsValidPath();
}
public MovieModule(IBroadcastSignalRMessage signalRBroadcaster,
IMovieService moviesService,
IMapCoversToLocal coverMapper,
string resource)
: base(signalRBroadcaster, resource)
{
_moviesService = moviesService;
_coverMapper = coverMapper;
GetResourceAll = AllMovie;
GetResourceById = GetMovie;
CreateResource = AddMovie;
UpdateResource = UpdateMovie;
DeleteResource = DeleteMovie;
}
private MovieResource GetMovie(int id)
{
var movies = _moviesService.GetMovie(id);
return MapToResource(movies);
}
private PagingResource<MovieResource> GetMoviePaged(PagingResource<MovieResource> pagingResource)
{
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Movie>();
pagingSpec.FilterExpressions.Add(_moviesService.ConstructFilterExpression(pagingResource.Filters.FirstOrDefault().Key, pagingResource.Filters.FirstOrDefault().Value));
return ApplyToPage(_moviesService.Paged, pagingSpec, MapToResource);
}
protected MovieResource MapToResource(Movie movies)
{
if (movies == null) return null;
var resource = movies.ToResource();
MapCoversToLocal(resource);
//FetchAndLinkMovieStatistics(resource);
//PopulateAlternateTitles(resource);
return resource;
}
private List<MovieResource> AllMovie()
{
//var moviesStats = _moviesStatisticsService.MovieStatistics();
var moviesResources = _moviesService.GetAllMovies().ToResource();
MapCoversToLocal(moviesResources.ToArray());
//LinkMovieStatistics(moviesResources, moviesStats);
PopulateAlternateTitles(moviesResources);
return moviesResources;
}
private Response GetByTitleSlug(dynamic options)
{
var slug = "";
private Response GetByTitleSlug(dynamic options)
{
string slug;
try
{
slug = options.slug;
@ -157,13 +120,13 @@ namespace NzbDrone.Api.Movies
try
{
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(Nancy.HttpStatusCode.OK);
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(HttpStatusCode.OK);
}
catch (ModelNotFoundException)
{
return new NotFoundResponse();
}
}
}
private int AddMovie(MovieResource moviesResource)
{
@ -208,48 +171,6 @@ namespace NzbDrone.Api.Movies
}
}
//private void FetchAndLinkMovieStatistics(MovieResource resource)
//{
// LinkMovieStatistics(resource, _moviesStatisticsService.MovieStatistics(resource.Id));
//}
//private void LinkMovieStatistics(List<MovieResource> resources, List<MovieStatistics> moviesStatistics)
//{
// var dictMovieStats = moviesStatistics.ToDictionary(v => v.MovieId);
// foreach (var movies in resources)
// {
// var stats = dictMovieStats.GetValueOrDefault(movies.Id);
// if (stats == null) continue;
// LinkMovieStatistics(movies, stats);
// }
//}
//private void LinkMovieStatistics(MovieResource resource, MovieStatistics moviesStatistics)
//{
// //resource.SizeOnDisk = 0;//TODO: incorporate movie statistics moviesStatistics.SizeOnDisk;
//}
private void PopulateAlternateTitles(List<MovieResource> resources)
{
foreach (var resource in resources)
{
PopulateAlternateTitles(resource);
}
}
private void PopulateAlternateTitles(MovieResource resource)
{
//var mappings = null;//_sceneMappingService.FindByTvdbId(resource.TvdbId);
//if (mappings == null) return;
//Not necessary anymore
//resource.AlternateTitles = mappings.Select(v => new AlternateTitleResource { Title = v.Title, SeasonNumber = v.SeasonNumber, SceneSeasonNumber = v.SceneSeasonNumber }).ToList();
}
public void Handle(MovieImportedEvent message)
{
BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.MovieId);

Loading…
Cancel
Save