Оно кароч работает но доделаю потом
This commit is contained in:
parent
23c059922d
commit
f50af7950d
@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.example.demo.core.configuration.Constants;
|
||||
import com.example.demo.films.model.FilmEntity;
|
||||
import com.example.demo.films.service.FilmService;
|
||||
import com.example.demo.genres.api.GenreDto;
|
||||
import com.example.demo.genres.model.GenreEntity;
|
||||
import com.example.demo.genres.service.GenreService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@ -24,10 +27,12 @@ public class FilmController {
|
||||
private static final String FILM_EDIT_VIEW = "film-edit";
|
||||
private static final String FILM_ATTRIBUTE = "film";
|
||||
|
||||
private final GenreService genreService;
|
||||
private final FilmService filmService;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
public FilmController(FilmService filmService, ModelMapper modelMapper) {
|
||||
public FilmController(GenreService genreService, FilmService filmService, ModelMapper modelMapper) {
|
||||
this.genreService = genreService;
|
||||
this.filmService = filmService;
|
||||
this.modelMapper = modelMapper;
|
||||
}
|
||||
@ -36,6 +41,10 @@ public class FilmController {
|
||||
return modelMapper.map(entity, FilmDto.class);
|
||||
}
|
||||
|
||||
private GenreDto toGenreDto(GenreEntity entity) {
|
||||
return modelMapper.map(entity, GenreDto.class);
|
||||
}
|
||||
|
||||
private FilmEntity toEntity(FilmDto dto) {
|
||||
return modelMapper.map(dto, FilmEntity.class);
|
||||
}
|
||||
@ -53,6 +62,11 @@ public class FilmController {
|
||||
@GetMapping("/edit/")
|
||||
public String create(Model model) {
|
||||
model.addAttribute(FILM_ATTRIBUTE, new FilmDto());
|
||||
model.addAttribute(
|
||||
"genres",
|
||||
genreService.getAll().stream()
|
||||
.map(this::toGenreDto)
|
||||
.toList());
|
||||
return FILM_EDIT_VIEW;
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,14 @@ public class FilmService {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<FilmEntity> createAll(long userId, List<FilmEntity> entities) {
|
||||
if (entities == null || entities.isEmpty()) {
|
||||
throw new IllegalArgumentException("Films list is null or empty");
|
||||
}
|
||||
return StreamSupport.stream(repository.saveAll(entities).spliterator(), false).toList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public FilmEntity update(Long id, FilmEntity entity) {
|
||||
final FilmEntity existsEntity = get(id);
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
||||
|
||||
<head>
|
||||
<title>Редакторовать фильм</title>
|
||||
<title>Редакторовать тип заказа</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -12,19 +12,20 @@
|
||||
<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-2">
|
||||
<label for="genre" class="form-label">Товары</label>
|
||||
<select th:field="*{genreName}" id="genre" class="form-select">
|
||||
<option selected value="">Укажите тип товара</option>
|
||||
<option th:each="genre : ${genres}" th:value="${genre.id}">[[${genre.name}]]</option>
|
||||
</select>
|
||||
<div th:if="${#fields.hasErrors('genreName')}" th:errors="*{genreName}" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Фильм</label>
|
||||
<label for="name" class="form-label">Жанр фильма</label>
|
||||
<input type="text" th:field="*{name}" id="name" class="form-control">
|
||||
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<select th:name="genreId" id="genreId" class="form-select">
|
||||
<option selected value="">Фильтр по типу товара</option>
|
||||
<option th:each="genre : ${genres}" th:value="${genre.id}" th:selected="${genre.id==genreId}">
|
||||
[[${genre.name}]]
|
||||
</option>
|
||||
</select>
|
||||
</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" href="/admin/film">Отмена</a>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
||||
|
||||
<head>
|
||||
<title>Фильмы</title>
|
||||
<title>Жанры фильмов</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -10,16 +10,16 @@
|
||||
<th:block th:switch="${items.size()}">
|
||||
<h2 th:case="0">Данные отсутствуют</h2>
|
||||
<th:block th:case="*">
|
||||
<h2>Фильмы</h2>
|
||||
<h2>Жанры фильмов</h2>
|
||||
<div>
|
||||
<a href="/admin/film/edit/" class="btn btn-primary">Добавить фильм</a>
|
||||
<a href="/admin/film/edit/" class="btn btn-primary">Добавить новый жанр</a>
|
||||
</div>
|
||||
<table class="table">
|
||||
<caption></caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="w-10">ID</th>
|
||||
<th scope="col" class="w-auto">Фильм</th>
|
||||
<th scope="col" class="w-auto">Жанр фильма</th>
|
||||
<th scope="col" class="w-10"></th>
|
||||
<th scope="col" class="w-10"></th>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user