в общем... оображаются все фильмы по выбранным категориям, а так же все фильмы при переходк на вкладку фильмов... все через одно место, но для админа достаточно вообще прям. нужно еще подредактировать ээ... редактирование фильма (категория не отображается)
This commit is contained in:
parent
d20e7b620b
commit
ae0b310be9
@ -8,8 +8,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
|
|
||||||
import com.example.backend.categories.model.CategorieEntity;
|
import com.example.backend.categories.model.CategorieEntity;
|
||||||
import com.example.backend.categories.service.CategorieService;
|
import com.example.backend.categories.service.CategorieService;
|
||||||
import com.example.backend.users.model.UserEntity;
|
import com.example.backend.movies.model.MovieEntity;
|
||||||
import com.example.backend.users.model.UserRole;
|
import com.example.backend.movies.service.MovieService;
|
||||||
import com.example.backend.users.service.UserService;
|
import com.example.backend.users.service.UserService;
|
||||||
|
|
||||||
// create lab 2
|
// create lab 2
|
||||||
@ -20,10 +20,14 @@ public class BackendApplication implements CommandLineRunner {
|
|||||||
private final Logger _logger = LoggerFactory.getLogger(BackendApplication.class);
|
private final Logger _logger = LoggerFactory.getLogger(BackendApplication.class);
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final CategorieService categorieService;
|
private final CategorieService categorieService;
|
||||||
|
private final MovieService movieService;
|
||||||
|
|
||||||
public BackendApplication(UserService userService, CategorieService categorieService) {
|
public BackendApplication(UserService userService,
|
||||||
|
CategorieService categorieService,
|
||||||
|
MovieService movieService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.categorieService = categorieService;
|
this.categorieService = categorieService;
|
||||||
|
this.movieService = movieService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -32,49 +36,56 @@ public class BackendApplication implements CommandLineRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
final var admin = new UserEntity(null, "elena", "1234");
|
|
||||||
final var vasya = new UserEntity(null, "vasya", "1234");
|
|
||||||
|
|
||||||
final var u1 = new UserEntity(null, "1", "1234");
|
// final var admin = new UserEntity(null, "elena", "1234");
|
||||||
final var u2 = new UserEntity(null, "2", "1234");
|
// final var vasya = new UserEntity(null, "vasya", "1234");
|
||||||
final var u3 = new UserEntity(null, "3", "1234");
|
|
||||||
final var u4 = new UserEntity(null, "4", "1234");
|
|
||||||
final var u5 = new UserEntity(null, "5", "1234");
|
|
||||||
final var u6 = new UserEntity(null, "6", "1234");
|
|
||||||
final var u7 = new UserEntity(null, "7", "1234");
|
|
||||||
|
|
||||||
final var cat1 = new CategorieEntity(null, "Драма", null);
|
// final var u1 = new UserEntity(null, "1", "1234");
|
||||||
final var cat2 = new CategorieEntity(null, "Комедия", null);
|
// final var u2 = new UserEntity(null, "2", "1234");
|
||||||
final var cat3 = new CategorieEntity(null, "Хоррор", null);
|
// final var u3 = new UserEntity(null, "3", "1234");
|
||||||
final var cat4 = new CategorieEntity(null, "Мультитк", null);
|
// final var u4 = new UserEntity(null, "4", "1234");
|
||||||
|
// final var u5 = new UserEntity(null, "5", "1234");
|
||||||
|
// final var u6 = new UserEntity(null, "6", "1234");
|
||||||
|
// final var u7 = new UserEntity(null, "7", "1234");
|
||||||
|
|
||||||
admin.setRole(UserRole.ADMIN);
|
// final var cat1 = new CategorieEntity(null, "Драма", null);
|
||||||
vasya.setRole(UserRole.USER);
|
// final var cat2 = new CategorieEntity(null, "Комедия", null);
|
||||||
|
// final var cat3 = new CategorieEntity(null, "Хоррор", null);
|
||||||
|
// final var cat4 = new CategorieEntity(null, "Мультитк", null);
|
||||||
|
|
||||||
u1.setRole(UserRole.USER);
|
final var cat5 = new CategorieEntity(null, "Опера", null);
|
||||||
u2.setRole(UserRole.USER);
|
|
||||||
u3.setRole(UserRole.USER);
|
|
||||||
u4.setRole(UserRole.USER);
|
|
||||||
u5.setRole(UserRole.USER);
|
|
||||||
u6.setRole(UserRole.USER);
|
|
||||||
u7.setRole(UserRole.USER);
|
|
||||||
|
|
||||||
userService.create(admin);
|
final var mov1 = new MovieEntity(null, cat5, "певчая птичка", "null", "null", null);
|
||||||
userService.create(vasya);
|
|
||||||
userService.create(u1);
|
|
||||||
userService.create(u2);
|
|
||||||
userService.create(u3);
|
|
||||||
userService.create(u4);
|
|
||||||
userService.create(u5);
|
|
||||||
userService.create(u6);
|
|
||||||
userService.create(u7);
|
|
||||||
|
|
||||||
categorieService.create(cat1);
|
// admin.setRole(UserRole.ADMIN);
|
||||||
categorieService.create(cat2);
|
// vasya.setRole(UserRole.USER);
|
||||||
categorieService.create(cat3);
|
|
||||||
categorieService.create(cat4);
|
|
||||||
|
|
||||||
_logger.info("Admin user added");
|
// u1.setRole(UserRole.USER);
|
||||||
|
// u2.setRole(UserRole.USER);
|
||||||
|
// u3.setRole(UserRole.USER);
|
||||||
|
// u4.setRole(UserRole.USER);
|
||||||
|
// u5.setRole(UserRole.USER);
|
||||||
|
// u6.setRole(UserRole.USER);
|
||||||
|
// u7.setRole(UserRole.USER);
|
||||||
|
|
||||||
|
// userService.create(admin);
|
||||||
|
// userService.create(vasya);
|
||||||
|
// userService.create(u1);
|
||||||
|
// userService.create(u2);
|
||||||
|
// userService.create(u3);
|
||||||
|
// userService.create(u4);
|
||||||
|
// userService.create(u5);
|
||||||
|
// userService.create(u6);
|
||||||
|
// userService.create(u7);
|
||||||
|
|
||||||
|
// categorieService.create(cat1);
|
||||||
|
// categorieService.create(cat2);
|
||||||
|
// categorieService.create(cat3);
|
||||||
|
// categorieService.create(cat4);
|
||||||
|
// categorieService.create(cat5);
|
||||||
|
// movieService.create(mov1);
|
||||||
|
|
||||||
|
_logger.info("The program is started");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package com.example.backend.categories.api;
|
|||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import com.example.backend.categories.model.CategorieEntity;
|
import com.example.backend.categories.model.CategorieEntity;
|
||||||
@ -63,8 +61,7 @@ public class CategorieController {
|
|||||||
|
|
||||||
@PostMapping("/edit/")
|
@PostMapping("/edit/")
|
||||||
public String create(@ModelAttribute(name = CATEGORIE_ATTRIBUTE) @Valid CategorieDTO categorieDTO,
|
public String create(@ModelAttribute(name = CATEGORIE_ATTRIBUTE) @Valid CategorieDTO categorieDTO,
|
||||||
BindingResult bindingResult, RedirectAttributes redirectAttributes,
|
BindingResult bindingResult, RedirectAttributes redirectAttributes) {
|
||||||
@RequestParam("imageFile") MultipartFile imageFile) {
|
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
return CATEGORIE_EDIT_VIEW;
|
return CATEGORIE_EDIT_VIEW;
|
||||||
}
|
}
|
||||||
@ -85,15 +82,13 @@ public class CategorieController {
|
|||||||
@PostMapping("/edit/{id}")
|
@PostMapping("/edit/{id}")
|
||||||
public String update(@PathVariable(name = "id") Integer id,
|
public String update(@PathVariable(name = "id") Integer id,
|
||||||
@ModelAttribute(name = CATEGORIE_ATTRIBUTE) @Valid CategorieDTO categorieDTO,
|
@ModelAttribute(name = CATEGORIE_ATTRIBUTE) @Valid CategorieDTO categorieDTO,
|
||||||
BindingResult bindingResult, RedirectAttributes redirectAttributes,
|
BindingResult bindingResult, RedirectAttributes redirectAttributes) {
|
||||||
@RequestParam("imageFile") MultipartFile imageFile) {
|
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
return CATEGORIE_EDIT_VIEW;
|
return CATEGORIE_EDIT_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
CategorieEntity category = toEntity(categorieDTO);
|
CategorieEntity category = toEntity(categorieDTO);
|
||||||
|
|
||||||
category.setImage(categorieService.get(id).getImage());
|
|
||||||
categorieService.update(id, category);
|
categorieService.update(id, category);
|
||||||
return Constants.REDIRECT_VIEW + URL;
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String SEQUENCE_NAME = "hibernate_sequence";
|
public static final String SEQUENCE_NAME = "hibernate_sequence";
|
||||||
|
|
||||||
public static final int DEFUALT_PAGE_SIZE = 5;
|
public static final int DEFUALT_PAGE_SIZE = 10;
|
||||||
|
|
||||||
public static final String REDIRECT_VIEW = "redirect:";
|
public static final String REDIRECT_VIEW = "redirect:";
|
||||||
|
|
||||||
|
@ -2,29 +2,46 @@ package com.example.backend.movies.api;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import com.example.backend.categories.service.CategorieService;
|
import com.example.backend.categories.service.CategorieService;
|
||||||
|
import com.example.backend.core.api.PageAttributesMapper;
|
||||||
import com.example.backend.core.configurations.Constants;
|
import com.example.backend.core.configurations.Constants;
|
||||||
import com.example.backend.movies.model.MovieEntity;
|
import com.example.backend.movies.model.MovieEntity;
|
||||||
import com.example.backend.movies.service.MovieService;
|
import com.example.backend.movies.service.MovieService;
|
||||||
|
import com.example.backend.users.api.UserDTO;
|
||||||
|
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
|
||||||
@RestController
|
@Controller
|
||||||
@RequestMapping(Constants.API_URL + "/movie")
|
@RequestMapping(MovieController.URL)
|
||||||
public class MovieController {
|
public class MovieController {
|
||||||
|
|
||||||
|
public static final String URL = Constants.ADMIN_PREFIX + "/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 final MovieService movieService;
|
private final MovieService movieService;
|
||||||
private final CategorieService categorieService;
|
private final CategorieService categorieService;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
@ -45,34 +62,98 @@ public class MovieController {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping()
|
||||||
public List<MovieDTO> getAll(@RequestParam(name = "categorieId", defaultValue = "0") Integer categorieId) {
|
public String getAll(@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
return movieService.getAll(categorieId).stream().map(this::toDto).toList();
|
Model model) {
|
||||||
|
model.addAttribute("movies",
|
||||||
|
movieService.getAll(0, page, Constants.DEFUALT_PAGE_SIZE)
|
||||||
|
.stream()
|
||||||
|
.map(this::toDto)
|
||||||
|
.toList());
|
||||||
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
|
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
model.addAttribute(CATEGORIEID_ATTRIBUTE, 0);
|
||||||
|
return MOVIE_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/categorieId/{id}")
|
||||||
public MovieDTO get(@PathVariable(name = "id") Integer id) {
|
public String getAll(@PathVariable(name = "id") Integer categorieId,
|
||||||
return toDto(movieService.get(id));
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
|
Model model) {
|
||||||
|
model.addAttribute("movies",
|
||||||
|
movieService.getAll(categorieId, page, Constants.DEFUALT_PAGE_SIZE)
|
||||||
|
.stream()
|
||||||
|
.map(this::toDto)
|
||||||
|
.toList());
|
||||||
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
|
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
model.addAttribute(CATEGORIEID_ATTRIBUTE, categorieId);
|
||||||
|
return MOVIE_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@GetMapping("/edit/")
|
||||||
public MovieDTO create(@RequestBody @Valid MovieDTO dto) {
|
public String create(@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page, Model model) {
|
||||||
return toDto(movieService.create(toEntity(dto)));
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
|
model.addAttribute(MOVIE_ATTRIBUTE, new MovieDTO());
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
return MOVIE_EDIT_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PostMapping("/edit/")
|
||||||
public MovieDTO update(@PathVariable(name = "id") Integer id, @RequestBody MovieDTO dto) {
|
public String create(@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
return toDto(movieService.update(id, toEntity(dto)));
|
@ModelAttribute(name = MOVIE_ATTRIBUTE) @Valid MovieDTO movieDTO,
|
||||||
|
BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
return MOVIE_EDIT_VIEW;
|
||||||
|
}
|
||||||
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
|
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
movieService.create(toEntity(movieDTO));
|
||||||
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@GetMapping("/edit/{id}")
|
||||||
public MovieDTO delete(@PathVariable(name = "id") Integer id) {
|
public String update(@PathVariable(name = "id") Integer id,
|
||||||
return toDto(movieService.delete(id));
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page, Model model) {
|
||||||
|
if (id <= 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
model.addAttribute(MOVIE_ATTRIBUTE, toDto(movieService.get(id)));
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
return MOVIE_EDIT_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/edit/{id}")
|
||||||
|
public String update(@PathVariable(name = "id") Integer id,
|
||||||
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
|
@ModelAttribute(name = MOVIE_ATTRIBUTE) @Valid MovieDTO movieDTO,
|
||||||
|
BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
return MOVIE_EDIT_VIEW;
|
||||||
|
}
|
||||||
|
if (id <= 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
movieService.update(id, toEntity(movieDTO));
|
||||||
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete/{id}")
|
||||||
|
public String delete(@PathVariable(name = "id") Integer id,
|
||||||
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
|
RedirectAttributes redirectAttributes) {
|
||||||
|
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
movieService.delete(id);
|
||||||
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/countView")
|
@GetMapping("/countView")
|
||||||
public Integer countView(@RequestParam(name = "movieId", defaultValue = "0") Integer movieId) {
|
public Integer countView(@RequestParam(name = "movieId", defaultValue = "0") Integer movieId) {
|
||||||
return movieService.countView(movieId);
|
return movieService.countView(movieId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,24 @@
|
|||||||
package com.example.backend.movies.repository;
|
package com.example.backend.movies.repository;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import com.example.backend.movies.model.MovieEntity;
|
import com.example.backend.movies.model.MovieEntity;
|
||||||
|
|
||||||
public interface MovieRepository extends CrudRepository<MovieEntity, Integer> {
|
public interface MovieRepository
|
||||||
|
extends CrudRepository<MovieEntity, Integer>, PagingAndSortingRepository<MovieEntity, Integer> {
|
||||||
|
|
||||||
Optional<MovieEntity> findByNameIgnoreCase(String name);
|
Optional<MovieEntity> findByNameIgnoreCase(String name);
|
||||||
|
|
||||||
Optional<MovieEntity> findByCategorieIdAndId(Integer categorieId, Integer id);
|
Optional<MovieEntity> findByCategorieIdAndId(Integer categorieId, Integer id);
|
||||||
|
|
||||||
List<MovieEntity> findByCategorieId(Integer categorieId);
|
Page<MovieEntity> findByCategorieId(Integer categorieId, Pageable page);
|
||||||
|
|
||||||
@Query("SELECT COUNT(DISTINCT v.user.id) FROM ViewedEntity v WHERE v.movie.id = :movieId")
|
@Query("SELECT COUNT(DISTINCT v.user.id) FROM ViewedEntity v WHERE v.movie.id = :movieId")
|
||||||
Integer getCountViews(@Param("movieId") Integer movieId);
|
Integer getCountViews(@Param("movieId") Integer movieId);
|
||||||
|
@ -3,6 +3,9 @@ package com.example.backend.movies.service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.StreamSupport;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -27,12 +30,14 @@ public class MovieService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<MovieEntity> getAll(Integer categorieId) {
|
public Page<MovieEntity> getAll(Integer categorieId, int page, int size) {
|
||||||
|
if (categorieId < 0) {
|
||||||
if (categorieId == 0) {
|
throw new IllegalArgumentException(String.format("This %d id is not found", categorieId));
|
||||||
return StreamSupport.stream(repository.findAll().spliterator(), false).toList();
|
|
||||||
}
|
}
|
||||||
return repository.findByCategorieId(categorieId);
|
if (categorieId == 0) {
|
||||||
|
return repository.findAll(PageRequest.of(page, size, Sort.by("id")));
|
||||||
|
}
|
||||||
|
return repository.findByCategorieId(categorieId, PageRequest.of(page, size, Sort.by("id")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
@ -58,7 +63,8 @@ public class MovieService {
|
|||||||
exisEntity.setDescription(entity.getDescription());
|
exisEntity.setDescription(entity.getDescription());
|
||||||
exisEntity.setDuration(entity.getDuration());
|
exisEntity.setDuration(entity.getDuration());
|
||||||
exisEntity.setImage(entity.getImage());
|
exisEntity.setImage(entity.getImage());
|
||||||
return repository.save(exisEntity);
|
repository.save(exisEntity);
|
||||||
|
return exisEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -11,7 +11,7 @@ spring.datasource.url=jdbc:h2:file:./data
|
|||||||
spring.datasource.username=elina
|
spring.datasource.username=elina
|
||||||
spring.datasource.password=elina
|
spring.datasource.password=elina
|
||||||
spring.datasource.driver-class-name=org.h2.Driver
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
spring.jpa.hibernate.ddl-auto=create
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.open-in-view=false
|
spring.jpa.open-in-view=false
|
||||||
#spring.jpa.show-sql=true
|
#spring.jpa.show-sql=true
|
||||||
#spring.jpa.properties.hibernate.format_sql=true
|
#spring.jpa.properties.hibernate.format_sql=true
|
||||||
|
@ -32,8 +32,10 @@
|
|||||||
<div class="category-item d-flex flex-column justify-content-center align-items-center mb-5 mb-md-0"
|
<div class="category-item d-flex flex-column justify-content-center align-items-center mb-5 mb-md-0"
|
||||||
th:each="categorie : ${categories}">
|
th:each="categorie : ${categories}">
|
||||||
<div class="category-card">
|
<div class="category-card">
|
||||||
<img class="card-img-top rounded-3"
|
<a th:href="@{/admin/movies/categorieId/{id}(id=${categorie.id})}">
|
||||||
th:src="${categorie.image != null ? 'data:image/jpeg;base64,' + categorie.image : 'https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg'}" />
|
<img class="card-img-top rounded-3"
|
||||||
|
th:src="${categorie.image != null ? 'data:image/jpeg;base64,' + categorie.image : 'https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg'}" />
|
||||||
|
</a>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title" th:text="${categorie.name}"></h5>
|
<h5 class="card-title" th:text="${categorie.name}"></h5>
|
||||||
</div>
|
</div>
|
||||||
|
51
backend/src/main/resources/templates/movie-edit.html
Normal file
51
backend/src/main/resources/templates/movie-edit.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Редактирование/создание ФиЛьМа =3</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main layout:fragment="content">
|
||||||
|
<h1>Редактирование/создание ФиЛьМа =3</h1>
|
||||||
|
<form action="#" th:action="@{/admin/movies/edit/{id}(id=${movie.id},page=${page})}" th:object="${movie}"
|
||||||
|
method="post" enctype="multipart/form-data">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="id" class="form-label">ID</label>
|
||||||
|
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label" for="name">Название:</label>
|
||||||
|
<input class="form-control" type="text" id="name" th:field="*{name}" />
|
||||||
|
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label" for="description">Описание:</label>
|
||||||
|
<input class="form-control" type="text" id="description" th:field="*{description}" />
|
||||||
|
<div th:if="${#fields.hasErrors('description')}" th:errors="*{description}" class="invalid-feedback">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label" for="duration">Продолжительность:</label>
|
||||||
|
<input class="form-control" type="text" id="duration" th:field="*{duration}" />
|
||||||
|
<div th:if="${#fields.hasErrors('duration')}" th:errors="*{duration}" class="invalid-feedback"></div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label" for="categorie">Категория:</label>
|
||||||
|
<select th:field="*{categorieId}" id="categorie" class="form-select">
|
||||||
|
<option value="" selected>Выберите категорию</option>
|
||||||
|
<option th:each="categorie : ${categories}" th:value="${categorie.id}" th:text="${categorie.name}">
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<div th:if="${#fields.hasErrors('categorieId')}" th:errors="*{categorieId}" class="invalid-feedback">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 d-flex flex-row">
|
||||||
|
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
|
||||||
|
<a class="btn btn-secondary button-fixed-width" th:href="@{/admin/movies(page=${page})}">Отмена</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -2,47 +2,85 @@
|
|||||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Вход</title>
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<main layout:fragment="content">
|
||||||
<main layout:fragment="content" class='main-bg-into d-flex flex-fill'>
|
<th:block th:switch="${movies.size()}">
|
||||||
<form action="#" th:action="@{/login}" method="post"
|
<h2 th:case="0">Данные отсутствуют</h2>
|
||||||
class="body flex-fill d-flex flex-column justify-content-around align-items-center" id="into-page">
|
<div class="d-flex flex-row me-2 justify-content-center mt-3 mb-3">
|
||||||
|
<a th:href="@{/admin/movies/edit/(page=${page})}" class="btn btn-primary">Добавить фильм</a>
|
||||||
<p class="text-label mt-4 d-flex flex-column align-items-center align-content-center">
|
|
||||||
Имя пользователя / электронная почта
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="mb-2 w-50">
|
|
||||||
<input id="username" class="form-control" placeholder="Имя пользователя / Эл. Почта" type="text"
|
|
||||||
name='username' required minlength="3" maxlength="50">
|
|
||||||
</input>
|
|
||||||
<p th:if="${param.error}" class="error mt-2">
|
|
||||||
Введите правильное имя пользователя
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<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}">
|
||||||
|
<div class="category-card">
|
||||||
|
<img class="card-img-top rounded-3"
|
||||||
|
th:src="|https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg|" />
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title" th:text="${movie.name}"></h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex flex-row me-ms-mt-2">
|
||||||
|
<form th:action="@{/admin/movies/edit/{id}(id=${movie.id})}" method="get">
|
||||||
|
<input type="hidden" th:name="page" th:value="${page}">
|
||||||
|
<button type="submit" class="btn btn-link button-link">
|
||||||
|
<svg class="bi-edit-pen" viewBox="0 0 127 127" fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M105.5 26L37 114.5C34.5 117 16.3 121.7 7.5 122.5C79.1 34.1 101 5.5 102 4C104.833 4.5 119.3 14.6 122.5 21C105 44 98.5 55 111.5 58.5"
|
||||||
|
stroke="#008315" stroke-width="6" stroke-linecap="round" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form th:action="@{/admin/movies/delete/{id}(id=${movie.id})}" method="post">
|
||||||
|
<input type="hidden" th:name="page" th:value="${page}">
|
||||||
|
<button type="submit" class="btn btn-link button-link"
|
||||||
|
onclick="return confirm('Вы уверены?')">
|
||||||
|
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5"
|
||||||
|
stroke="#D10000" stroke-width="8" stroke-linecap="round" />
|
||||||
|
<path
|
||||||
|
d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z"
|
||||||
|
stroke="#D10000" stroke-width="8" />
|
||||||
|
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8"
|
||||||
|
stroke-linecap="round" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p class="text-label d-flex flex-column align-items-center">
|
</th:block>
|
||||||
Пароль
|
</th:block>
|
||||||
</p>
|
<th:block th:replace="~{ pagination :: pagination (
|
||||||
<div class="mb-2 w-50">
|
url=${'admin/movies'},
|
||||||
<input id="password" class="form-control" placeholder="Пароль" type="password" name='password' required
|
totalPages=${totalPages},
|
||||||
minlength="4" maxlength="20">
|
currentPage=${currentPage}) }" />
|
||||||
</input>
|
|
||||||
<p th:if="${param.error}" class="error mt-2">
|
|
||||||
Введите верный пароль
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-4 h-25 d-flex flex-column justify-content-center mb-4">
|
|
||||||
<a class="btn btn-secondary button-fixed-width" href="/signup">Регистрация</a>
|
|
||||||
<button type="submit" class="btn btn-light">Войти</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -6,12 +6,12 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<main layout:fragment="content">
|
<main layout:fragment="content" class="overflow-auto" style="max-height: 100vh;">
|
||||||
<th:block th:switch="${items.size()}">
|
<th:block th:switch="${items.size()}">
|
||||||
<h2 th:case="0">Данные отсутствуют</h2>
|
<h2 th:case="0">Данные отсутствуют</h2>
|
||||||
<th:block th:case="*">
|
<th:block th:case="*">
|
||||||
<h2>Пользователи</h2>
|
<h2>Пользователи</h2>
|
||||||
<div>
|
<div class="d-flex flex-column justify-content-center align-items-center">
|
||||||
<a th:href="@{/admin/user/edit/(page=${page})}" class="btn btn-primary">Добавить пользователя</a>
|
<a th:href="@{/admin/user/edit/(page=${page})}" class="btn btn-primary">Добавить пользователя</a>
|
||||||
</div>
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user