Skip to content

Commit

Permalink
Merge pull request #23 from AbreuHD/feature/home-add-home-screen-endp…
Browse files Browse the repository at this point in the history
…oint

Get Home data endpoint added, now we can get 6 movies for each genre,…
  • Loading branch information
AbreuHD authored Sep 15, 2024
2 parents f86a412 + 2be2035 commit b55523e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
16 changes: 9 additions & 7 deletions Core.Application/DTOs/Home/HomeDTO.cs
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; }
}
}
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;
}
}
}
2 changes: 1 addition & 1 deletion Core.Application/Mappings/GeneralProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public GeneralProfile()
.ReverseMap();

CreateMap<Genre, TmdbGenreResponseDto>()
.ReverseMap();
.ReverseMap();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class HomeModuleController : BaseAPI
Summary = "Home Page",
Description = "Get Home Page Data"
)]
public async Task<IActionResult> Home()
public async Task<IActionResult> Home(bool KidMode = false)
{
return Ok(await Mediator.Send(new GetHomePageDataQuery()));
return Ok(await Mediator.Send(new GetHomePageDataQuery() { KidMode = KidMode}));
}
}
}

0 comments on commit b55523e

Please sign in to comment.