diff --git a/src/NzbDrone.Api/Movies/MovieModuleWithSignalR.cs b/src/NzbDrone.Api/Movies/MovieModuleWithSignalR.cs new file mode 100644 index 000000000..84e5a4b61 --- /dev/null +++ b/src/NzbDrone.Api/Movies/MovieModuleWithSignalR.cs @@ -0,0 +1,78 @@ +using NzbDrone.Api.Movie; +using NzbDrone.Core.Datastore.Events; +using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.Download; +using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.Tv; +using NzbDrone.SignalR; + +namespace NzbDrone.Api.Movies +{ + public abstract class MovieModuleWithSignalR : NzbDroneRestModuleWithSignalR, + IHandle, + IHandle + { + protected readonly IMovieService _episodeService; + protected readonly IQualityUpgradableSpecification _qualityUpgradableSpecification; + + protected MovieModuleWithSignalR(IMovieService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster) + : base(signalRBroadcaster) + { + _episodeService = episodeService; + _qualityUpgradableSpecification = qualityUpgradableSpecification; + + GetResourceById = GetMovie; + } + + protected MovieModuleWithSignalR(IMovieService episodeService, + IQualityUpgradableSpecification qualityUpgradableSpecification, + IBroadcastSignalRMessage signalRBroadcaster, + string resource) + : base(signalRBroadcaster, resource) + { + _episodeService = episodeService; + _qualityUpgradableSpecification = qualityUpgradableSpecification; + + GetResourceById = GetMovie; + } + + protected MovieResource GetMovie(int id) + { + var episode = _episodeService.GetMovie(id); + var resource = MapToResource(episode, true); + return resource; + } + + protected MovieResource MapToResource(Core.Tv.Movie episode, bool includeSeries) + { + var resource = episode.ToResource(); + + if (includeSeries) + { + var series = episode ?? _episodeService.GetMovie(episode.Id); + resource = series.ToResource(); + } + + return resource; + } + + public void Handle(MovieGrabbedEvent message) + { + var resource = message.Movie.Movie.ToResource(); + + //add a grabbed field in MovieResource? + //resource.Grabbed = true; + + BroadcastResourceChange(ModelAction.Updated, resource); + } + + public void Handle(MovieDownloadedEvent message) + { + var resource = message.Movie.Movie.ToResource(); + BroadcastResourceChange(ModelAction.Updated, resource); + } + } +} diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index ec5e30df4..9347015db 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -118,6 +118,7 @@ + diff --git a/src/NzbDrone.Api/Wanted/MovieCutoffModule.cs b/src/NzbDrone.Api/Wanted/MovieCutoffModule.cs index b454d5d78..cf490f529 100644 --- a/src/NzbDrone.Api/Wanted/MovieCutoffModule.cs +++ b/src/NzbDrone.Api/Wanted/MovieCutoffModule.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Api.Wanted { - public class MovieCutoffModule : NzbDroneRestModuleWithSignalR + public class MovieCutoffModule : MovieModuleWithSignalR { private readonly IMovieCutoffService _movieCutoffService; @@ -15,7 +15,7 @@ public MovieCutoffModule(IMovieCutoffService movieCutoffService, IMovieService movieService, IQualityUpgradableSpecification qualityUpgradableSpecification, IBroadcastSignalRMessage signalRBroadcaster) - : base(signalRBroadcaster, "wanted/cutoff") + : base(movieService, qualityUpgradableSpecification, signalRBroadcaster, "wanted/cutoff") { _movieCutoffService = movieCutoffService; GetResourcePaged = GetCutoffUnmetMovies; @@ -34,15 +34,9 @@ private PagingResource GetCutoffUnmetMovies(PagingResource v.Monitored == true; } - var resource = ApplyToPage(_movieCutoffService.MoviesWhereCutoffUnmet, pagingSpec, v => MapToResource(v)); + var resource = ApplyToPage(_movieCutoffService.MoviesWhereCutoffUnmet, pagingSpec, v => MapToResource(v, true)); return resource; } - - private MovieResource MapToResource(Core.Tv.Movie movie) - { - var resource = movie.ToResource(); - return resource; - } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/Wanted/MovieMissingModule.cs b/src/NzbDrone.Api/Wanted/MovieMissingModule.cs index 4b1b89503..319e70a08 100644 --- a/src/NzbDrone.Api/Wanted/MovieMissingModule.cs +++ b/src/NzbDrone.Api/Wanted/MovieMissingModule.cs @@ -12,16 +12,14 @@ namespace NzbDrone.Api.Wanted { - class MovieMissingModule : NzbDroneRestModuleWithSignalR, - IHandle, - IHandle + class MovieMissingModule : MovieModuleWithSignalR { protected readonly IMovieService _movieService; public MovieMissingModule(IMovieService movieService, IQualityUpgradableSpecification qualityUpgradableSpecification, IBroadcastSignalRMessage signalRBroadcaster) - : base(signalRBroadcaster, "wanted/missing") + : base(movieService, qualityUpgradableSpecification, signalRBroadcaster, "wanted/missing") { _movieService = movieService; @@ -41,31 +39,9 @@ private PagingResource GetMissingMovies(PagingResource v.Monitored == true; } - var resource = ApplyToPage(_movieService.MoviesWithoutFiles, pagingSpec, v => MapToResource(v, false)); + var resource = ApplyToPage(_movieService.MoviesWithoutFiles, pagingSpec, v => MapToResource(v, true)); return resource; } - - private MovieResource MapToResource(Core.Tv.Movie movie, bool includeMovieFile) - { - var resource = movie.ToResource(); - return resource; - } - - public void Handle(MovieGrabbedEvent message) - { - var resource = message.Movie.Movie.ToResource(); - - //add a grabbed field in MovieResource? - //resource.Grabbed = true; - - BroadcastResourceChange(ModelAction.Updated, resource); - } - - public void Handle(MovieDownloadedEvent message) - { - var resource = message.Movie.Movie.ToResource(); - BroadcastResourceChange(ModelAction.Updated, resource); - } } }