-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from AbreuHD/feature/GetMovieInfo
GetMovieInfo Endpoint Done
- Loading branch information
Showing
13 changed files
with
185 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...plication/Features/GenreModule/Commands/GetGenresFromAMovie/GetGenresFromAMovieCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Core.Application/Features/Movies/GetAllMovieWebById/GetAllMovieWebByIdCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...tures/SearchMovieModule/Queries/SearchMovieModule/SearchMovieInfo/SearchMovieInfoQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
} | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
...res/SearchMovieModule/Queries/SearchMovieModule/SearchMoviePages/SearchMoviePagesQuery.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters