-
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 #23 from AbreuHD/feature/home-add-home-screen-endp…
…oint Get Home data endpoint added, now we can get 6 movies for each genre,…
- Loading branch information
Showing
4 changed files
with
70 additions
and
16 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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
using Core.Application.DTOs.Movies; | ||
using Core.Application.DTOs.Genres; | ||
using Core.Application.DTOs.Movies; | ||
|
||
namespace Core.Application.DTOs.Home | ||
{ | ||
public class HomeDto | ||
{ | ||
public List<PreviewSearchMovieDto>? Accion { get; set; } | ||
public List<PreviewSearchMovieDto>? Animacion { get; set; } | ||
public List<PreviewSearchMovieDto>? Horror { get; set; } | ||
public List<PreviewSearchMovieDto>? Romance { get; set; } | ||
public List<PreviewSearchMovieDto>? Familiar { get; set; } | ||
public List<PreviewSearchMovieDto>? History { get; set; } | ||
public TmdbGenreResponseDto Genre { get; set; } | ||
public List<PreviewSearchMovieDto>? Movies { get; set; } | ||
//public List<PreviewSearchMovieDto>? Animacion { get; set; } | ||
//public List<PreviewSearchMovieDto>? Horror { get; set; } | ||
//public List<PreviewSearchMovieDto>? Romance { get; set; } | ||
//public List<PreviewSearchMovieDto>? Familiar { get; set; } | ||
//public List<PreviewSearchMovieDto>? History { get; set; } | ||
} | ||
} |
64 changes: 58 additions & 6 deletions
64
...ion/Features/SearchMovieModule/Queries/HomeModule/GetHomePageData/GetHomePageDataQuery.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 |
---|---|---|
@@ -1,18 +1,70 @@ | ||
using Core.Application.DTOs.General; | ||
using AutoMapper; | ||
using Core.Application.DTOs.General; | ||
using Core.Application.DTOs.Genres; | ||
using Core.Application.DTOs.Home; | ||
using Core.Application.DTOs.Movies; | ||
using Core.Application.Interface.Repositories; | ||
using MediatR; | ||
|
||
namespace Core.Application.Features.SearchMovieModule.Queries.HomeModule.GetHomePageData | ||
{ | ||
public class GetHomePageDataQuery : IRequest<GenericApiResponse<HomeDto>> | ||
public class GetHomePageDataQuery : IRequest<GenericApiResponse<List<HomeDto>>> | ||
{ | ||
|
||
public bool KidMode { get; set; } = false; | ||
} | ||
public class GetHomePageDataQueryHandler : IRequestHandler<GetHomePageDataQuery, GenericApiResponse<HomeDto>> | ||
public class GetHomePageDataQueryHandler : IRequestHandler<GetHomePageDataQuery, GenericApiResponse<List<HomeDto>>> | ||
{ | ||
public async Task<GenericApiResponse<HomeDto>> Handle(GetHomePageDataQuery request, CancellationToken cancellationToken) | ||
private readonly IMovieRepository _movieRepository; | ||
private readonly IGenreRepository _genreRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public GetHomePageDataQueryHandler(IMovieRepository movieRepository, IGenreRepository genre, IMapper mapper) | ||
{ | ||
throw new NotImplementedException(); | ||
_movieRepository = movieRepository; | ||
_genreRepository = genre; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<GenericApiResponse<List<HomeDto>>> Handle(GetHomePageDataQuery request, CancellationToken cancellationToken) | ||
{ | ||
var response = new GenericApiResponse<List<HomeDto>>(); | ||
response.Payload = new List<HomeDto>(); | ||
|
||
var genres = await _genreRepository.GetAllWithIncludes( new List<string> { "Genre_Movie" }); | ||
|
||
foreach (var genre in genres) | ||
{ | ||
var i = 0; | ||
foreach (var x in genre.Genre_Movie) | ||
{ | ||
var movieToAdd = await _movieRepository.GetByIdAsync(x.MovieID); | ||
|
||
if (request.KidMode) | ||
{ | ||
if(movieToAdd.Adult is false) | ||
{ | ||
i++; | ||
x.Movie = movieToAdd; | ||
} | ||
} | ||
else | ||
{ | ||
i++; | ||
x.Movie = movieToAdd; | ||
} | ||
if (i == 6) { break; } | ||
} | ||
|
||
if (genre.Genre_Movie.Count is not 0) | ||
{ | ||
response.Payload.Add(new HomeDto | ||
{ | ||
Genre = _mapper.Map<TmdbGenreResponseDto>(genre), | ||
Movies = _mapper.Map<List<PreviewSearchMovieDto>>(genre.Genre_Movie.Select(x => x.Movie).ToList()) | ||
}); | ||
} | ||
} | ||
return response; | ||
} | ||
} | ||
} |
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