Fixed: Old API use with Ombi causing NREs

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

@ -3,28 +3,27 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Nancy; using Nancy;
using NzbDrone.Api.Movies; using NzbDrone.Api.Movies;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaCover; 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;
using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.Validation;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.SignalR; using NzbDrone.SignalR;
using Radarr.Http;
namespace NzbDrone.Api.Calendar 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, public CalendarModule(IBroadcastSignalRMessage signalR,
IMovieService moviesService, IMovieService moviesService,
IMapCoversToLocal coverMapper) IMapCoversToLocal coverMapper)
: base(signalR, moviesService, coverMapper, "calendar") : base(signalR, "calendar")
{ {
_moviesService = moviesService;
_coverMapper = coverMapper;
GetResourceAll = GetCalendar; GetResourceAll = GetCalendar;
} }
@ -46,5 +45,14 @@ namespace NzbDrone.Api.Calendar
return resources.OrderBy(e => e.InCinemas).ToList(); 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 namespace NzbDrone.Api.Movies
{ {
public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Core.Movies.Movie>, public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Movie>,
IHandle<MovieImportedEvent>, IHandle<MovieImportedEvent>,
IHandle<MovieFileDeletedEvent>, IHandle<MovieFileDeletedEvent>,
IHandle<MovieUpdatedEvent>, IHandle<MovieUpdatedEvent>,
IHandle<MovieEditedEvent>, IHandle<MovieEditedEvent>,
IHandle<MovieDeletedEvent>, IHandle<MovieDeletedEvent>,
IHandle<MovieRenamedEvent>, IHandle<MovieRenamedEvent>,
IHandle<MediaCoversUpdatedEvent> IHandle<MediaCoversUpdatedEvent>
@ -34,7 +34,7 @@ namespace NzbDrone.Api.Movies
protected readonly IMovieService _moviesService; protected readonly IMovieService _moviesService;
private readonly IMapCoversToLocal _coverMapper; private readonly IMapCoversToLocal _coverMapper;
private const string TITLE_SLUG_ROUTE = "/titleslug/(?<slug>[^/]+)"; private const string TITLE_SLUG_ROUTE = "/titleslug/(?<slug>[^/]+)";
public MovieModule(IBroadcastSignalRMessage signalRBroadcaster, public MovieModule(IBroadcastSignalRMessage signalRBroadcaster,
IMovieService moviesService, IMovieService moviesService,
@ -53,14 +53,8 @@ namespace NzbDrone.Api.Movies
_coverMapper = coverMapper; _coverMapper = coverMapper;
GetResourceAll = AllMovie; GetResourceAll = AllMovie;
GetResourcePaged = GetMoviePaged;
GetResourceById = GetMovie; GetResourceById = GetMovie;
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug; /*(options) => { Get[TITLE_SLUG_ROUTE] = GetByTitleSlug;
return ReqResExtensions.AsResponse(GetByTitleSlug(options.slug), Nancy.HttpStatusCode.OK);
};*/
CreateResource = AddMovie; CreateResource = AddMovie;
UpdateResource = UpdateMovie; UpdateResource = UpdateMovie;
DeleteResource = DeleteMovie; DeleteResource = DeleteMovie;
@ -86,65 +80,34 @@ namespace NzbDrone.Api.Movies
PutValidator.RuleFor(s => s.Path).IsValidPath(); 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) private MovieResource GetMovie(int id)
{ {
var movies = _moviesService.GetMovie(id); var movies = _moviesService.GetMovie(id);
return MapToResource(movies); 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) protected MovieResource MapToResource(Movie movies)
{ {
if (movies == null) return null; if (movies == null) return null;
var resource = movies.ToResource(); var resource = movies.ToResource();
MapCoversToLocal(resource); MapCoversToLocal(resource);
//FetchAndLinkMovieStatistics(resource);
//PopulateAlternateTitles(resource);
return resource; return resource;
} }
private List<MovieResource> AllMovie() private List<MovieResource> AllMovie()
{ {
//var moviesStats = _moviesStatisticsService.MovieStatistics();
var moviesResources = _moviesService.GetAllMovies().ToResource(); var moviesResources = _moviesService.GetAllMovies().ToResource();
MapCoversToLocal(moviesResources.ToArray()); MapCoversToLocal(moviesResources.ToArray());
//LinkMovieStatistics(moviesResources, moviesStats);
PopulateAlternateTitles(moviesResources);
return moviesResources; return moviesResources;
} }
private Response GetByTitleSlug(dynamic options) private Response GetByTitleSlug(dynamic options)
{ {
var slug = ""; string slug;
try try
{ {
slug = options.slug; slug = options.slug;
@ -157,13 +120,13 @@ namespace NzbDrone.Api.Movies
try try
{ {
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(Nancy.HttpStatusCode.OK); return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(HttpStatusCode.OK);
} }
catch (ModelNotFoundException) catch (ModelNotFoundException)
{ {
return new NotFoundResponse(); return new NotFoundResponse();
} }
} }
private int AddMovie(MovieResource moviesResource) 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) public void Handle(MovieImportedEvent message)
{ {
BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.MovieId); BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.MovieId);

Loading…
Cancel
Save