ЛР4 полность работают фильмы и жанры
This commit is contained in:
parent
b07faa67c5
commit
361d0a65ff
@ -33,13 +33,13 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addGenre(filmId) {
|
addGenre(filmId) {
|
||||||
let genreId = document.getElementById('genre').value;
|
let genreId = document.getElementById('genres').value;
|
||||||
let response = axios.post(`http://localhost:8080/film/add_genre/${filmId}`);
|
let response = axios.post(`http://localhost:8080/film/add_genre/${filmId}?genre_id=${genreId}`);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
},
|
},
|
||||||
delGenre(filmId) {
|
delGenre(filmId) {
|
||||||
let genreId = document.getElementById('genre').value;
|
let genreId = document.getElementById('genres').value;
|
||||||
let response = axios.delete(`http://localhost:8080/film/del_genre/${filmId}`);
|
let response = axios.delete(`http://localhost:8080/film/del_genre/${filmId}?genre_id=${genreId}`);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
},
|
},
|
||||||
itemsGenres(genreIds) {
|
itemsGenres(genreIds) {
|
||||||
@ -87,7 +87,7 @@
|
|||||||
:selectedItems="this.selectedItemsGenres">
|
:selectedItems="this.selectedItemsGenres">
|
||||||
</DataTable>
|
</DataTable>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="genres" class="form-label">Добавить жанр</label>
|
<label for="genres" class="form-label">Жанры</label>
|
||||||
<select class="form-select" id="genres" required>
|
<select class="form-select" id="genres" required>
|
||||||
<option disabled value="">Выберите жанр</option>
|
<option disabled value="">Выберите жанр</option>
|
||||||
<option v-for="genre in this.genres"
|
<option v-for="genre in this.genres"
|
||||||
@ -96,7 +96,11 @@
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
<button class="btn btn-outline-secondary" type="button" id="addGenreButton"
|
<button class="btn btn-outline-secondary" type="button" id="addGenreButton"
|
||||||
@click.prevent="addGenre(data.id)">Добавить</button>
|
@click.prevent="addGenre(data.id)">Добавить</button>
|
||||||
|
<button class="btn btn-outline-secondary" type="button" id="delGenreButton"
|
||||||
|
@click.prevent="delGenre(data.id)">Удалить</button>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</template>
|
</template>
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -71,13 +71,10 @@ public class FilmService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Film addGenre(Long filmId, Long genreId) {
|
public Film addGenre(Long filmId, Long genreId) {
|
||||||
final Optional<Film> filmOpt = filmRepository.findById(filmId);
|
Film film = findFilm(filmId);
|
||||||
|
if (film == null) {
|
||||||
if (filmOpt.isEmpty()) {
|
|
||||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||||
}
|
}
|
||||||
Film film = filmOpt.get();
|
|
||||||
|
|
||||||
final Genre genre = genreService.findGenre(genreId);
|
final Genre genre = genreService.findGenre(genreId);
|
||||||
if (genre == null) {
|
if (genre == null) {
|
||||||
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId));
|
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId));
|
||||||
@ -89,13 +86,10 @@ public class FilmService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Film deleteGenre(Long filmId, Long genreId) {
|
public Film deleteGenre(Long filmId, Long genreId) {
|
||||||
final Optional<Film> filmOpt = filmRepository.findById(filmId);
|
Film film = findFilm(filmId);
|
||||||
|
if (film == null) {
|
||||||
if (filmOpt.isEmpty()) {
|
|
||||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||||
}
|
}
|
||||||
Film film = filmOpt.get();
|
|
||||||
|
|
||||||
final Genre genre = genreService.findGenre(genreId);
|
final Genre genre = genreService.findGenre(genreId);
|
||||||
if (genre == null) {
|
if (genre == null) {
|
||||||
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId));
|
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId));
|
||||||
|
Loading…
Reference in New Issue
Block a user