From 41f03b46f1ac2caefe14162ac2faf35a4019fd2f Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 20 Apr 2017 16:31:59 +0100 Subject: [PATCH] Mapping mainly --- Ombi/Ombi.Core/Engine/MovieEngine.cs | 83 ++++++------------- Ombi/Ombi.Core/Engine/RequestEngine.cs | 17 ++-- .../Ombi.DependencyInjection/IocExtensions.cs | 12 ++- .../Ombi.DependencyInjection.csproj | 1 + Ombi/Ombi.Mapping/MappingConverters.cs | 26 ++++++ Ombi/Ombi.Mapping/Ombi.Mapping.csproj | 1 + Ombi/Ombi.Mapping/OmbiProfile.cs | 46 ++++++++++ Ombi/Ombi.Schedule/Class1.cs | 8 -- Ombi/Ombi.Schedule/ITestJob.cs | 11 +++ Ombi/Ombi.Schedule/IoCJobActivator.cs | 20 +++++ Ombi/Ombi.Schedule/Ombi.Schedule.csproj | 1 + Ombi/Ombi.Schedule/TestJob.cs | 17 ++++ Ombi/Ombi.TheMovieDbApi/IMovieDbApi.cs | 21 ++--- Ombi/Ombi.TheMovieDbApi/Models/GenreDto.cs | 8 ++ .../Models/MovieResponseDTO.cs | 27 ++++++ .../Models/MovieSearchResult.cs | 20 +++++ .../Ombi.Api.TheMovieDb.csproj | 6 ++ Ombi/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 55 +++++++----- Ombi/Ombi/Ombi.csproj | 2 + Ombi/Ombi/Startup.cs | 18 +++- 20 files changed, 291 insertions(+), 109 deletions(-) create mode 100644 Ombi/Ombi.Mapping/MappingConverters.cs delete mode 100644 Ombi/Ombi.Schedule/Class1.cs create mode 100644 Ombi/Ombi.Schedule/ITestJob.cs create mode 100644 Ombi/Ombi.Schedule/IoCJobActivator.cs create mode 100644 Ombi/Ombi.Schedule/TestJob.cs create mode 100644 Ombi/Ombi.TheMovieDbApi/Models/GenreDto.cs create mode 100644 Ombi/Ombi.TheMovieDbApi/Models/MovieResponseDTO.cs create mode 100644 Ombi/Ombi.TheMovieDbApi/Models/MovieSearchResult.cs diff --git a/Ombi/Ombi.Core/Engine/MovieEngine.cs b/Ombi/Ombi.Core/Engine/MovieEngine.cs index d9b3c9c31..474f53986 100644 --- a/Ombi/Ombi.Core/Engine/MovieEngine.cs +++ b/Ombi/Ombi.Core/Engine/MovieEngine.cs @@ -2,6 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AutoMapper; +using Ombi.Api.TheMovieDb; +using Ombi.Api.TheMovieDb.Models; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; using Ombi.Core.Requests.Models; @@ -15,13 +18,15 @@ namespace Ombi.Core.Engine public class MovieEngine : IMovieEngine { - public MovieEngine(IRequestService service, IMovieDbApi movApi) + public MovieEngine(IRequestService service, IMovieDbApi movApi, IMapper mapper) { RequestService = service; MovieApi = movApi; + Mapper = mapper; } private IRequestService RequestService { get; } private IMovieDbApi MovieApi { get; } + private IMapper Mapper { get; } public async Task> LookupImdbInformation(IEnumerable movies) { @@ -31,27 +36,8 @@ namespace Ombi.Core.Engine { var movieInfo = await MovieApi.GetMovieInformationWithVideo(m.Id); - var viewMovie = new SearchMovieViewModel - { - Adult = movieInfo.adult, - BackdropPath = movieInfo.backdrop_path, - Id = movieInfo.id, - OriginalLanguage = movieInfo.original_language, - OriginalTitle = movieInfo.original_title, - Overview = movieInfo.overview, - Popularity = movieInfo.popularity, - PosterPath = movieInfo.poster_path, - ReleaseDate = - string.IsNullOrEmpty(movieInfo.release_date) - ? DateTime.MinValue - : DateTime.Parse(movieInfo.release_date), - Title = movieInfo.title, - Video = movieInfo.video, - VoteAverage = movieInfo.vote_average, - VoteCount = movieInfo.vote_count, - ImdbId = movieInfo?.imdb_id, - Homepage = movieInfo?.homepage - }; + var viewMovie = Mapper.Map(movieInfo); + retVal.Add(viewMovie); // TODO needs to be careful about this, it's adding extra time to search... // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 @@ -62,9 +48,9 @@ namespace Ombi.Core.Engine //viewMovie.Trailer = string.IsNullOrEmpty(videoId) // ? string.Empty // : $"https://www.youtube.com/watch?v={videoId}"; - if (dbMovies.ContainsKey(movieInfo.id) /*&& canSee*/) // compare to the requests db + if (dbMovies.ContainsKey(movieInfo.Id) /*&& canSee*/) // compare to the requests db { - var dbm = dbMovies[movieInfo.id]; + var dbm = dbMovies[movieInfo.Id]; viewMovie.Requested = true; viewMovie.Approved = dbm.Approved; @@ -76,59 +62,54 @@ namespace Ombi.Core.Engine public async Task> ProcessMovieSearch(string search) { - var api = new TheMovieDbApi.TheMovieDbApi(); - var result = await api.SearchMovie(search); + var result = await MovieApi.SearchMovie(search); if (result != null) { - return await TransformMovieResultsToResponse(result.results); + return await TransformMovieResultsToResponse(result); } return null; } public async Task> PopularMovies() { - var api = new TheMovieDbApi.TheMovieDbApi(); - var result = await api.PopularMovies(); + var result = await MovieApi.PopularMovies(); if (result != null) { - return await TransformMovieResultsToResponse(result.results); + return await TransformMovieResultsToResponse(result); } return null; } public async Task> TopRatedMovies() { - var api = new TheMovieDbApi.TheMovieDbApi(); - var result = await api.TopRated(); + var result = await MovieApi.TopRated(); if (result != null) { - return await TransformMovieResultsToResponse(result.results); + return await TransformMovieResultsToResponse(result); } return null; } public async Task> UpcomingMovies() { - var api = new TheMovieDbApi.TheMovieDbApi(); - var result = await api.Upcoming(); + var result = await MovieApi.Upcoming(); if (result != null) { - return await TransformMovieResultsToResponse(result.results); + return await TransformMovieResultsToResponse(result); } return null; } public async Task> NowPlayingMovies() { - var api = new TheMovieDbApi.TheMovieDbApi(); - var result = await api.NowPlaying(); + var result = await MovieApi.NowPlaying(); if (result != null) { - return await TransformMovieResultsToResponse(result.results); + return await TransformMovieResultsToResponse(result); } return null; } - private async Task> TransformMovieResultsToResponse(IEnumerable movies) + private async Task> TransformMovieResultsToResponse(IEnumerable movies) { await Task.Yield(); var viewMovies = new List(); @@ -136,22 +117,8 @@ namespace Ombi.Core.Engine Dictionary dbMovies = await RequestedMovies(); foreach (var movie in movies) { - var viewMovie = new SearchMovieViewModel - { - Adult = movie.adult, - BackdropPath = movie.backdrop_path, - Id = movie.id, - OriginalLanguage = movie.original_language, - OriginalTitle = movie.original_title, - Overview = movie.overview, - Popularity = movie.popularity, - PosterPath = movie.poster_path, - ReleaseDate = string.IsNullOrEmpty(movie.release_date) ? DateTime.MinValue : DateTime.Parse(movie.release_date), - Title = movie.title, - Video = movie.video, - VoteAverage = movie.vote_average, - VoteCount = movie.vote_count - }; + var viewMovie = Mapper.Map(movie); + viewMovies.Add(viewMovie); @@ -186,9 +153,9 @@ namespace Ombi.Core.Engine // viewMovie.Available = true; // } // } - if (dbMovies.ContainsKey(movie.id) /*&& canSee*/) // compare to the requests db + if (dbMovies.ContainsKey(movie.Id) /*&& canSee*/) // compare to the requests db { - var dbm = dbMovies[movie.id]; + var dbm = dbMovies[movie.Id]; viewMovie.Requested = true; viewMovie.Approved = dbm.Approved; diff --git a/Ombi/Ombi.Core/Engine/RequestEngine.cs b/Ombi/Ombi.Core/Engine/RequestEngine.cs index 2bb21d183..4275d55a5 100644 --- a/Ombi/Ombi.Core/Engine/RequestEngine.cs +++ b/Ombi/Ombi.Core/Engine/RequestEngine.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; +using Ombi.Api.TheMovieDb; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; using Ombi.Core.Requests.Models; @@ -38,7 +39,7 @@ namespace Ombi.Core.Engine //}); } var fullMovieName = - $"{movieInfo.title}{(!string.IsNullOrEmpty(movieInfo.release_date) ? $" ({DateTime.Parse(movieInfo.release_date).Year})" : string.Empty)}"; + $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}"; var existingRequest = await RequestService.CheckRequestAsync(model.Id); if (existingRequest != null) @@ -95,14 +96,14 @@ namespace Ombi.Core.Engine var requestModel = new RequestModel { - ProviderId = movieInfo.id, + ProviderId = movieInfo.Id, Type = RequestType.Movie, - Overview = movieInfo.overview, - ImdbId = movieInfo.imdb_id, - PosterPath = movieInfo.poster_path, - Title = movieInfo.title, - ReleaseDate = !string.IsNullOrEmpty(movieInfo.release_date) ? DateTime.Parse(movieInfo.release_date) : DateTime.MinValue, - Status = movieInfo.status, + Overview = movieInfo.Overview, + ImdbId = movieInfo.ImdbId, + PosterPath = movieInfo.PosterPath, + Title = movieInfo.Title, + ReleaseDate = !string.IsNullOrEmpty(movieInfo.ReleaseDate) ? DateTime.Parse(movieInfo.ReleaseDate) : DateTime.MinValue, + Status = movieInfo.Status, RequestedDate = DateTime.UtcNow, Approved = false, //RequestedUsers = new List { Username }, diff --git a/Ombi/Ombi.DependencyInjection/IocExtensions.cs b/Ombi/Ombi.DependencyInjection/IocExtensions.cs index ed11ce162..f03f1ddec 100644 --- a/Ombi/Ombi.DependencyInjection/IocExtensions.cs +++ b/Ombi/Ombi.DependencyInjection/IocExtensions.cs @@ -7,12 +7,14 @@ using Microsoft.Extensions.DependencyInjection; using Ombi.Api.Emby; using Ombi.Api.Plex; using Ombi.Api.Sonarr; +using Ombi.Api.TheMovieDb; using Ombi.Core; using Ombi.Core.Engine; using Ombi.Core.IdentityResolver; using Ombi.Core.Models.Requests; using Ombi.Core.Requests.Models; using Ombi.Core.Settings; +using Ombi.Schedule; using Ombi.Store.Context; using Ombi.Store.Repository; using Ombi.TheMovieDbApi; @@ -29,6 +31,7 @@ namespace Ombi.DependencyInjection services.RegisterServices(); services.RegisterStore(); services.RegisterIdentity(); + services.RegisterJobs(); return services; } @@ -42,7 +45,7 @@ namespace Ombi.DependencyInjection public static IServiceCollection RegisterApi(this IServiceCollection services) { - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -68,6 +71,13 @@ namespace Ombi.DependencyInjection return services; } + public static IServiceCollection RegisterJobs(this IServiceCollection services) + { + services.AddTransient(); + + return services; + } + public static IServiceCollection RegisterIdentity(this IServiceCollection services) { services.AddTransient(); diff --git a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index b49771653..48fbec61b 100644 --- a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -15,6 +15,7 @@ + \ No newline at end of file diff --git a/Ombi/Ombi.Mapping/MappingConverters.cs b/Ombi/Ombi.Mapping/MappingConverters.cs new file mode 100644 index 000000000..842e1a95e --- /dev/null +++ b/Ombi/Ombi.Mapping/MappingConverters.cs @@ -0,0 +1,26 @@ +using AutoMapper; +using System; + +namespace Ombi.Mapping +{ + public class StringToDateTimeConverter : ITypeConverter + { + + public DateTime Convert(string source, DateTime destination, ResolutionContext context) + { + DateTime dateTime; + + if (string.IsNullOrEmpty(source)) + { + return default(DateTime); + } + + if (DateTime.TryParse(source.ToString(), out dateTime)) + { + return dateTime; + } + + return default(DateTime); + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Mapping/Ombi.Mapping.csproj b/Ombi/Ombi.Mapping/Ombi.Mapping.csproj index ce044ce17..8210ca118 100644 --- a/Ombi/Ombi.Mapping/Ombi.Mapping.csproj +++ b/Ombi/Ombi.Mapping/Ombi.Mapping.csproj @@ -6,6 +6,7 @@ + diff --git a/Ombi/Ombi.Mapping/OmbiProfile.cs b/Ombi/Ombi.Mapping/OmbiProfile.cs index 6a2121106..0b493dc03 100644 --- a/Ombi/Ombi.Mapping/OmbiProfile.cs +++ b/Ombi/Ombi.Mapping/OmbiProfile.cs @@ -1,7 +1,11 @@ using System; +using System.Collections.Generic; using AutoMapper; +using Ombi.Api.TheMovieDb.Models; using Ombi.Core.Models; +using Ombi.Core.Models.Search; using Ombi.Store.Entities; +using Ombi.TheMovieDbApi.Models; namespace Ombi.Mapping { @@ -9,7 +13,49 @@ namespace Ombi.Mapping { public OmbiProfile() { + CreateMap().ReverseMap(); + + CreateMap().ConvertUsing(); + + CreateMap() + .ForMember(dest => dest.Adult, opts => opts.MapFrom(src => src.adult)) + .ForMember(dest => dest.BackdropPath, opts => opts.MapFrom(src => src.backdrop_path)) + .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.id)) + .ForMember(dest => dest.OriginalLanguage, opts => opts.MapFrom(src => src.original_language)) + .ForMember(dest => dest.OriginalTitle, opts => opts.MapFrom(src => src.original_title)) + .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.overview)) + .ForMember(dest => dest.Popularity, opts => opts.MapFrom(src => src.popularity)) + .ForMember(dest => dest.PosterPath, opts => opts.MapFrom(src => src.poster_path)) + .ForMember(dest => dest.ReleaseDate, opts => opts.MapFrom(src => src.release_date)) + .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.title)) + .ForMember(dest => dest.Video, opts => opts.MapFrom(src => src.video)) + .ForMember(dest => dest.VoteAverage, opts => opts.MapFrom(src => src.vote_average)) + .ForMember(dest => dest.VoteCount, opts => opts.MapFrom(src => src.vote_count)); + + CreateMap() + .ForMember(dest => dest.Adult, opts => opts.MapFrom(src => src.adult)) + .ForMember(dest => dest.BackdropPath, opts => opts.MapFrom(src => src.backdrop_path)) + .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.id)) + .ForMember(dest => dest.OriginalLanguage, opts => opts.MapFrom(src => src.original_language)) + .ForMember(dest => dest.OriginalTitle, opts => opts.MapFrom(src => src.original_title)) + .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.overview)) + .ForMember(dest => dest.Popularity, opts => opts.MapFrom(src => src.popularity)) + .ForMember(dest => dest.PosterPath, opts => opts.MapFrom(src => src.poster_path)) + .ForMember(dest => dest.ReleaseDate, opts => opts.MapFrom(src => src.release_date)) + .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.title)) + .ForMember(dest => dest.Video, opts => opts.MapFrom(src => src.video)) + .ForMember(dest => dest.VoteAverage, opts => opts.MapFrom(src => src.vote_average)) + .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.imdb_id)) + .ForMember(dest => dest.Homepage, opts => opts.MapFrom(src => src.homepage)) + .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.runtime)) + .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.status)) + .ForMember(dest => dest.Tagline, opts => opts.MapFrom(src => src.tagline)) + .ForMember(dest => dest.VoteCount, opts => opts.MapFrom(src => src.vote_count)); + CreateMap(); + + CreateMap().ReverseMap(); + } } } diff --git a/Ombi/Ombi.Schedule/Class1.cs b/Ombi/Ombi.Schedule/Class1.cs deleted file mode 100644 index 9f1c9aa3b..000000000 --- a/Ombi/Ombi.Schedule/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace Ombi.Schedule -{ - public class Class1 - { - } -} diff --git a/Ombi/Ombi.Schedule/ITestJob.cs b/Ombi/Ombi.Schedule/ITestJob.cs new file mode 100644 index 000000000..16b18a92c --- /dev/null +++ b/Ombi/Ombi.Schedule/ITestJob.cs @@ -0,0 +1,11 @@ +using Hangfire.RecurringJobExtensions; +using Hangfire.Server; + +namespace Ombi.Schedule +{ + public interface ITestJob + { + [RecurringJob("*/1 * * * *")] + void Test(PerformContext context); + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Schedule/IoCJobActivator.cs b/Ombi/Ombi.Schedule/IoCJobActivator.cs new file mode 100644 index 000000000..aa8565361 --- /dev/null +++ b/Ombi/Ombi.Schedule/IoCJobActivator.cs @@ -0,0 +1,20 @@ +using System; +using Hangfire; +using Microsoft.Extensions.DependencyInjection; + +namespace Ombi.Schedule +{ + public class IoCJobActivator : JobActivator + { + private readonly IServiceProvider _container; + public IoCJobActivator(IServiceProvider container) + { + _container = container; + } + + public override object ActivateJob(Type type) + { + return _container.GetService(type); + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Schedule/Ombi.Schedule.csproj b/Ombi/Ombi.Schedule/Ombi.Schedule.csproj index 5fa73ec90..0fc535a80 100644 --- a/Ombi/Ombi.Schedule/Ombi.Schedule.csproj +++ b/Ombi/Ombi.Schedule/Ombi.Schedule.csproj @@ -8,6 +8,7 @@ + \ No newline at end of file diff --git a/Ombi/Ombi.Schedule/TestJob.cs b/Ombi/Ombi.Schedule/TestJob.cs new file mode 100644 index 000000000..66d9e22f8 --- /dev/null +++ b/Ombi/Ombi.Schedule/TestJob.cs @@ -0,0 +1,17 @@ +using System; +using System.Diagnostics; +using Hangfire; +using Hangfire.RecurringJobExtensions; +using Hangfire.Server; + +namespace Ombi.Schedule +{ + public class TestJob : ITestJob + { + [RecurringJob("*/1 * * * *")] + public void Test(PerformContext context) + { + Debug.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} TestJob1 Running ..."); + } + } +} diff --git a/Ombi/Ombi.TheMovieDbApi/IMovieDbApi.cs b/Ombi/Ombi.TheMovieDbApi/IMovieDbApi.cs index 13f4a65f6..d39e2e6a7 100644 --- a/Ombi/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/Ombi/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -1,17 +1,18 @@ -using System.Threading.Tasks; -using Ombi.Api; +using System.Collections.Generic; +using System.Threading.Tasks; +using Ombi.Api.TheMovieDb.Models; using Ombi.TheMovieDbApi.Models; -namespace Ombi.TheMovieDbApi +namespace Ombi.Api.TheMovieDb { public interface IMovieDbApi { - Task GetMovieInformation(int movieId); - Task GetMovieInformationWithVideo(int movieId); - Task> NowPlaying(); - Task> PopularMovies(); - Task> SearchMovie(string searchTerm); - Task> TopRated(); - Task> Upcoming(); + Task GetMovieInformation(int movieId); + Task GetMovieInformationWithVideo(int movieId); + Task> NowPlaying(); + Task> PopularMovies(); + Task> SearchMovie(string searchTerm); + Task> TopRated(); + Task> Upcoming(); } } \ No newline at end of file diff --git a/Ombi/Ombi.TheMovieDbApi/Models/GenreDto.cs b/Ombi/Ombi.TheMovieDbApi/Models/GenreDto.cs new file mode 100644 index 000000000..9615d2498 --- /dev/null +++ b/Ombi/Ombi.TheMovieDbApi/Models/GenreDto.cs @@ -0,0 +1,8 @@ +namespace Ombi.Api.TheMovieDb.Models +{ + public class GenreDto + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.TheMovieDbApi/Models/MovieResponseDTO.cs b/Ombi/Ombi.TheMovieDbApi/Models/MovieResponseDTO.cs new file mode 100644 index 000000000..b679ba5cf --- /dev/null +++ b/Ombi/Ombi.TheMovieDbApi/Models/MovieResponseDTO.cs @@ -0,0 +1,27 @@ +namespace Ombi.Api.TheMovieDb.Models +{ + public class MovieResponseDto + { + public bool Adult { get; set; } + public string BackdropPath { get; set; } + public int Budget { get; set; } + public GenreDto[] Genres { get; set; } + public string Homepage { get; set; } + public int Id { get; set; } + public string ImdbId { get; set; } + public string OriginalLanguage { get; set; } + public string OriginalTitle { get; set; } + public string Overview { get; set; } + public float Popularity { get; set; } + public string PosterPath { get; set; } + public string ReleaseDate { get; set; } + public int Revenue { get; set; } + public int Runtime { get; set; } + public string Status { get; set; } + public string Tagline { get; set; } + public string Title { get; set; } + public bool Video { get; set; } + public float VoteAverage { get; set; } + public int VoteCount { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.TheMovieDbApi/Models/MovieSearchResult.cs b/Ombi/Ombi.TheMovieDbApi/Models/MovieSearchResult.cs new file mode 100644 index 000000000..8503cd7f7 --- /dev/null +++ b/Ombi/Ombi.TheMovieDbApi/Models/MovieSearchResult.cs @@ -0,0 +1,20 @@ +namespace Ombi.Api.TheMovieDb.Models +{ + public class MovieSearchResult + { + public string PosterPath { get; set; } + public bool Adult { get; set; } + public string Overview { get; set; } + public string ReleaseDate { get; set; } + public int?[] GenreIds { get; set; } + public int Id { get; set; } + public string OriginalTitle { get; set; } + public string OriginalLanguage { get; set; } + public string Title { get; set; } + public string BackdropPath { get; set; } + public float Popularity { get; set; } + public int VoteCount { get; set; } + public bool Video { get; set; } + public float VoteAverage { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj b/Ombi/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj index e2e0a5381..7b9c6df53 100644 --- a/Ombi/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj +++ b/Ombi/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj @@ -10,4 +10,10 @@ + + + ..\..\..\..\..\.nuget\packages\automapper\6.0.2\lib\netstandard1.3\AutoMapper.dll + + + \ No newline at end of file diff --git a/Ombi/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/Ombi/Ombi.TheMovieDbApi/TheMovieDbApi.cs index 76342d915..938065036 100644 --- a/Ombi/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/Ombi/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -1,72 +1,83 @@ -using System.Net.Http; +using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; -using Ombi.Api; +using AutoMapper; +using Ombi.Api.TheMovieDb.Models; using Ombi.TheMovieDbApi.Models; -namespace Ombi.TheMovieDbApi +namespace Ombi.Api.TheMovieDb { public class TheMovieDbApi : IMovieDbApi { - public TheMovieDbApi() + public TheMovieDbApi(IMapper mapper) { - Api = new Api.Api(); + Api = new Ombi.Api.Api(); + Mapper = mapper; } + + private IMapper Mapper { get; } private const string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00"; private static readonly string BaseUri ="http://api.themoviedb.org/3/"; - private Api.Api Api { get; } + private Ombi.Api.Api Api { get; } - public async Task GetMovieInformation(int movieId) + public async Task GetMovieInformation(int movieId) { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - - return await Api.Request(request); + + var result = await Api.Request(request); + return Mapper.Map(result); } - public async Task GetMovieInformationWithVideo(int movieId) + public async Task GetMovieInformationWithVideo(int movieId) { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("append_to_response", "videos"); - return await Api.Request(request); + var result = await Api.Request(request); + return Mapper.Map(result); } - public async Task> SearchMovie(string searchTerm) + public async Task> SearchMovie(string searchTerm) { var request = new Request($"search/movie", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm); - return await Api.Request>(request); + var result = await Api.Request>(request); + return Mapper.Map>(result.results); } - public async Task> PopularMovies() + public async Task> PopularMovies() { var request = new Request($"movie/popular", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - - return await Api.Request>(request); + var result = await Api.Request>(request); + return Mapper.Map>(result.results); } - public async Task> TopRated() + public async Task> TopRated() { var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - return await Api.Request>(request); + var result = await Api.Request>(request); + return Mapper.Map>(result.results); } - public async Task> Upcoming() + public async Task> Upcoming() { var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - return await Api.Request>(request); + var result = await Api.Request>(request); + return Mapper.Map>(result.results); } - public async Task> NowPlaying() + public async Task> NowPlaying() { var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - return await Api.Request>(request); + var result = await Api.Request>(request); + return Mapper.Map>(result.results); } } diff --git a/Ombi/Ombi/Ombi.csproj b/Ombi/Ombi/Ombi.csproj index fcbe7d811..6e5bddc50 100644 --- a/Ombi/Ombi/Ombi.csproj +++ b/Ombi/Ombi/Ombi.csproj @@ -20,6 +20,7 @@ + @@ -40,6 +41,7 @@ + diff --git a/Ombi/Ombi/Startup.cs b/Ombi/Ombi/Startup.cs index f27763977..f737b7633 100644 --- a/Ombi/Ombi/Startup.cs +++ b/Ombi/Ombi/Startup.cs @@ -1,6 +1,8 @@ using AutoMapper; +using AutoMapper.EquivalencyExpression; using Hangfire; using Hangfire.MemoryStorage; +using Hangfire.RecurringJobExtensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.StaticFiles; @@ -9,6 +11,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Ombi.DependencyInjection; using Ombi.Mapping; +using Ombi.Schedule; namespace Ombi { @@ -33,10 +36,20 @@ namespace Ombi // Add framework services. services.AddMvc(); services.AddOmbiMappingProfile(); - services.AddAutoMapper(); + services.AddAutoMapper(expression => + { + expression.AddCollectionMappers(); + }); services.RegisterDependencies(); // Ioc and EF - services.AddHangfire(x => x.UseMemoryStorage(new MemoryStorageOptions())); + + services.AddHangfire(x => + { + x.UseMemoryStorage(new MemoryStorageOptions()); + //using RecurringJobAttribute to build RecurringJob automatically. + x.UseRecurringJob(typeof(ITestJob)); + //x.UseActivator(new IoCJobActivator(services.BuildServiceProvider())); + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -54,6 +67,7 @@ namespace Ombi app.UseExceptionHandler("/Home/Error"); } + app.UseHangfireServer(); app.UseHangfireDashboard();