категории создаются, удаляются, фильмы редактируются, починила удаление категорий - добавила динамический запрос для удаления всех связанных фильмов
This commit is contained in:
parent
ae0b310be9
commit
1fe72328a0
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.backend.core.errors.NotFoundException;
|
import com.example.backend.core.errors.NotFoundException;
|
||||||
|
import com.example.backend.movies.repository.MovieRepository;
|
||||||
import com.example.backend.categories.model.CategorieEntity;
|
import com.example.backend.categories.model.CategorieEntity;
|
||||||
import com.example.backend.categories.repository.CategorieRepository;
|
import com.example.backend.categories.repository.CategorieRepository;
|
||||||
|
|
||||||
@ -15,9 +16,11 @@ import com.example.backend.categories.repository.CategorieRepository;
|
|||||||
public class CategorieService {
|
public class CategorieService {
|
||||||
|
|
||||||
private final CategorieRepository repository;
|
private final CategorieRepository repository;
|
||||||
|
private final MovieRepository movieRepository;
|
||||||
|
|
||||||
public CategorieService(CategorieRepository repository) {
|
public CategorieService(CategorieRepository repository, MovieRepository movieRepository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
this.movieRepository = movieRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkName(String name) {
|
private void checkName(String name) {
|
||||||
@ -57,6 +60,7 @@ public class CategorieService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public CategorieEntity delete(Integer id) {
|
public CategorieEntity delete(Integer id) {
|
||||||
final CategorieEntity existsentity = get(id);
|
final CategorieEntity existsentity = get(id);
|
||||||
|
movieRepository.deleteByCategorieId(existsentity.getId());
|
||||||
repository.delete(existsentity);
|
repository.delete(existsentity);
|
||||||
return existsentity;
|
return existsentity;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ public class MovieController {
|
|||||||
return MOVIE_EDIT_VIEW;
|
return MOVIE_EDIT_VIEW;
|
||||||
}
|
}
|
||||||
model.addAttribute("categories", categorieService.getAll());
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
|
model.addAttribute(CATEGORIEID_ATTRIBUTE, 0);
|
||||||
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
movieService.create(toEntity(movieDTO));
|
movieService.create(toEntity(movieDTO));
|
||||||
return Constants.REDIRECT_VIEW + URL;
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
@ -121,6 +122,7 @@ public class MovieController {
|
|||||||
if (id <= 0) {
|
if (id <= 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
model.addAttribute("categories", categorieService.getAll());
|
||||||
model.addAttribute(MOVIE_ATTRIBUTE, toDto(movieService.get(id)));
|
model.addAttribute(MOVIE_ATTRIBUTE, toDto(movieService.get(id)));
|
||||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
return MOVIE_EDIT_VIEW;
|
return MOVIE_EDIT_VIEW;
|
||||||
|
@ -20,6 +20,8 @@ public interface MovieRepository
|
|||||||
|
|
||||||
Page<MovieEntity> findByCategorieId(Integer categorieId, Pageable page);
|
Page<MovieEntity> findByCategorieId(Integer categorieId, Pageable page);
|
||||||
|
|
||||||
|
Optional<MovieEntity> deleteByCategorieId(Integer categorieId);
|
||||||
|
|
||||||
@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);
|
||||||
|
|
||||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user