Skip to content

Commit

Permalink
Merge pull request #21 from AbreuHD/feature/GetMovieInfo
Browse files Browse the repository at this point in the history
GetMovieInfo Endpoint Done
  • Loading branch information
AbreuHD authored Sep 13, 2024
2 parents 00dc5f4 + 808b464 commit 8889980
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 38 deletions.
21 changes: 21 additions & 0 deletions Core.Application/DTOs/Movies/InfoSearchMovieDto.cs
Original file line number Diff line number Diff line change
@@ -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<MovieWebDTO> Source { get; set; }
public List<TmdbGenreResponseDto> Genres { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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<List<TmdbGenreResponseDto>>
{
public required List<int> Genres { get; set; }
}
public class GetGenresFromAMovieCommandHandler : IRequestHandler<GetGenresFromAMovieCommand, List<TmdbGenreResponseDto>>
{
private readonly IGenreRepository _genreRepository;
private readonly IMapper _mapper;

public GetGenresFromAMovieCommandHandler(IGenreRepository genreRepository, IMapper mapper)
{
_genreRepository = genreRepository;
_mapper = mapper;
}

public async Task<List<TmdbGenreResponseDto>> Handle(GetGenresFromAMovieCommand request, CancellationToken cancellationToken)
{
var response = new List<TmdbGenreResponseDto>();
foreach (var genre in request.Genres)
{
response.Add(_mapper.Map<TmdbGenreResponseDto>(await _genreRepository.GetByIdAsync(genre)));
}
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<List<MovieWebDTO>>
{
public List<int> MovieWebId { get; set; }
}

public class GetAllMovieWebByIdCommandHandler : IRequestHandler<GetAllMovieWebByIdCommand, List<MovieWebDTO>>
{
private readonly IMovieWebRepository _movieWebRepository;
private readonly IMapper _mapper;

public GetAllMovieWebByIdCommandHandler(IMovieWebRepository movieWebRepository, IMapper mapper)
{
_movieWebRepository = movieWebRepository;
_mapper = mapper;
}

public async Task<List<MovieWebDTO>> Handle(GetAllMovieWebByIdCommand request, CancellationToken cancellationToken)
{
var response = new List<MovieWebDTO>();

foreach (var x in request.MovieWebId)
{
response.Add(_mapper.Map<MovieWebDTO>(await _movieWebRepository.GetByIdAsync(x)));
}

return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<GenericApiResponse<InfoSearchMovieDto>>
{
public int MovieId { get; set; }
}

public class SearchMovieInfoQueryHandler : IRequestHandler<SearchMovieInfoQuery, GenericApiResponse<InfoSearchMovieDto>>
{
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<GenericApiResponse<InfoSearchMovieDto>> Handle(SearchMovieInfoQuery request, CancellationToken cancellationToken)
{
try
{
var data = await _movieRepository.GetMovieInfo(request.MovieId);
var response = _mapper.Map<InfoSearchMovieDto>(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<InfoSearchMovieDto>
{
Payload = _mapper.Map<InfoSearchMovieDto>(response),
Message = "OK",
Success = true,
Statuscode = (int)HttpStatusCode.OK
};
}
catch (Exception ex)
{
return new GenericApiResponse<InfoSearchMovieDto>
{
Success = false,
Message = ex.Message,
Statuscode = (int)HttpStatusCode.InternalServerError,
Payload = null
};
}
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion Core.Application/Helpers/TMDB/GetTMDBData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckedList> GetTMDBId(List<MovieWebDTO> movies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface IMovieRepository : IGenericRepository<Movie>
Task<List<Movie_MovieWeb>> GetId(List<Movie_MovieWeb> movie);
Task<int> GetIdByTmdbId(int TmdbId);
Task<List<Movie>> SearchMovies(string Title);
Task<Movie> GetMovieWebPage(int MovieId);
Task<Movie> GetMovieInfo(int MovieId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ namespace Core.Application.Interface.Repositories
public interface IMovieWebRepository : IGenericRepository<MovieWeb>
{
Task<List<MovieWebDTO>> Exist(List<MovieWebDTO> movie);

}
}
10 changes: 10 additions & 0 deletions Core.Application/Mappings/GeneralProfile.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -27,6 +28,15 @@ public GeneralProfile()

CreateMap<Movie, PreviewSearchMovieDto>()
.ReverseMap();

CreateMap<Movie, InfoSearchMovieDto>()
.ReverseMap();

CreateMap<MovieWeb, MovieWebDTO>()
.ReverseMap();

CreateMap<Genre, TmdbGenreResponseDto>()
.ReverseMap();
}
}
}
6 changes: 4 additions & 2 deletions Infraestructure.Persistence/Repositories/MovieRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public async Task<int> GetIdByTmdbId(int TmdbId)
return (await _dbContext.Set<Movie>().FirstAsync(x => x.TMDBID == TmdbId)).ID;
}

public async Task<Movie> GetMovieWebPage(int MovieId)
public async Task<Movie> GetMovieInfo(int MovieId)
{
var response = await _dbContext.Set<Movie>().Include(x => x.Movie_MovieWeb).FirstOrDefaultAsync(x => x.ID == MovieId);
var response = await _dbContext.Set<Movie>().FindAsync(MovieId);
await _dbContext.Entry(response).Collection(x => x.Movie_MovieWeb).LoadAsync();
await _dbContext.Entry(response).Collection(x => x.Genre_Movie).LoadAsync();
return response;
}

Expand Down
2 changes: 1 addition & 1 deletion Infraestructure.Persistence/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class ServiceRegistration
public static void AddPersistenceInfraestructure(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<KhakuContext>(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<>));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<IActionResult> Search(string Title, List<int> Values)
)]
public async Task<IActionResult> Info(int MovieId)
{
return Ok(await Mediator.Send(new SearchMoviePagesQuery { MovieId = MovieId }));
return Ok(await Mediator.Send(new SearchMovieInfoQuery { MovieId = MovieId }));
}
}
}
2 changes: 1 addition & 1 deletion Presentation.KuhakuCentral/KuhakuCentral.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Auth.Infraestructure.Identity" Version="0.0.3" />
<PackageReference Include="Auth.Infraestructure.Identity" Version="0.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
Expand Down

0 comments on commit 8889980

Please sign in to comment.