diff --git a/Core.Application/DTOs/Movies/InfoSearchMovieDto.cs b/Core.Application/DTOs/Movies/InfoSearchMovieDto.cs new file mode 100644 index 0000000..d9cfa9a --- /dev/null +++ b/Core.Application/DTOs/Movies/InfoSearchMovieDto.cs @@ -0,0 +1,21 @@ +using Core.Application.DTOs.Genres; +using Core.Application.DTOs.Scraping; + +namespace Core.Application.DTOs.Movies +{ + public class InfoSearchMovieDto + { + public int ID { get; set; } + public int TMDBID { get; set; } + public string Title { get; set; } + public bool? Adult { get; set; } + public double? Vote_average { get; set; } + public string? Overview { get; set; } + public string? Poster_path { get; set; } + public string? Backdrop_path { get; set; } + public DateTime? Release_date { get; set; } + + public List Source { get; set; } + public List Genres { get; set; } + } +} diff --git a/Core.Application/Features/GenreModule/Commands/GetGenresFromAMovie/GetGenresFromAMovieCommand.cs b/Core.Application/Features/GenreModule/Commands/GetGenresFromAMovie/GetGenresFromAMovieCommand.cs new file mode 100644 index 0000000..751cca8 --- /dev/null +++ b/Core.Application/Features/GenreModule/Commands/GetGenresFromAMovie/GetGenresFromAMovieCommand.cs @@ -0,0 +1,39 @@ +using AutoMapper; +using Core.Application.DTOs.General; +using Core.Application.DTOs.Genres; +using Core.Application.Interface.Repositories; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Core.Application.Features.GenreModule.Commands.GetGenresFromAMovie +{ + public class GetGenresFromAMovieCommand : IRequest> + { + public required List Genres { get; set; } + } + public class GetGenresFromAMovieCommandHandler : IRequestHandler> + { + private readonly IGenreRepository _genreRepository; + private readonly IMapper _mapper; + + public GetGenresFromAMovieCommandHandler(IGenreRepository genreRepository, IMapper mapper) + { + _genreRepository = genreRepository; + _mapper = mapper; + } + + public async Task> Handle(GetGenresFromAMovieCommand request, CancellationToken cancellationToken) + { + var response = new List(); + foreach (var genre in request.Genres) + { + response.Add(_mapper.Map(await _genreRepository.GetByIdAsync(genre))); + } + return response; + } + } +} diff --git a/Core.Application/Features/Movies/GetAllMovieWebById/GetAllMovieWebByIdCommand.cs b/Core.Application/Features/Movies/GetAllMovieWebById/GetAllMovieWebByIdCommand.cs new file mode 100644 index 0000000..5d98947 --- /dev/null +++ b/Core.Application/Features/Movies/GetAllMovieWebById/GetAllMovieWebByIdCommand.cs @@ -0,0 +1,43 @@ +using AutoMapper; +using Core.Application.DTOs.General; +using Core.Application.DTOs.Scraping; +using Core.Application.Interface.Repositories; +using Core.Domain.Entities.WebScraping; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Core.Application.Features.Movies.GetAllMovieWebById +{ + public class GetAllMovieWebByIdCommand : IRequest> + { + public List MovieWebId { get; set; } + } + + public class GetAllMovieWebByIdCommandHandler : IRequestHandler> + { + private readonly IMovieWebRepository _movieWebRepository; + private readonly IMapper _mapper; + + public GetAllMovieWebByIdCommandHandler(IMovieWebRepository movieWebRepository, IMapper mapper) + { + _movieWebRepository = movieWebRepository; + _mapper = mapper; + } + + public async Task> Handle(GetAllMovieWebByIdCommand request, CancellationToken cancellationToken) + { + var response = new List(); + + foreach (var x in request.MovieWebId) + { + response.Add(_mapper.Map(await _movieWebRepository.GetByIdAsync(x))); + } + + return response; + } + } +} diff --git a/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMovieInfo/SearchMovieInfoQuery.cs b/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMovieInfo/SearchMovieInfoQuery.cs new file mode 100644 index 0000000..456db8c --- /dev/null +++ b/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMovieInfo/SearchMovieInfoQuery.cs @@ -0,0 +1,63 @@ +using AutoMapper; +using Core.Application.DTOs.General; +using Core.Application.DTOs.Genres; +using Core.Application.DTOs.Movies; +using Core.Application.Features.GenreModule.Commands.GetGenresFromAMovie; +using Core.Application.Features.Movies.GetAllMovieWebById; +using Core.Application.Interface.Repositories; +using Core.Domain.Entities.GeneralMovie; +using MediatR; +using System.Net; + +namespace Core.Application.Features.SearchMovieModule.Queries.SearchMovieModule.SearchMoviePages +{ + public class SearchMovieInfoQuery : IRequest> + { + public int MovieId { get; set; } + } + + public class SearchMovieInfoQueryHandler : IRequestHandler> + { + private readonly IMovieRepository _movieRepository; + private readonly IMovieWebRepository _movieWebRepository; + private readonly IMediator _mediator; + private readonly IMapper _mapper; + + public SearchMovieInfoQueryHandler(IMovieRepository movieRepository, IMovieWebRepository movieWebRepository, IMapper mapper, IMediator mediator) + { + _movieRepository = movieRepository; + _movieWebRepository = movieWebRepository; + _mapper = mapper; + _mediator = mediator; + } + + public async Task> Handle(SearchMovieInfoQuery request, CancellationToken cancellationToken) + { + try + { + var data = await _movieRepository.GetMovieInfo(request.MovieId); + var response = _mapper.Map(data); + response.Genres = await _mediator.Send(new GetGenresFromAMovieCommand { Genres = data.Genre_Movie.Select(x => x.GenreID).ToList() }); + response.Source = await _mediator.Send(new GetAllMovieWebByIdCommand { MovieWebId = data.Movie_MovieWeb.Select(x => x.MovieWebID).ToList() }); + + return new GenericApiResponse + { + Payload = _mapper.Map(response), + Message = "OK", + Success = true, + Statuscode = (int)HttpStatusCode.OK + }; + } + catch (Exception ex) + { + return new GenericApiResponse + { + Success = false, + Message = ex.Message, + Statuscode = (int)HttpStatusCode.InternalServerError, + Payload = null + }; + } + } + } +} diff --git a/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMoviePages/SearchMoviePagesQuery.cs b/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMoviePages/SearchMoviePagesQuery.cs deleted file mode 100644 index 3cf2edc..0000000 --- a/Core.Application/Features/SearchMovieModule/Queries/SearchMovieModule/SearchMoviePages/SearchMoviePagesQuery.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Core.Application.DTOs.General; -using Core.Application.DTOs.Movies; -using Core.Application.Interface.Repositories; -using MediatR; - -namespace Core.Application.Features.SearchMovieModule.Queries.SearchMovieModule.SearchMoviePages -{ - public class SearchMoviePagesQuery : IRequest> - { - public int MovieId { get; set; } - } - - public class SearchMoviePagesQueryHandler : IRequestHandler> - { - private readonly IMovieRepository _movieRepository; - private readonly IMovieWebRepository _movieWebRepository; - - public SearchMoviePagesQueryHandler(IMovieRepository movieRepository, IMovieWebRepository movieWebRepository) - { - _movieRepository = movieRepository; - _movieWebRepository = movieWebRepository; - } - - public async Task> Handle(SearchMoviePagesQuery request, CancellationToken cancellationToken) - { - var data = await _movieRepository.GetMovieWebPage(request.MovieId); - throw new NotImplementedException(); - } - } -} diff --git a/Core.Application/Helpers/TMDB/GetTMDBData.cs b/Core.Application/Helpers/TMDB/GetTMDBData.cs index 9116cbb..308fcad 100644 --- a/Core.Application/Helpers/TMDB/GetTMDBData.cs +++ b/Core.Application/Helpers/TMDB/GetTMDBData.cs @@ -19,7 +19,7 @@ public GetTMDBData(IConfiguration configuration, IMapper mapper) { _configuration = configuration; _mapper = mapper; - TMDBAPIKEY = _configuration["TMDBAPIKey"] ?? "false"; + TMDBAPIKEY = Environment.GetEnvironmentVariable("TMDBAPIKey") ?? _configuration["TMDBAPIKey"]; } public async Task GetTMDBId(List movies) diff --git a/Core.Application/Interface/Repositories/IMovieRepository.cs b/Core.Application/Interface/Repositories/IMovieRepository.cs index db087d2..f1654ad 100644 --- a/Core.Application/Interface/Repositories/IMovieRepository.cs +++ b/Core.Application/Interface/Repositories/IMovieRepository.cs @@ -9,6 +9,6 @@ public interface IMovieRepository : IGenericRepository Task> GetId(List movie); Task GetIdByTmdbId(int TmdbId); Task> SearchMovies(string Title); - Task GetMovieWebPage(int MovieId); + Task GetMovieInfo(int MovieId); } } diff --git a/Core.Application/Interface/Repositories/IMovieWebRepository.cs b/Core.Application/Interface/Repositories/IMovieWebRepository.cs index a558d8b..be60978 100644 --- a/Core.Application/Interface/Repositories/IMovieWebRepository.cs +++ b/Core.Application/Interface/Repositories/IMovieWebRepository.cs @@ -6,6 +6,5 @@ namespace Core.Application.Interface.Repositories public interface IMovieWebRepository : IGenericRepository { Task> Exist(List movie); - } } diff --git a/Core.Application/Mappings/GeneralProfile.cs b/Core.Application/Mappings/GeneralProfile.cs index f47ebf6..547dd2d 100644 --- a/Core.Application/Mappings/GeneralProfile.cs +++ b/Core.Application/Mappings/GeneralProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Core.Application.DTOs.Genres; using Core.Application.DTOs.Movies; using Core.Application.DTOs.Relations; using Core.Application.DTOs.Scraping; @@ -27,6 +28,15 @@ public GeneralProfile() CreateMap() .ReverseMap(); + + CreateMap() + .ReverseMap(); + + CreateMap() + .ReverseMap(); + + CreateMap() + .ReverseMap(); } } } diff --git a/Infraestructure.Persistence/Repositories/MovieRepository.cs b/Infraestructure.Persistence/Repositories/MovieRepository.cs index 983328d..16be839 100644 --- a/Infraestructure.Persistence/Repositories/MovieRepository.cs +++ b/Infraestructure.Persistence/Repositories/MovieRepository.cs @@ -53,9 +53,11 @@ public async Task GetIdByTmdbId(int TmdbId) return (await _dbContext.Set().FirstAsync(x => x.TMDBID == TmdbId)).ID; } - public async Task GetMovieWebPage(int MovieId) + public async Task GetMovieInfo(int MovieId) { - var response = await _dbContext.Set().Include(x => x.Movie_MovieWeb).FirstOrDefaultAsync(x => x.ID == MovieId); + var response = await _dbContext.Set().FindAsync(MovieId); + await _dbContext.Entry(response).Collection(x => x.Movie_MovieWeb).LoadAsync(); + await _dbContext.Entry(response).Collection(x => x.Genre_Movie).LoadAsync(); return response; } diff --git a/Infraestructure.Persistence/ServiceRegistration.cs b/Infraestructure.Persistence/ServiceRegistration.cs index 57f764f..ad287c1 100644 --- a/Infraestructure.Persistence/ServiceRegistration.cs +++ b/Infraestructure.Persistence/ServiceRegistration.cs @@ -13,7 +13,7 @@ public static class ServiceRegistration public static void AddPersistenceInfraestructure(this IServiceCollection services, IConfiguration configuration) { services.AddDbContext(options => - options.UseMySql(configuration.GetConnectionString("DefaultConnection"), new MySqlServerVersion(new Version(10, 6, 16)), m => + options.UseMySql(Environment.GetEnvironmentVariable("DefaultConnection") ?? configuration.GetConnectionString("DefaultConnection"), new MySqlServerVersion(new Version(10, 6, 16)), m => m.MigrationsAssembly(typeof(KhakuContext).Assembly.FullName).SchemaBehavior(MySqlSchemaBehavior.Ignore))); services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>)); diff --git a/Presentation.KuhakuCentral/Controllers/V1/MovieSearchModule/MovieSearchModuleController.cs b/Presentation.KuhakuCentral/Controllers/V1/MovieSearchModule/MovieSearchModuleController.cs index e264c4c..b654784 100644 --- a/Presentation.KuhakuCentral/Controllers/V1/MovieSearchModule/MovieSearchModuleController.cs +++ b/Presentation.KuhakuCentral/Controllers/V1/MovieSearchModule/MovieSearchModuleController.cs @@ -32,7 +32,7 @@ public async Task Search(string Title, List Values) )] public async Task Info(int MovieId) { - return Ok(await Mediator.Send(new SearchMoviePagesQuery { MovieId = MovieId })); + return Ok(await Mediator.Send(new SearchMovieInfoQuery { MovieId = MovieId })); } } } diff --git a/Presentation.KuhakuCentral/KuhakuCentral.csproj b/Presentation.KuhakuCentral/KuhakuCentral.csproj index a1195f2..0e3f5d4 100644 --- a/Presentation.KuhakuCentral/KuhakuCentral.csproj +++ b/Presentation.KuhakuCentral/KuhakuCentral.csproj @@ -7,7 +7,7 @@ - +