все работает, только вот... пагинацию бы еще
This commit is contained in:
parent
34bc393330
commit
bfef99b5f2
@ -6,7 +6,7 @@ public class Constants {
|
||||
|
||||
public static final String SEQUENCE_NAME = "hibernate_sequence";
|
||||
|
||||
public static final int DEFUALT_PAGE_SIZE = 10;
|
||||
public static final int DEFUALT_PAGE_SIZE = 5;
|
||||
|
||||
public static final String REDIRECT_VIEW = "redirect:";
|
||||
|
||||
|
@ -1,77 +1,181 @@
|
||||
package com.example.backend.favorites.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.springframework.ui.Model;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.security.core.Authentication;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.backend.core.configurations.Constants;
|
||||
import com.example.backend.favorites.model.FavoriteEntity;
|
||||
import com.example.backend.favorites.service.FavoriteService;
|
||||
import com.example.backend.movies.api.MovieDTO;
|
||||
import com.example.backend.movies.api.MovieUserDTO;
|
||||
import com.example.backend.movies.model.MovieEntity;
|
||||
import com.example.backend.movies.service.MovieService;
|
||||
import com.example.backend.users.model.UserEntity;
|
||||
import com.example.backend.users.service.UserService;
|
||||
import com.example.backend.viewed.model.ViewedEntity;
|
||||
import com.example.backend.viewed.service.ViewedService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Constants.API_URL + "/favorite")
|
||||
@Controller
|
||||
@RequestMapping(FavoriteController.URL)
|
||||
public class FavoriteController {
|
||||
|
||||
public static final String URL = "/favs";
|
||||
private static final String FAVORITE_VIEW = "favs";
|
||||
private static final String PAGE_ATTRIBUTE = "page";
|
||||
|
||||
private final FavoriteService favoriteService;
|
||||
private final UserService userService;
|
||||
private final MovieService movieService;
|
||||
private final ModelMapper modelMapper;
|
||||
private final ViewedService viewedServise;
|
||||
|
||||
public FavoriteController(FavoriteService favoriteService, UserService userService,
|
||||
MovieService movieService, ModelMapper modelMapper) {
|
||||
MovieService movieService, ModelMapper modelMapper, ViewedService viewedServise) {
|
||||
this.modelMapper = modelMapper;
|
||||
this.userService = userService;
|
||||
this.favoriteService = favoriteService;
|
||||
this.viewedServise = viewedServise;
|
||||
this.movieService = movieService;
|
||||
}
|
||||
|
||||
private FavoriteDto toDto(FavoriteEntity entity) {
|
||||
return modelMapper.map(entity, FavoriteDto.class);
|
||||
private MovieDTO toDtoMovie(MovieEntity entity) {
|
||||
return modelMapper.map(entity, MovieDTO.class);
|
||||
}
|
||||
|
||||
private FavoriteEntity toEntity(FavoriteDto dto) {
|
||||
final FavoriteEntity entity = modelMapper.map(dto, FavoriteEntity.class);
|
||||
entity.setMovie(movieService.get(dto.getMovieId()));
|
||||
entity.setUser(userService.get(dto.getUserId()));
|
||||
return entity;
|
||||
private List<MovieUserDTO> getListMovieUserDTOs(Integer categorieId, int page) {
|
||||
List<MovieDTO> movies = movieService.getAll(categorieId, page, Constants.DEFUALT_PAGE_SIZE)
|
||||
.stream()
|
||||
.map(this::toDtoMovie)
|
||||
.toList();
|
||||
List<MovieUserDTO> muDTO = new ArrayList<MovieUserDTO>();
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
List<FavoriteEntity> favs = favoriteService.getAll(currentUserId);
|
||||
List<ViewedEntity> viewes = viewedServise.getAll(currentUserId);
|
||||
|
||||
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()) {
|
||||
newMovDto.setFavorite(true);
|
||||
break;
|
||||
}
|
||||
newMovDto.setFavorite(false);
|
||||
}
|
||||
|
||||
for (ViewedEntity viewedEntity : viewes) {
|
||||
if ((int) viewedEntity.getMovie().getId() == (int) movieDTO.getId()) {
|
||||
newMovDto.setViewed(true);
|
||||
break;
|
||||
}
|
||||
newMovDto.setViewed(false);
|
||||
}
|
||||
|
||||
muDTO.add(newMovDto);
|
||||
}
|
||||
return muDTO;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<FavoriteDto> getAll(@RequestParam(name = "userId", defaultValue = "0") Integer userId) {
|
||||
return favoriteService.getAll(userId).stream().map(this::toDto).toList();
|
||||
@GetMapping()
|
||||
public String getAll(Model model, @RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page) {
|
||||
List<MovieUserDTO> muDTO = getListMovieUserDTOs(0, page);
|
||||
model.addAttribute("movies", muDTO);
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
return FAVORITE_VIEW;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public FavoriteDto get(@PathVariable(name = "id") Integer id) {
|
||||
return toDto(favoriteService.get(id));
|
||||
@PostMapping("/changeFavStatus/{id}")
|
||||
public String changeFavStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
Model model) {
|
||||
|
||||
boolean isFavorite = false;
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
FavoriteEntity fav = favoriteService.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
if (fav == null) {
|
||||
isFavorite = false;
|
||||
} else {
|
||||
isFavorite = true;
|
||||
}
|
||||
|
||||
if (isFavorite == false) {
|
||||
|
||||
UserEntity user = userService.get(currentUserId);
|
||||
MovieEntity movie = movieService.get(movieId);
|
||||
|
||||
FavoriteEntity newFav = new FavoriteEntity(null, user, movie);
|
||||
|
||||
favoriteService.create(newFav);
|
||||
|
||||
} else {
|
||||
|
||||
FavoriteEntity delFav = favoriteService.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
favoriteService.delete(delFav.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public FavoriteDto create(@RequestBody @Valid FavoriteDto dto) {
|
||||
return toDto(favoriteService.create(toEntity(dto)));
|
||||
@PostMapping("/changeViewStatus/{id}")
|
||||
public String changeViewStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
Model model) {
|
||||
|
||||
boolean isViewed = false;
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
ViewedEntity view = viewedServise.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
if (view == null) {
|
||||
isViewed = false;
|
||||
} else {
|
||||
isViewed = true;
|
||||
}
|
||||
|
||||
if (isViewed == false) {
|
||||
|
||||
UserEntity user = userService.get(currentUserId);
|
||||
MovieEntity movie = movieService.get(movieId);
|
||||
|
||||
ViewedEntity newView = new ViewedEntity(null, user, movie);
|
||||
|
||||
viewedServise.create(newView);
|
||||
|
||||
} else {
|
||||
|
||||
ViewedEntity delView = viewedServise.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
viewedServise.delete(delView.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public FavoriteDto update(@PathVariable(name = "id") Integer id,
|
||||
@RequestBody FavoriteDto dto) {
|
||||
return toDto(favoriteService.update(id, toEntity(dto)));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public FavoriteDto delete(@PathVariable(name = "id") Integer id) {
|
||||
return toDto(favoriteService.delete(id));
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ package com.example.backend.favorites.repository;
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import com.example.backend.favorites.model.FavoriteEntity;
|
||||
|
||||
public interface FavoriteRepository extends CrudRepository<FavoriteEntity, Integer> {
|
||||
public interface FavoriteRepository
|
||||
extends CrudRepository<FavoriteEntity, Integer>, PagingAndSortingRepository<FavoriteEntity, Integer> {
|
||||
|
||||
List<FavoriteEntity> findByUserId(Integer userId);
|
||||
|
||||
|
@ -3,12 +3,16 @@ package com.example.backend.favorites.service;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.backend.core.errors.NotFoundException;
|
||||
import com.example.backend.favorites.model.FavoriteEntity;
|
||||
import com.example.backend.favorites.repository.FavoriteRepository;
|
||||
import com.example.backend.users.model.UserEntity;
|
||||
|
||||
@Service
|
||||
public class FavoriteService {
|
||||
@ -26,6 +30,11 @@ public class FavoriteService {
|
||||
return repository.findByUserId(userId);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<FavoriteEntity> getAll(int page, int size) {
|
||||
return repository.findAll(PageRequest.of(page, size, Sort.by("id")));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FavoriteEntity get(Integer id) {
|
||||
return repository.findById(id).orElseThrow(() -> new NotFoundException(FavoriteEntity.class, id));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.backend.movies.api;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -21,6 +22,7 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import com.example.backend.core.api.PageAttributesMapper;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
@ -1,78 +1,182 @@
|
||||
package com.example.backend.viewed.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.backend.core.configurations.Constants;
|
||||
import com.example.backend.favorites.model.FavoriteEntity;
|
||||
import com.example.backend.favorites.service.FavoriteService;
|
||||
import com.example.backend.viewed.model.ViewedEntity;
|
||||
import com.example.backend.viewed.service.ViewedService;
|
||||
import com.example.backend.movies.api.MovieDTO;
|
||||
import com.example.backend.movies.api.MovieUserDTO;
|
||||
import com.example.backend.movies.model.MovieEntity;
|
||||
import com.example.backend.movies.service.MovieService;
|
||||
import com.example.backend.users.model.UserEntity;
|
||||
import com.example.backend.users.service.UserService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Constants.API_URL + "/viewed")
|
||||
@Controller
|
||||
@RequestMapping(ViewedController.URL)
|
||||
public class ViewedController {
|
||||
|
||||
private final ViewedService viewedService;
|
||||
public static final String URL = "/viewed";
|
||||
private static final String FAVORITE_VIEW = "viewed";
|
||||
private static final String PAGE_ATTRIBUTE = "page";
|
||||
|
||||
private final FavoriteService favoriteService;
|
||||
private final UserService userService;
|
||||
private final MovieService movieService;
|
||||
private final ModelMapper modelMapper;
|
||||
private final ViewedService viewedServise;
|
||||
|
||||
public ViewedController(
|
||||
ViewedService viewedService, UserService userService,
|
||||
MovieService movieService, ModelMapper modelMapper) {
|
||||
FavoriteService favoriteService, UserService userService,
|
||||
MovieService movieService, ModelMapper modelMapper, ViewedService viewedServise) {
|
||||
this.modelMapper = modelMapper;
|
||||
this.userService = userService;
|
||||
this.viewedService = viewedService;
|
||||
this.favoriteService = favoriteService;
|
||||
this.viewedServise = viewedServise;
|
||||
this.movieService = movieService;
|
||||
}
|
||||
|
||||
private ViewedDto toDto(ViewedEntity entity) {
|
||||
return modelMapper.map(entity, ViewedDto.class);
|
||||
private MovieDTO toDtoMovie(MovieEntity entity) {
|
||||
return modelMapper.map(entity, MovieDTO.class);
|
||||
}
|
||||
|
||||
private ViewedEntity toEntity(ViewedDto dto) {
|
||||
final ViewedEntity entity = modelMapper.map(dto, ViewedEntity.class);
|
||||
entity.setMovie(movieService.get(dto.getMovieId()));
|
||||
entity.setUser(userService.get(dto.getUserId()));
|
||||
return entity;
|
||||
private List<MovieUserDTO> getListMovieUserDTOs(Integer categorieId, int page) {
|
||||
List<MovieDTO> movies = movieService.getAll(categorieId, page, Constants.DEFUALT_PAGE_SIZE)
|
||||
.stream()
|
||||
.map(this::toDtoMovie)
|
||||
.toList();
|
||||
List<MovieUserDTO> muDTO = new ArrayList<MovieUserDTO>();
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
List<FavoriteEntity> favs = favoriteService.getAll(currentUserId);
|
||||
List<ViewedEntity> viewes = viewedServise.getAll(currentUserId);
|
||||
|
||||
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()) {
|
||||
newMovDto.setFavorite(true);
|
||||
break;
|
||||
}
|
||||
newMovDto.setFavorite(false);
|
||||
}
|
||||
|
||||
for (ViewedEntity viewedEntity : viewes) {
|
||||
if ((int) viewedEntity.getMovie().getId() == (int) movieDTO.getId()) {
|
||||
newMovDto.setViewed(true);
|
||||
break;
|
||||
}
|
||||
newMovDto.setViewed(false);
|
||||
}
|
||||
|
||||
muDTO.add(newMovDto);
|
||||
}
|
||||
return muDTO;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<ViewedDto> getAll(@RequestParam(name = "userId", defaultValue = "0") Integer userId) {
|
||||
return viewedService.getAll(userId).stream().map(this::toDto).toList();
|
||||
@GetMapping()
|
||||
public String getAll(Model model, @RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page) {
|
||||
List<MovieUserDTO> muDTO = getListMovieUserDTOs(0, page);
|
||||
model.addAttribute("movies", muDTO);
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
return FAVORITE_VIEW;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ViewedDto get(@PathVariable(name = "id") Integer id) {
|
||||
return toDto(viewedService.get(id));
|
||||
@PostMapping("/changeFavStatus/{id}")
|
||||
public String changeFavStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
Model model) {
|
||||
|
||||
boolean isFavorite = false;
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
FavoriteEntity fav = favoriteService.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
if (fav == null) {
|
||||
isFavorite = false;
|
||||
} else {
|
||||
isFavorite = true;
|
||||
}
|
||||
|
||||
if (isFavorite == false) {
|
||||
|
||||
UserEntity user = userService.get(currentUserId);
|
||||
MovieEntity movie = movieService.get(movieId);
|
||||
|
||||
FavoriteEntity newFav = new FavoriteEntity(null, user, movie);
|
||||
|
||||
favoriteService.create(newFav);
|
||||
|
||||
} else {
|
||||
|
||||
FavoriteEntity delFav = favoriteService.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
favoriteService.delete(delFav.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ViewedDto create(@RequestBody @Valid ViewedDto dto) {
|
||||
return toDto(viewedService.create(toEntity(dto)));
|
||||
}
|
||||
@PostMapping("/changeViewStatus/{id}")
|
||||
public String changeViewStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
Model model) {
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ViewedDto update(@PathVariable(name = "id") Integer id,
|
||||
@RequestBody ViewedDto dto) {
|
||||
return toDto(viewedService.update(id, toEntity(dto)));
|
||||
}
|
||||
boolean isViewed = false;
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ViewedDto delete(@PathVariable(name = "id") Integer id) {
|
||||
return toDto(viewedService.delete(id));
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Integer currentUserId = userService.getCurrentUserId(authentication.getName());
|
||||
|
||||
ViewedEntity view = viewedServise.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
if (view == null) {
|
||||
isViewed = false;
|
||||
} else {
|
||||
isViewed = true;
|
||||
}
|
||||
|
||||
if (isViewed == false) {
|
||||
|
||||
UserEntity user = userService.get(currentUserId);
|
||||
MovieEntity movie = movieService.get(movieId);
|
||||
|
||||
ViewedEntity newView = new ViewedEntity(null, user, movie);
|
||||
|
||||
viewedServise.create(newView);
|
||||
|
||||
} else {
|
||||
|
||||
ViewedEntity delView = viewedServise.findByUserIdAndMovieId(currentUserId, movieId);
|
||||
|
||||
viewedServise.delete(delView.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@ import java.util.Optional;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import com.example.backend.viewed.model.ViewedEntity;
|
||||
|
||||
public interface ViewedRepository extends CrudRepository<ViewedEntity, Integer> {
|
||||
public interface ViewedRepository
|
||||
extends CrudRepository<ViewedEntity, Integer>, PagingAndSortingRepository<ViewedEntity, Integer> {
|
||||
|
||||
List<ViewedEntity> findByUserId(Integer userId);
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
||||
|
||||
|
||||
<head>
|
||||
<title>Просмотренные</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main layout:fragment="content">
|
||||
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
68
backend/src/main/resources/templates/favs.html
Normal file
68
backend/src/main/resources/templates/favs.html
Normal file
@ -0,0 +1,68 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
||||
|
||||
<head>
|
||||
<title>Избранные</title>
|
||||
<style>
|
||||
.card-img-top {
|
||||
height: 200px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.categories-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
flex: 1 1 calc(33.333% - 10px);
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main layout:fragment="content">
|
||||
<th:block th:switch="${movies.size()}">
|
||||
<h2 th:case="0">Данные отсутствуют</h2>
|
||||
<th:block th:case="*">
|
||||
<div class="categories-container d-flex flex-row justify-content-center mt-3 mb-3">
|
||||
<div class="category-item d-flex flex-column justify-content-center align-items-center mb-5 mb-md-0"
|
||||
th:each="movie : ${movies}" th:if="${movie.isFavorite}">
|
||||
|
||||
<div class="category-card">
|
||||
<a th:href="@{/movies/card/{id}(id=${movie.movieDTO.id})}">
|
||||
<img class="card-img-top rounded-3"
|
||||
th:src="|https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg|" />
|
||||
</a>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" th:text="${movie.movieDTO.name}"></h5>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-row ms-mt-2">
|
||||
<form th:action="@{/favs/changeFavStatus/{id}(id=${movie.movieDTO.id})}" method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
<i th:if="${movie.isFavorite}" class="heart-icon bi bi-heart-fill"></i>
|
||||
<i th:if="${!movie.isFavorite}" class="heart-icon bi bi-heart"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form th:action="@{/favs/changeViewStatus/{id}(id=${movie.movieDTO.id})}" method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
<i th:if="${movie.isViewed}" class="eye-icon bi bi-eye-fill"></i>
|
||||
<i th:if="${!movie.isViewed}" class="eye-icon bi bi-eye"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</th:block>
|
||||
</th:block>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -49,8 +49,8 @@
|
||||
th:classappend="${activeLink.startsWith('/categories') ? 'active' : '' }">Категории</a>
|
||||
<a class="nav-link" href="/movies"
|
||||
th:classappend="${activeLink.startsWith('/movies') ? 'active' : '' }">Фильмы</a>
|
||||
<a class="nav-link" href="/favorites"
|
||||
th:classappend="${activeLink.startsWith('/favorites') ? 'active' : '' }">Избранные</a>
|
||||
<a class="nav-link" href="/favs"
|
||||
th:classappend="${activeLink.startsWith('/favs') ? 'active' : '' }">Избранные</a>
|
||||
<a class="nav-link" href="/viewed"
|
||||
th:classappend="${activeLink.startsWith('/viewed') ? 'active' : '' }">Просмотренные</a>
|
||||
</th:block>
|
||||
|
@ -107,7 +107,7 @@
|
||||
|
||||
<div class="d-flex flex-row ms-mt-2">
|
||||
|
||||
<form th:action="@{/movies/changeFavStatus/{id}(id=${movie.movieDTO.id})}"
|
||||
<form th:action="@{/movies/changeFavStatus/{id}(id=${movie.movieDTO.id},page=${page})}"
|
||||
method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
@ -115,7 +115,7 @@
|
||||
<i th:if="${!movie.isFavorite}" class="heart-icon bi bi-heart"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form th:action="@{/movies/changeViewStatus/{id}(id=${movie.movieDTO.id})}"
|
||||
<form th:action="@{/movies/changeViewStatus/{id}(id=${movie.movieDTO.id},page=${page})}"
|
||||
method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
@ -135,10 +135,9 @@
|
||||
</th:block>
|
||||
|
||||
<th:block th:replace="~{ pagination :: pagination (
|
||||
url=${'movies'},
|
||||
totalPages=${totalPages},
|
||||
currentPage=${currentPage}) }">
|
||||
</th:block>
|
||||
url=${'movies'},
|
||||
totalPages=${totalPages},
|
||||
currentPage=${currentPage}) }" />
|
||||
|
||||
</th:block>
|
||||
</th:block>
|
||||
|
67
backend/src/main/resources/templates/viewed.html
Normal file
67
backend/src/main/resources/templates/viewed.html
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
||||
|
||||
<head>
|
||||
<title>Просмотренные</title>
|
||||
<style>
|
||||
.card-img-top {
|
||||
height: 200px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.categories-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
flex: 1 1 calc(33.333% - 10px);
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main layout:fragment="content">
|
||||
<th:block th:switch="${movies.size()}">
|
||||
<h2 th:case="0">Данные отсутствуют</h2>
|
||||
<th:block th:case="*">
|
||||
<div class="categories-container d-flex flex-row justify-content-center mt-3 mb-3">
|
||||
<div class="category-item d-flex flex-column justify-content-center align-items-center mb-5 mb-md-0"
|
||||
th:each="movie : ${movies}" th:if="${movie.isViewed}">
|
||||
|
||||
<div class="category-card">
|
||||
<a th:href="@{/movies/card/{id}(id=${movie.movieDTO.id})}">
|
||||
<img class="card-img-top rounded-3"
|
||||
th:src="|https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg|" />
|
||||
</a>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" th:text="${movie.movieDTO.name}"></h5>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-row ms-mt-2">
|
||||
<form th:action="@{/viewed/changeFavStatus/{id}(id=${movie.movieDTO.id})}" method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
<i th:if="${movie.isFavorite}" class="heart-icon bi bi-heart-fill"></i>
|
||||
<i th:if="${!movie.isFavorite}" class="heart-icon bi bi-heart"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form th:action="@{/viewed/changeViewStatus/{id}(id=${movie.movieDTO.id})}" method="post">
|
||||
<input type="hidden" th:name="page" th:value="${page}">
|
||||
<button type="submit" class="btn btn-link button-link">
|
||||
<i th:if="${movie.isViewed}" class="eye-icon bi bi-eye-fill"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</th:block>
|
||||
</th:block>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user