вся инфа по фильму выводится в карточку ))) вместе с просмотрами

This commit is contained in:
Елена Бакальская 2024-06-21 01:59:41 +04:00
parent 8ac47b0fdf
commit 34bc393330
4 changed files with 22 additions and 21 deletions

View File

@ -5,7 +5,6 @@ import java.util.ArrayList;
import org.modelmapper.ModelMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.example.backend.categories.service.CategorieService;
import com.example.backend.core.configurations.Constants;
@ -19,15 +18,11 @@ import com.example.backend.viewed.model.ViewedEntity;
import com.example.backend.viewed.service.ViewedService;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.security.core.Authentication;
import jakarta.validation.Valid;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
@ -38,11 +33,8 @@ public class MovieUserController {
public static final String URL = "/movies";
private static final String MOVIE_VIEW = "movies";
private static final String MOVIE_EDIT_VIEW = "movie-edit";
private static final String PAGE_ATTRIBUTE = "page";
private static final String MOVIE_ATTRIBUTE = "movie";
private static final String CATEGORIEID_ATTRIBUTE = "categorieId";
private static final String MOVEID_ATTRIBUTE = "movieId";
private final MovieService movieService;
private final CategorieService categorieService;
@ -70,11 +62,11 @@ public class MovieUserController {
return modelMapper.map(entity, MovieDTO.class);
}
private MovieEntity toEntity(MovieDTO dto) {
final MovieEntity entity = modelMapper.map(dto, MovieEntity.class);
entity.setCategorie(categorieService.get(dto.getCategorieId()));
return entity;
}
// private MovieEntity toEntity(MovieDTO dto) {
// final MovieEntity entity = modelMapper.map(dto, MovieEntity.class);
// entity.setCategorie(categorieService.get(dto.getCategorieId()));
// return entity;
// }
private List<MovieUserDTO> getListMovieUserDTOs(Integer categorieId, int page) {
List<MovieDTO> movies = movieService.getAll(categorieId, page, Constants.DEFUALT_PAGE_SIZE)
@ -92,6 +84,7 @@ public class MovieUserController {
for (MovieDTO movieDTO : movies) {
MovieUserDTO newMovDto = new MovieUserDTO();
newMovDto.setMovieDTO(movieDTO);
newMovDto.setCountViewes(movieService.countView(movieDTO.getId()));
for (FavoriteEntity favoriteEntity : favs) {
if ((int) favoriteEntity.getMovie().getId() == (int) movieDTO.getId()) {
@ -221,10 +214,11 @@ public class MovieUserController {
}
@GetMapping("/card/{id}")
public String getCardFilm(@PathVariable(name = "id") Integer movieId,
Model model) {
public String getCardFilm(@PathVariable(name = "id") Integer movieId, Model model) {
int countView = movieService.countView(movieId);
MovieEntity movie = movieService.get(movieId);
model.addAttribute("movie", movie);
model.addAttribute("countView", countView); // Изменено на countView
return "card-film";
}

View File

@ -12,6 +12,16 @@ public class MovieUserDTO {
@NotBlank
private boolean isViewed;
private Integer countViewes;
public Integer getCountViewes() {
return countViewes;
}
public void setCountViewes(Integer countViewes) {
this.countViewes = countViewes;
}
public MovieDTO getMovieDTO() {
return movieDTO;
}

View File

@ -7,20 +7,17 @@
<body>
<main layout:fragment="content">
<!-- <form action="#" th:action="@{/movies/card/{id}(id=${movie.movieDTO.id})}" -->
<!-- th:with="movie=${#authentication.name}" method="get"> -->
<div class="d-flex flex-row justify-content-center align-items-center mb-5 mt-5" th:object="${movie}">
<div class="d-flex flex-column justify-content-center align-items-center">
<div class="d-flex flex-column justify-content-center align-items-center" th:object="${countView}">
<img th:src="|https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg|"
class="rounded-3 mt-3 mb-3"></img>
<p class="category-name text-center mt-2 mb-3" th:text="${movie.name}"></p>
<p class="category-name text-center mt-2 mb-3" th:text="${movie.description}"></p>
<p class="category-name text-center mt-2 mb-3" th:text="${movie.duration}"></p>
<p class="category-name text-center mt-2 mb-3" th:text="'Вот столько человек меня
посмотрели...' + ${countView}"></p>
</div>
</div>
<!-- </form> -->
</main>
</body>

Binary file not shown.