Compare commits
No commits in common. "Lab4" and "main" have entirely different histories.
28
Frontend/vue-project/.gitignore
vendored
28
Frontend/vue-project/.gitignore
vendored
@ -1,28 +0,0 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
@ -1,29 +0,0 @@
|
||||
# vue-project
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
|
||||
|
||||
## Customize configuration
|
||||
|
||||
See [Vite Configuration Reference](https://vitejs.dev/config/).
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/node_modules/@fortawesome/fontawesome-free/css/all.min.css">
|
||||
<title>VIDEO | FILMS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
3072
Frontend/vue-project/package-lock.json
generated
3072
Frontend/vue-project/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,26 +0,0 @@
|
||||
{
|
||||
"name": "vue-project",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.2.1",
|
||||
"@vuelidate/core": "^2.0.0",
|
||||
"@vuelidate/validators": "^2.0.0",
|
||||
"axios": "^1.1.3",
|
||||
"bootstrap": "^5.2.2",
|
||||
"vue": "^3.2.47",
|
||||
"vue-router": "^4.1.6",
|
||||
"vuelidate": "^0.7.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.0.0",
|
||||
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
||||
"vite": "^4.3.1"
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
@ -1,34 +0,0 @@
|
||||
<script>
|
||||
import Header from './components/Header.vue';
|
||||
import Footer from './components/Footer.vue';
|
||||
export default {
|
||||
components: {
|
||||
Header,
|
||||
Footer
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Header></Header>
|
||||
<div class="container-fluid">
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
<Footer></Footer>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: fixed;
|
||||
background-color: blue !important;
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
.last_info, .block_films{
|
||||
font-size: 2rem !important;
|
||||
}
|
||||
.mock {
|
||||
width: 100%;
|
||||
height: 120px;
|
||||
}
|
||||
</style>
|
@ -1,243 +0,0 @@
|
||||
<script>
|
||||
import 'axios';
|
||||
import axios from "axios";
|
||||
import Collection from "../models/Collection";
|
||||
import Film from "../models/Film";
|
||||
export default {
|
||||
created() {
|
||||
this.getCollections();
|
||||
this.getFilms();
|
||||
},
|
||||
mounted() {
|
||||
const addModal = document.getElementById('editModal');
|
||||
addModal.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
const openModalForAdd = document.getElementById('openModalForAdd');
|
||||
openModalForAdd.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return{
|
||||
collections: [],
|
||||
URL: "http://localhost:8080/",
|
||||
collection: new Collection(),
|
||||
films: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getCollections(){
|
||||
axios.get(this.URL + "collection")
|
||||
.then(response => {
|
||||
this.collections = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
addCollection(collection){
|
||||
console.log(collection);
|
||||
axios.post(this.URL + "collection", collection)
|
||||
.then(() => {
|
||||
this.getCollections();
|
||||
this.closeModal();
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
deleteCollection(id){
|
||||
axios.delete(this.URL + `collection/${id}`)
|
||||
.then(() =>{
|
||||
this.getCollections();
|
||||
})
|
||||
},
|
||||
editCollection(collection){
|
||||
axios.put(this.URL + `collection/${collection.id}`, collection)
|
||||
.then(() =>{
|
||||
const index = this.collections.findIndex((s) => s.id === collection.id);
|
||||
if (index !== -1) {
|
||||
this.collections[index] = { ...collection };
|
||||
}
|
||||
this.closeModal();
|
||||
this.getCollections();
|
||||
})
|
||||
this.closeModal();
|
||||
},
|
||||
openModalForAdd(status, collection = null) {
|
||||
if (status === "create") {
|
||||
this.collection = new Collection();
|
||||
this.collection.status = "create";
|
||||
} else if (status === "edit" && collection) {
|
||||
this.collection = { ...collection };
|
||||
this.collection.status = "edit";
|
||||
}
|
||||
document.getElementById("openModalForAdd").style.display = "block";
|
||||
},
|
||||
closeModalForAdd() {
|
||||
document.getElementById("openModalForAdd").style.display = "none";
|
||||
this.collection = new Collection();
|
||||
},
|
||||
openModal(status, collection = null) {
|
||||
if (status === "create") {
|
||||
this.collection = new Collection();
|
||||
this.collection.status = "create";
|
||||
} else if (status === "edit" && collection) {
|
||||
this.collection = { ...collection };
|
||||
this.collection.status = "edit";
|
||||
}
|
||||
document.getElementById("editModal").style.display = "block";
|
||||
},
|
||||
closeModal() {
|
||||
document.getElementById("editModal").style.display = "none";
|
||||
},
|
||||
getFilms(){
|
||||
axios.get(this.URL + "film")
|
||||
.then(response => {
|
||||
this.films = response.data;
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
||||
addCollectionFilm(id) {
|
||||
let filmId = document.getElementById('films').value;
|
||||
axios
|
||||
.post(this.URL + `collection/add_film/${id}?film_id=${filmId}`)
|
||||
.then(() => {
|
||||
this.closeModalForAdd();
|
||||
this.getCollections();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
delCollectionFilm(id) {
|
||||
let filmId = document.getElementById('films').value;
|
||||
axios
|
||||
.delete(this.URL + `collection/del_film/${id}?film_id=${filmId}`)
|
||||
.then(() => {
|
||||
this.closeModalForAdd();
|
||||
this.getCollections();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
itemsGenres(filmIds) {
|
||||
let result = [];
|
||||
if (typeof filmIds === 'undefined') {
|
||||
return;
|
||||
}
|
||||
this.films.forEach(film => {
|
||||
for (let i = 0; i < filmIds.length; i++) {
|
||||
if (film.id === filmIds[i]) {
|
||||
result.push(film);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="container mt-4">
|
||||
<h1 class="text-center text-danger mb-4">Коллекции</h1>
|
||||
<button class="btn btn-success mr-2" @click="openModal('create')">Добавить</button>
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="col in collections" :key="col.id">
|
||||
<td>{{ col.name }}</td>
|
||||
<td>
|
||||
<td>
|
||||
<button class="btn btn-warning mr-2" @click="openModal('edit', col)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteCollection(col.id)">Удалить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-success mr-2" @click="openModalForAdd('edit', col);">Добавить фильмы</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--Форма для создания коллекций-->
|
||||
<div class="modal" tabindex="-1" id="editModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Коллекция</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="name">Название:</label>
|
||||
<input type="text" class="form-control" id="name" name="name" v-model="collection.name">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModal()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" v-if="collection.status === 'create'" @click="addCollection(collection)">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else @click="editCollection(collection)">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--Форма для привязки коллекции и фильма -->
|
||||
<div class="modal" tabindex="-1" id="openModalForAdd">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Добавление фильмов</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="name">Название:</label>
|
||||
<input readonly type="text" class="form-control" id="name" name="name" v-model="collection.name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name">Фильмы:</label>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" v-for="film in itemsGenres(this.collection.filmIds)" :key="film.id">
|
||||
<div>
|
||||
<label>{{ film.name }}</label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="mt-4">
|
||||
<label>Выберите фильм</label>
|
||||
<select class="form-select" id="films" required>
|
||||
<option v-for="film in this.films"
|
||||
:value="film.id">
|
||||
{{ film.name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mt-4">
|
||||
<button class="btn btn-success" type="button" id="addFilmButton"
|
||||
@click="addCollectionFilm(this.collection.id)">Добавить</button>
|
||||
<button class="btn btn-danger" type="button" id="delFilmButton"
|
||||
@click="delCollectionFilm(this.collection.id)">Удалить</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModalForAdd()">Закрыть</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
@ -1,217 +0,0 @@
|
||||
<script>
|
||||
import 'axios';
|
||||
import axios from "axios";
|
||||
import Film from "../models/Film";
|
||||
import Genre from "../models/Genre";
|
||||
export default {
|
||||
created() {
|
||||
this.getFilms();
|
||||
this.getGenres();
|
||||
},
|
||||
mounted() {
|
||||
const addModal = document.getElementById('editModal');
|
||||
addModal.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
const openModalForAdd = document.getElementById('openModalForAdd');
|
||||
openModalForAdd.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return{
|
||||
films: [],
|
||||
URL: "http://localhost:8080/",
|
||||
film: new Film(),
|
||||
genres: [],
|
||||
selectedGenres: [],
|
||||
open: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getFilms(){
|
||||
axios.get(this.URL + "film")
|
||||
.then(response => {
|
||||
this.films = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
addFilm(film){
|
||||
console.log(film);
|
||||
axios.post(this.URL + "film", film)
|
||||
.then(() => {
|
||||
this.getFilms();
|
||||
this.closeModal();
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
deleteFilm(id){
|
||||
axios.delete(this.URL + `film/${id}`)
|
||||
.then(() =>{
|
||||
this.getFilms();
|
||||
})
|
||||
},
|
||||
editFilm(film){
|
||||
axios.put(this.URL + `film/${film.id}`, film)
|
||||
.then(() =>{
|
||||
const index = this.films.findIndex((s) => s.id === film.id);
|
||||
if (index !== -1) {
|
||||
this.films[index] = { ...film };
|
||||
}
|
||||
this.closeModal();
|
||||
this.getFilms();
|
||||
})
|
||||
this.closeModal();
|
||||
},
|
||||
openModalForAdd(status, film = null) {
|
||||
if (status === "create") {
|
||||
this.film = new Film();
|
||||
this.film.status = "create";
|
||||
} else if (status === "edit" && film) {
|
||||
this.film = { ...film };
|
||||
this.film.status = "edit";
|
||||
}
|
||||
this.open = this.film.genreIds ? [...this.film.genreIds] : []; // Создаём новый массив, чтобы избежать проблем с ссылками
|
||||
this.loadSelectedGenres();
|
||||
document.getElementById("openModalForAdd").style.display = "block";
|
||||
},
|
||||
closeModalForAdd() {
|
||||
document.getElementById("openModalForAdd").style.display = "none";
|
||||
this.open = [...this.selectedGenres];
|
||||
this.selectedGenres = [];
|
||||
this.film = new Film();
|
||||
},
|
||||
openModal(status, film = null) {
|
||||
if (status === "create") {
|
||||
this.film = new Film();
|
||||
this.film.status = "create";
|
||||
} else if (status === "edit" && film) {
|
||||
this.film = { ...film };
|
||||
this.film.status = "edit";
|
||||
}
|
||||
document.getElementById("editModal").style.display = "block";
|
||||
},
|
||||
closeModal() {
|
||||
document.getElementById("editModal").style.display = "none";
|
||||
},
|
||||
getGenres(){
|
||||
axios.get(this.URL + "genre")
|
||||
.then(response => {
|
||||
this.genres = response.data;
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
saveSelectedGenres() {
|
||||
this.open = [...this.selectedGenres];
|
||||
},
|
||||
|
||||
loadSelectedGenres() {
|
||||
this.selectedGenres = [...this.open];
|
||||
},
|
||||
|
||||
addFilmGenre(id, list) {
|
||||
axios
|
||||
.post(this.URL + `film/add_genres/${id}`, list)
|
||||
.then(() => {
|
||||
this.closeModalForAdd();
|
||||
this.getFilms();
|
||||
this.open = [...this.selectedGenres];
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="container mt-4">
|
||||
<h1 class="text-center text-danger mb-4">Фильмы</h1>
|
||||
<button class="btn btn-success mr-2" @click="openModal('create')">Добавить</button>
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="flm in films" :key="flm.id">
|
||||
<td>{{ flm.name }}</td>
|
||||
<td>
|
||||
<td>
|
||||
<button class="btn btn-warning mr-2" @click="openModal('edit', flm)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteFilm(flm.id)">Удалить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-success mr-2" @click="openModalForAdd('edit', flm);">Добавить жанры</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--Форма для создания фильмов-->
|
||||
<div class="modal" tabindex="-1" id="editModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Фильм</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="name">Название:</label>
|
||||
<input type="text" class="form-control" id="name" name="name" v-model="film.name">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModal()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" v-if="film.status === 'create'" @click="addFilm(film)">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else @click="editFilm(film)">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--Форма для привязки фильма и жанра -->
|
||||
<div class="modal" tabindex="-1" id="openModalForAdd">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Добавление жанров</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="name">Название:</label>
|
||||
<input readonly type="text" class="form-control" id="name" name="name" v-model="film.name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name">Выберите жанры для добавления:</label>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" v-for="genre in genres" :key="genre.id">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" v-model="selectedGenres" :value="genre.id" v-bind:checked="open.includes(genre.id)" id="genreCheck{{ genre.id }}">
|
||||
<label class="form-check-label" for="genreCheck{{ genre.id }}">{{ genre.name }}</label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModalForAdd()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" @click="addFilmGenre(film.id, selectedGenres)">Добавить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
@ -1,132 +0,0 @@
|
||||
<script>
|
||||
import 'axios';
|
||||
import axios from 'axios';
|
||||
import Genre from "../models/Genre";
|
||||
|
||||
export default {
|
||||
created() {
|
||||
this.getGenres();
|
||||
},
|
||||
mounted() {
|
||||
const addModal = document.getElementById('editModal');
|
||||
addModal.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
genres: [],
|
||||
URL: "http://localhost:8080/",
|
||||
genre: new Genre(),
|
||||
editedGenre: new Genre()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getGenres(){
|
||||
axios.get(this.URL + "genre")
|
||||
.then(response => {
|
||||
this.genres = response.data;
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
addGenre(genre) {
|
||||
console.log(genre);
|
||||
axios
|
||||
.post(this.URL + "genre", genre)
|
||||
.then(() => {
|
||||
this.getGenres();
|
||||
this.closeModal();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
deleteGenre(id){
|
||||
axios.delete(this.URL + `genre/${id}`)
|
||||
.then(() =>{
|
||||
this.getGenres();
|
||||
})
|
||||
},
|
||||
openModal(status, genre = null) {
|
||||
if (status === "create") {
|
||||
this.editedGenre = new Genre();
|
||||
this.editedGenre.status = "create";
|
||||
} else if (status === "edit" && genre) {
|
||||
this.editedGenre = { ...genre };
|
||||
this.editedGenre.status = "edit";
|
||||
}
|
||||
|
||||
document.getElementById("editModal").style.display = "block";
|
||||
},
|
||||
closeModal() {
|
||||
document.getElementById("editModal").style.display = "none";
|
||||
},
|
||||
editGenre(genre) {
|
||||
axios.put(this.URL + `genre/${genre.id}`, genre)
|
||||
.then(() => {
|
||||
const index = this.genres.findIndex((s) => s.id === genre.id);
|
||||
if (index !== -1) {
|
||||
this.genres[index] = { ...genre };
|
||||
}
|
||||
this.closeModal();
|
||||
this.getGenres();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="container mt-4">
|
||||
<h1 class="text-center text-danger mb-4">Жанры</h1>
|
||||
<button class="btn btn-success mr-2" @click="openModal('create')">Добавить</button>
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="gen in genres" :key="gen.id">
|
||||
<td>{{ gen.name }}</td>
|
||||
<td>
|
||||
<td>
|
||||
<button class="btn btn-warning mr-2" @click="openModal('edit', gen)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteGenre(gen.id)">Удалить</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal" tabindex="-1" id="editModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Жанр</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="name">Название:</label>
|
||||
<input type="text" class="form-control" id="name" name="name" v-model="editedGenre.name">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModal()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" v-if="editedGenre.status === 'create'" @click="addGenre(editedGenre)">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else @click="editGenre(editedGenre)">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
@ -1,23 +0,0 @@
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
catalogs: [
|
||||
{ name: 'genres', label: 'Жанры' },
|
||||
{ name: 'films', label: 'Фильмы' },
|
||||
{ name: 'collections', label: 'Коллекции' }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="list-group">
|
||||
<router-link v-for="catalog in this.catalogs"
|
||||
:to="'/catalogs/' + catalog.name"
|
||||
class="list-group-item list-group-item-action">
|
||||
{{ catalog.label }}
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
@ -1,70 +0,0 @@
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
headers: Array,
|
||||
items: Array,
|
||||
selectedItems: Array
|
||||
},
|
||||
emits: {
|
||||
dblclick: null
|
||||
},
|
||||
methods: {
|
||||
rowClick(id) {
|
||||
if (this.isSelected(id)) {
|
||||
var index = this.selectedItems.indexOf(id);
|
||||
if (index !== -1) {
|
||||
this.selectedItems.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
this.selectedItems.push(id);
|
||||
}
|
||||
},
|
||||
rowDblClick(id) {
|
||||
this.$emit('dblclick', id);
|
||||
},
|
||||
isSelected(id) {
|
||||
return this.selectedItems.includes(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th v-for="header in this.headers"
|
||||
:id="header.name"
|
||||
scope="col">{{ header.label }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in this.items"
|
||||
@click="rowClick(item.id)"
|
||||
@dblclick="rowDblClick(item.id)"
|
||||
:class="{selected: isSelected(item.id)}">
|
||||
<th scope="row">{{ index + 1 }}</th>
|
||||
<td v-for="header in this.headers">
|
||||
{{ item[header.name] }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
tbody tr:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
tr.selected {
|
||||
background-color: #07fa44;
|
||||
opacity: 80%;
|
||||
}
|
||||
tbody tr {
|
||||
user-select: none;
|
||||
}
|
||||
*{
|
||||
color: orange;
|
||||
}
|
||||
</style>
|
@ -1,20 +0,0 @@
|
||||
<template>
|
||||
<footer class="d-flex justify-content-center justify-content-lg-around p-3 bg-success">
|
||||
<span class="logo text-danger bg-white">VF</span>
|
||||
<span class="text-white mt-4">более 10 лет только лучшие фильмы</span>
|
||||
<span class="text-white mt-4">Почта для отзывов и предложений: videofilms@mail.ru</span>
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logo{
|
||||
font-size: 64px;
|
||||
line-height: 76px;
|
||||
}
|
||||
footer{
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
margin: 0 !important;
|
||||
}
|
||||
</style>
|
@ -1,37 +0,0 @@
|
||||
<template>
|
||||
<header>
|
||||
<nav class="navbar navbar-dark navbar-expand-lg bg-black">
|
||||
<div class="container-fluid">
|
||||
<router-link to="/index" class="navbar-brand"><img src="/src/images/name.png" alt="name"></router-link>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Переключатель навигации">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<router-link to="/index" class="nav-link">Главная</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link to="/catalogs/genres" class="nav-link">Жанры</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link to="/catalogs/films" class="nav-link">Фильмы</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link to="/catalogs/collections" class="nav-link">Коллекции</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link to="/report" class="nav-link">Отчет</router-link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
header{
|
||||
font-size: 28px;
|
||||
}
|
||||
</style>
|
@ -1,57 +0,0 @@
|
||||
<script>
|
||||
export default{
|
||||
data(){
|
||||
return{
|
||||
images: [
|
||||
{image: "/src/images/banner1.jpg"},
|
||||
{image: "/src/images/banner2.jpg"},
|
||||
{image: "/src/images/banner3.jpg"}
|
||||
],
|
||||
count: 0,
|
||||
banner: "/src/images/banner1.jpg"
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
change(){
|
||||
this.banner = this.images[this.count].image;
|
||||
if(this.count == this.images.length-1) this.count = 0;
|
||||
else this.count++;
|
||||
setTimeout(this.change, 3000);
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
this.change();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="first_page">
|
||||
<div id="banner">
|
||||
<img :src = banner />
|
||||
</div>
|
||||
<div class="mock"></div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.first_page{
|
||||
background-image: url(/src/images/Фон1.jpg);
|
||||
min-height: 100vh;
|
||||
width: 100%;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
#banner {
|
||||
margin: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
min-height: 700px;
|
||||
}
|
||||
#banner img {
|
||||
border-radius: 5px;
|
||||
height: 700px;
|
||||
min-width: 300px;
|
||||
}
|
||||
</style>
|
@ -1,76 +0,0 @@
|
||||
<script>
|
||||
import 'axios';
|
||||
import axios from "axios";
|
||||
import Film from "../models/Film";
|
||||
import Genre from "../models/Genre";
|
||||
|
||||
export default{
|
||||
created() {
|
||||
this.getFilms();
|
||||
this.getGenres();
|
||||
},
|
||||
data() {
|
||||
return{
|
||||
films: [],
|
||||
URL: "http://localhost:8080/",
|
||||
genres: [],
|
||||
genreId: undefined
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getFilms(){
|
||||
axios.get(this.URL + "film")
|
||||
.then(response => {
|
||||
this.films = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
getGenres(){
|
||||
axios.get(this.URL + "genre")
|
||||
.then(response => {
|
||||
this.genres = response.data;
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
filter() {
|
||||
let genreId = document.getElementById('genreFilterSelect').value;
|
||||
axios.get(this.URL + `genre/film/${genreId}`)
|
||||
.then(response => {
|
||||
this.films = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="mt-4">
|
||||
<h2 class="text-danger">Выберите жанр для отчета</h2>
|
||||
<select class="form-select" id="genreFilterSelect" required>
|
||||
<option v-for="genre in this.genres" :value="genre.id">{{ genre.name }}</option>
|
||||
</select>
|
||||
<button class="btn btn-success" type="button" id="report-button"
|
||||
@click.prevent="filter">Сформировать</button>
|
||||
<button class="btn btn-danger" type="button" id="report-button"
|
||||
@click.prevent="getFilms">Очистить</button>
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="flm in films" :key="flm.id">
|
||||
<td>{{ flm.name }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
Binary file not shown.
Before Width: | Height: | Size: 71 KiB |
Binary file not shown.
Before Width: | Height: | Size: 152 KiB |
Binary file not shown.
Before Width: | Height: | Size: 123 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 77 KiB |
@ -1,25 +0,0 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import App from './App.vue'
|
||||
import Index from './components/Index.vue'
|
||||
import CatalogGenres from './components/CatalogGenres.vue'
|
||||
import CatalogFilms from './components/CatalogFilms.vue'
|
||||
import CatalogCollections from './components/CatalogCollections.vue'
|
||||
import Report from './components/Report.vue'
|
||||
|
||||
const routes = [
|
||||
{ path: '/', redirect: '/index' },
|
||||
{ path: '/index', component: Index},
|
||||
{ path: '/catalogs/genres', component: CatalogGenres},
|
||||
{ path: '/catalogs/films', component: CatalogFilms},
|
||||
{ path: '/catalogs/collections', component: CatalogCollections},
|
||||
{ path: '/report', component: Report}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
linkActiveClass: 'active',
|
||||
routes
|
||||
})
|
||||
|
||||
createApp(App).use(router).mount('#app')
|
@ -1,7 +0,0 @@
|
||||
export default class Collection {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
this.filmIds = data?.filmIds;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export default class Film {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
this.genreIds = data?.genreIds;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
export default class Genre {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), vueJsx()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
}
|
||||
})
|
@ -14,14 +14,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Collection;
|
||||
|
||||
public interface ICollectionRepository extends JpaRepository<Collection, Long> {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IFilmRepository extends JpaRepository<Film, Long> {
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IGenreRepository extends JpaRepository<Genre, Long> {
|
||||
@Query("SELECT DISTINCT f FROM Film f where :filmsGenres MEMBER OF f.genres")
|
||||
List<Film> findFilmsOnGenre(@Param("filmsGenres") Genre genre);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.CollectionService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/collection")
|
||||
public class CollectionController {
|
||||
private final CollectionService collectionService;
|
||||
|
||||
public CollectionController(CollectionService collectionService) {
|
||||
this.collectionService = collectionService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public CollectionDTO getCollection(@PathVariable Long id) {
|
||||
return new CollectionDTO(collectionService.findCollection(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<CollectionDTO> getCollection() {
|
||||
return collectionService.findAllCollections().stream().map(CollectionDTO::new).toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public CollectionDTO createCollection(@RequestBody @Valid CollectionDTO collectionDTO) {
|
||||
return new CollectionDTO(collectionService.addCollection(collectionDTO.getName()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public CollectionDTO updateCollection(@PathVariable Long id, @RequestBody @Valid CollectionDTO collectionDTO) {
|
||||
return new CollectionDTO(collectionService.updateCollection(id, collectionDTO.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public CollectionDTO deleteCollection(@PathVariable Long id) {
|
||||
return new CollectionDTO(collectionService.deleteCollection(id));
|
||||
}
|
||||
@DeleteMapping
|
||||
public void deleteAllCollections(){
|
||||
collectionService.deleteAllCollections();
|
||||
}
|
||||
|
||||
@PostMapping("/add_film/{id}")
|
||||
public CollectionDTO addFilm(@PathVariable Long id, @RequestParam Long film_id) {
|
||||
return new CollectionDTO(collectionService.addFilm(id, film_id));
|
||||
}
|
||||
|
||||
@DeleteMapping("/del_film/{id}")
|
||||
public CollectionDTO delFilm(@PathVariable Long id, @RequestParam Long film_id) {
|
||||
return new CollectionDTO(collectionService.deleteFilm(id, film_id));
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Collection;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private List<Long> filmIds;
|
||||
public CollectionDTO() {
|
||||
}
|
||||
public CollectionDTO(Collection collection){
|
||||
this.id = collection.getId();
|
||||
this.name = collection.getName();
|
||||
if(collection.getFilms() != null) {
|
||||
this.filmIds = collection.getFilms().stream().map(Film::getId).toList();
|
||||
}
|
||||
}
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public List<Long> getFilmIds(){
|
||||
return filmIds;
|
||||
}
|
||||
public void setId(long id){ this.id = id; }
|
||||
public void setName(String name){ this.name = name; }
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/film")
|
||||
public class FilmController {
|
||||
private final FilmService filmService;
|
||||
|
||||
public FilmController(FilmService filmService) {
|
||||
this.filmService = filmService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public FilmDTO getFilm(@PathVariable Long id) {
|
||||
return new FilmDTO(filmService.findFilm(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<FilmDTO> getFilm() {
|
||||
return filmService.findAllFilms().stream().map(FilmDTO::new).toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public FilmDTO createFilm(@RequestBody @Valid FilmDTO filmDTO) {
|
||||
return new FilmDTO(filmService.addFilm(filmDTO.getName()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public FilmDTO updateFilm(@PathVariable Long id, @RequestBody @Valid FilmDTO filmDTO) {
|
||||
return new FilmDTO(filmService.updateFilm(id, filmDTO.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public FilmDTO deleteFilm(@PathVariable Long id) {
|
||||
return new FilmDTO(filmService.deleteFilm(id));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public void deleteAllFilms(){
|
||||
filmService.deleteAllFilms();
|
||||
}
|
||||
|
||||
@PostMapping("/add_genres/{id}")
|
||||
public FilmDTO addGenres(@PathVariable Long id, @RequestBody @Valid List<Long> genreIds) {
|
||||
return new FilmDTO(filmService.addGenres(id, genreIds));
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FilmDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private List<Long> genreIds;
|
||||
public FilmDTO() {
|
||||
}
|
||||
public FilmDTO(Film film){
|
||||
this.id = film.getId();
|
||||
this.name = film.getName();
|
||||
if(film.getGenres() != null) {
|
||||
this.genreIds = film.getGenres().stream().map(Genre::getId).toList();
|
||||
}
|
||||
}
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public List<Long> getGenreIds(){
|
||||
return genreIds;
|
||||
}
|
||||
public void setId(long id){ this.id = id; }
|
||||
public void setName(String name){ this.name = name; }
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/genre")
|
||||
public class GenreController {
|
||||
private final GenreService genreService;
|
||||
|
||||
public GenreController(GenreService genreService) {
|
||||
this.genreService = genreService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public GenreDTO getGenre(@PathVariable Long id) {
|
||||
return new GenreDTO(genreService.findGenre(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<GenreDTO> getGenre() {
|
||||
return genreService.findAllGenres().stream().map(GenreDTO::new).toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public GenreDTO createGenre(@RequestBody @Valid GenreDTO genreDTO) {
|
||||
return new GenreDTO(genreService.addGenre(genreDTO.getName()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public GenreDTO updateGenre(@PathVariable Long id, @RequestBody @Valid GenreDTO genreDTO) {
|
||||
return new GenreDTO(genreService.updateGenre(id, genreDTO.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public GenreDTO deleteGenre(@PathVariable Long id) {
|
||||
return new GenreDTO(genreService.deleteGenre(id));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public void deleteAllGenres(){
|
||||
genreService.deleteAllGenres();
|
||||
}
|
||||
|
||||
@GetMapping("/film/{id}")
|
||||
public List<FilmDTO> findFilmOnGenre(@PathVariable Long id){
|
||||
return genreService.findFilmOnGenre(id)
|
||||
.stream()
|
||||
.map(FilmDTO::new)
|
||||
.toList();
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
|
||||
public class GenreDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
public GenreDTO() {
|
||||
}
|
||||
public GenreDTO(Genre genre){
|
||||
this.id = genre.getId();
|
||||
this.name = genre.getName();
|
||||
}
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public void setId(long id){ this.id = id; }
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Collection {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@NotBlank(message = "Name can't be null")
|
||||
private String name;
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name="collections_films",
|
||||
joinColumns = @JoinColumn(name="collection_id"),
|
||||
inverseJoinColumns = @JoinColumn(name="film_id")
|
||||
)
|
||||
private List<Film> films;
|
||||
|
||||
public Collection() {
|
||||
}
|
||||
|
||||
public Collection(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addFilm(Film film) {
|
||||
if (films == null){
|
||||
films = new ArrayList<>();
|
||||
}
|
||||
if (!this.films.contains(film)) {
|
||||
this.films.add(film);
|
||||
film.addCollection(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeFilm(Film film){
|
||||
if(films != null){
|
||||
films.remove(film);
|
||||
film.removeCollection(this);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Film> getFilms() {
|
||||
return films;
|
||||
}
|
||||
|
||||
public void setFilms(List<Film> films) {
|
||||
this.films = films;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Collection collection = (Collection) o;
|
||||
return Objects.equals(id, collection.id);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Collection{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
"films:" + (films == null ? "[]" : films.toString()) +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Film {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@NotBlank(message = "Name can't be null")
|
||||
private String name;
|
||||
@ManyToMany
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@JoinTable(name="films_genres",
|
||||
joinColumns = @JoinColumn(name="film_id"),
|
||||
inverseJoinColumns = @JoinColumn(name="genre_id")
|
||||
)
|
||||
private List<Genre> genres;
|
||||
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "films")
|
||||
private List<Collection> collections;
|
||||
|
||||
public Film() {
|
||||
}
|
||||
|
||||
public Film(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addGenre(Genre genre) {
|
||||
if (genres == null){
|
||||
genres = new ArrayList<>();
|
||||
}
|
||||
if (!this.genres.contains(genre))
|
||||
this.genres.add(genre);
|
||||
}
|
||||
|
||||
public void removeGenre(Genre genre){
|
||||
if(genres != null){
|
||||
genres.remove(genre);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeGenres(){
|
||||
genres = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCollection(Collection collection) {
|
||||
if(this.collections==null)
|
||||
collections=new ArrayList<>();
|
||||
if (!this.genres.contains(collection))
|
||||
this.collections.add(collection);
|
||||
}
|
||||
|
||||
public void removeCollection(Collection collection){
|
||||
if(collections != null){
|
||||
collections.remove(collection);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Genre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
public void setGenres(List<Genre> genres) {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public List<Collection> getCollections() {
|
||||
return collections;
|
||||
}
|
||||
public void setCollections(List<Collection> collections) {
|
||||
this.collections = collections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Film film = (Film) o;
|
||||
return Objects.equals(id, film.id);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Film{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
"genres:" + (genres == null ? "[]" : genres.toString()) +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Genre {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@NotBlank(message = "Name can't be null")
|
||||
private String name;
|
||||
|
||||
public Genre() {
|
||||
}
|
||||
|
||||
public Genre(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Genre genre = (Genre) o;
|
||||
return Objects.equals(id, genre.id);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Genre{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
public class CollectionNotFoundException extends RuntimeException {
|
||||
public CollectionNotFoundException(Long id) {
|
||||
super(String.format("Collection with id [%s] is not found", id));
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Collection;
|
||||
import ru.ulstu.is.lab1.DataBase.Repository.ICollectionRepository;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidatorUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CollectionService {
|
||||
private final ICollectionRepository collectionRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
private final FilmService filmService;
|
||||
|
||||
public CollectionService(ICollectionRepository collectionRepository, ValidatorUtil validatorUtil, FilmService filmService){
|
||||
this.collectionRepository = collectionRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
this.filmService = filmService;
|
||||
}
|
||||
@Transactional
|
||||
public Collection addCollection(String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Collection name is null or empty");
|
||||
}
|
||||
final Collection collection = new Collection(name);
|
||||
validatorUtil.validate(collection);
|
||||
return collectionRepository.save(collection);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Collection findCollection(Long id) {
|
||||
final Optional<Collection> collection = collectionRepository.findById(id);
|
||||
return collection.orElseThrow(() -> new CollectionNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Collection> findAllCollections() {
|
||||
return collectionRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Collection updateCollection(Long id, String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Collection name is null or empty");
|
||||
}
|
||||
final Collection currentCollection = findCollection(id);
|
||||
currentCollection.setName(name);
|
||||
validatorUtil.validate(currentCollection);
|
||||
return collectionRepository.save(currentCollection);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Collection deleteCollection(Long id) {
|
||||
final Collection currentCollection = findCollection(id);
|
||||
collectionRepository.delete(currentCollection);
|
||||
return currentCollection;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllCollections() {
|
||||
collectionRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Collection addFilm(Long collectionId, Long filmId) {
|
||||
Collection collection = findCollection(collectionId);
|
||||
if (collection == null) {
|
||||
throw new EntityNotFoundException(String.format("Collection with id [%s] is not found", collectionId));
|
||||
}
|
||||
final Film film = filmService.findFilm(filmId);
|
||||
if (film == null) {
|
||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||
}
|
||||
|
||||
collection.addFilm(film);
|
||||
return collectionRepository.save(collection);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Collection deleteFilm(Long collectionId, Long filmId) {
|
||||
Collection collection = findCollection(collectionId);
|
||||
if (collection == null) {
|
||||
throw new EntityNotFoundException(String.format("Collection with id [%s] is not found", collectionId));
|
||||
}
|
||||
final Film film = filmService.findFilm(filmId);
|
||||
if (film == null) {
|
||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||
}
|
||||
|
||||
collection.removeFilm(film);
|
||||
return collectionRepository.save(collection);
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
public class FilmNotFoundException extends RuntimeException {
|
||||
public FilmNotFoundException(Long id) {
|
||||
super(String.format("Film with id [%s] is not found", id));
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.Repository.IFilmRepository;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidatorUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class FilmService {
|
||||
private final IFilmRepository filmRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
private final GenreService genreService;
|
||||
|
||||
public FilmService(IFilmRepository filmRepository, ValidatorUtil validatorUtil, GenreService genreService){
|
||||
this.filmRepository = filmRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
this.genreService = genreService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film addFilm(String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Film name is null or empty");
|
||||
}
|
||||
final Film film = new Film(name);
|
||||
validatorUtil.validate(film);
|
||||
return filmRepository.save(film);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Film findFilm(Long id) {
|
||||
final Optional<Film> film = filmRepository.findById(id);
|
||||
return film.orElseThrow(() -> new FilmNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Film> findAllFilms() {
|
||||
return filmRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film updateFilm(Long id, String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Film name is null or empty");
|
||||
}
|
||||
final Film currentFilm = findFilm(id);
|
||||
currentFilm.setName(name);
|
||||
validatorUtil.validate(currentFilm);
|
||||
return filmRepository.save(currentFilm);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film deleteFilm(Long id) {
|
||||
final Film currentFilm = findFilm(id);
|
||||
filmRepository.delete(currentFilm);
|
||||
return currentFilm;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllFilms() {
|
||||
filmRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film addGenres(Long filmId, List<Long> genreIds) {
|
||||
Film film = findFilm(filmId);
|
||||
if (film == null) {
|
||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||
}
|
||||
film.removeGenres();
|
||||
for(Long genreId : genreIds) {
|
||||
final Genre genre = genreService.findGenre(genreId);
|
||||
film.addGenre(genre);
|
||||
}
|
||||
return filmRepository.save(film);
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
public class GenreNotFoundException extends RuntimeException {
|
||||
public GenreNotFoundException(Long id) {
|
||||
super(String.format("Genre with id [%s] is not found", id));
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.DataBase.Repository.IGenreRepository;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidatorUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class GenreService {
|
||||
private final IGenreRepository genreRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
public GenreService(IGenreRepository genreRepository, ValidatorUtil validatorUtil){
|
||||
this.genreRepository = genreRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Genre addGenre(String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Genre name is null or empty");
|
||||
}
|
||||
final Genre genre = new Genre(name);
|
||||
validatorUtil.validate(genre);
|
||||
return genreRepository.save(genre);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Genre findGenre(Long id) {
|
||||
final Optional<Genre> genre = genreRepository.findById(id);
|
||||
return genre.orElseThrow(() -> new GenreNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Genre> findAllGenres() {
|
||||
return genreRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Genre updateGenre(Long id, String name) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new IllegalArgumentException("Genre name is null or empty");
|
||||
}
|
||||
final Genre currentGenre = findGenre(id);
|
||||
currentGenre.setName(name);
|
||||
validatorUtil.validate(currentGenre);
|
||||
return genreRepository.save(currentGenre);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Genre deleteGenre(Long id) {
|
||||
final Genre currentGenre = findGenre(id);
|
||||
genreRepository.delete(currentGenre);
|
||||
return currentGenre;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllGenres() {
|
||||
genreRepository.deleteAll();
|
||||
}
|
||||
@Transactional
|
||||
public List<Film> findFilmOnGenre(Long id){
|
||||
return genreRepository.findFilmsOnGenre(findGenre(id));
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ package ru.ulstu.is.lab1;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@ -11,4 +13,8 @@ public class Lab1 {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Lab1.class, args);
|
||||
}
|
||||
@GetMapping("/hello")
|
||||
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
|
||||
return String.format("Hello %s!", name);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
class WebConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry){
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package ru.ulstu.is.lab1.util.error;
|
||||
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreNotFoundException;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmNotFoundException;
|
||||
import ru.ulstu.is.lab1.DataBase.service.CollectionNotFoundException;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidationException;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ControllerAdvice
|
||||
public class AdviceController {
|
||||
@ExceptionHandler({
|
||||
GenreNotFoundException.class,
|
||||
FilmNotFoundException.class,
|
||||
CollectionNotFoundException.class,
|
||||
ValidationException.class
|
||||
})
|
||||
public ResponseEntity<Object> handleException(Throwable e) {
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
|
||||
final ValidationException validationException = new ValidationException(
|
||||
e.getBindingResult().getAllErrors().stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||
.collect(Collectors.toSet()));
|
||||
return handleException(validationException);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<Object> handleUnknownException(Throwable e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package ru.ulstu.is.lab1.util.validation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ValidationException extends RuntimeException{
|
||||
public ValidationException(Set<String> errors) {
|
||||
super(String.join("\n", errors));
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package ru.ulstu.is.lab1.util.validation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ValidatorUtil{
|
||||
private final Validator validator;
|
||||
|
||||
public ValidatorUtil() {
|
||||
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
|
||||
this.validator = factory.getValidator();
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void validate(T object) {
|
||||
final Set<ConstraintViolation<T>> errors = validator.validate(object);
|
||||
if (!errors.isEmpty()) {
|
||||
throw new ValidationException(errors.stream()
|
||||
.map(ConstraintViolation::getMessage)
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
spring.main.banner-mode=off
|
||||
#server.port=8080
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
@ -1,80 +0,0 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Collection;
|
||||
import ru.ulstu.is.lab1.DataBase.service.CollectionService;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaCollectionTests {
|
||||
/*private static final Logger log = LoggerFactory.getLogger(JpaFilmTests.class);
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
@Test
|
||||
void testCollectionsCreate(){
|
||||
collectionService.deleteAllCollections();
|
||||
filmService.deleteAllFilms();
|
||||
final Film film1 = filmService.addFilm("Джокер");
|
||||
final Film film2 = filmService.addFilm("Учитель на замену");
|
||||
Collection collection1 = collectionService.addCollection("Грустное");
|
||||
collection1 = collectionService.addFilm(collection1.getId(), film1.getId());
|
||||
collection1 = collectionService.addFilm(collection1.getId(), film2.getId());
|
||||
Collection collection2 = collectionService.addCollection("Об антигерое");
|
||||
collection2 = collectionService.addFilm(collection2.getId(), film1.getId());
|
||||
log.info("testCreateCollection " + collection1.toString());
|
||||
log.info("testCreateCollection " + collection2.toString());
|
||||
Assertions.assertNotNull(collection1.getId());
|
||||
Assertions.assertNotNull(collection2.getId());
|
||||
}
|
||||
@Test
|
||||
void testCollectionRead() {
|
||||
collectionService.deleteAllCollections();
|
||||
filmService.deleteAllFilms();
|
||||
final Film film = filmService.addFilm("Астрал");
|
||||
Collection collection = collectionService.addCollection("Пугающее");
|
||||
collection = collectionService.addFilm(collection.getId(), film.getId());
|
||||
log.info("testCollectionRead[0]: " + collection.toString());
|
||||
final Collection findCollection = collectionService.findCollection(collection.getId());
|
||||
log.info("testCollectionRead[1]: " + findCollection.toString());
|
||||
Assertions.assertEquals(collection, findCollection);
|
||||
}
|
||||
@Test
|
||||
void testAddFilms(){
|
||||
collectionService.deleteAllCollections();
|
||||
filmService.deleteAllFilms();
|
||||
final Film film1 = filmService.addFilm("Начало");
|
||||
final Film film2 = filmService.addFilm("Пункт назначения");
|
||||
final Film film3 = filmService.addFilm("День сурка");
|
||||
Collection collection = collectionService.addCollection("Избранное");
|
||||
collection = collectionService.addFilm(collection.getId(), film1.getId());
|
||||
collection = collectionService.addFilm(collection.getId(), film2.getId());
|
||||
collection = collectionService.addFilm(collection.getId(), film3.getId());
|
||||
log.info("testAddFilms[0]: " + collection.toString());
|
||||
Assertions.assertEquals(collection.getFilms().size(), 3);
|
||||
}
|
||||
@Test
|
||||
void testCollectionReadNotFound() {
|
||||
collectionService.deleteAllCollections();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> collectionService.findCollection(-1L));
|
||||
}
|
||||
@Test
|
||||
void testCollectionsReadAllEmpty() {
|
||||
collectionService.deleteAllCollections();
|
||||
final List<Collection> collections = collectionService.findAllCollections();
|
||||
log.info("testCollectionReadAllEmpty: " + collections.toString());
|
||||
Assertions.assertEquals(collections.size(), 0);
|
||||
}*/
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaFilmTests {
|
||||
/*private static final Logger log = LoggerFactory.getLogger(JpaFilmTests.class);
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
@Autowired
|
||||
private GenreService genreService;
|
||||
@Test
|
||||
void testFilmsCreate(){
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Фантастика");
|
||||
final Genre genre2 = genreService.addGenre("Комедия");
|
||||
Film film1 = filmService.addFilm("Сапожник");
|
||||
film1 = filmService.addGenre(film1.getId(), genre1.getId());
|
||||
film1 = filmService.addGenre(film1.getId(), genre2.getId());
|
||||
Film film2 = filmService.addFilm("Маска");
|
||||
film2 = filmService.addGenre(film2.getId(), genre1.getId());
|
||||
log.info("testCreateFilm " + film1.toString());
|
||||
log.info("testCreateFilm " + film2.toString());
|
||||
Assertions.assertNotNull(film1.getId());
|
||||
Assertions.assertNotNull(film2.getId());
|
||||
}
|
||||
@Test
|
||||
void testFilmRead() {
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre = genreService.addGenre("Ужасы");
|
||||
Film film = filmService.addFilm("Оно");
|
||||
film = filmService.addGenre(film.getId(), genre.getId());
|
||||
log.info("testFilmRead[0]: " + film.toString());
|
||||
final Film findFilm = filmService.findFilm(film.getId());
|
||||
log.info("testFilmRead[1]: " + findFilm.toString());
|
||||
Assertions.assertEquals(film, findFilm);
|
||||
}
|
||||
@Test
|
||||
void testAddGenres(){
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Драма");
|
||||
final Genre genre2 = genreService.addGenre("Триллер");
|
||||
final Genre genre3 = genreService.addGenre("Боевик");
|
||||
Film film = filmService.addFilm("Брат");
|
||||
film = filmService.addGenre(film.getId(), genre1.getId());
|
||||
film = filmService.addGenre(film.getId(), genre2.getId());
|
||||
film = filmService.addGenre(film.getId(), genre3.getId());
|
||||
log.info("testAddGenres[0]: " + film.toString());
|
||||
Assertions.assertEquals(film.getGenres().size(), 3);
|
||||
}
|
||||
@Test
|
||||
void testFilmReadNotFound() {
|
||||
filmService.deleteAllFilms();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> filmService.findFilm(-1L));
|
||||
}
|
||||
@Test
|
||||
void testFilmsReadAllEmpty() {
|
||||
filmService.deleteAllFilms();
|
||||
final List<Film> films = filmService.findAllFilms();
|
||||
log.info("testFilmReadAllEmpty: " + films.toString());
|
||||
Assertions.assertEquals(films.size(), 0);
|
||||
}
|
||||
@Test
|
||||
void testSelect() {
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Драма");
|
||||
final Genre genre2 = genreService.addGenre("Триллер");
|
||||
final Genre genre3 = genreService.addGenre("Боевик");
|
||||
Film film = filmService.addFilm("Брат");
|
||||
Film film2 = filmService.addFilm("Маска");
|
||||
film = filmService.addGenre(film.getId(), genre1.getId());
|
||||
film = filmService.addGenre(film.getId(), genre2.getId());
|
||||
film = filmService.addGenre(film.getId(), genre3.getId());
|
||||
film2 = filmService.addGenre(film2.getId(), genre1.getId());
|
||||
List<Film> list = filmService.findFilmOnGenre(genre1);
|
||||
log.info("findFilmOnGenre: " + list.toString());
|
||||
Assertions.assertEquals(list.size(), 2);
|
||||
}*/
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class JpaGenreTests {
|
||||
/*private static final Logger log = LoggerFactory.getLogger(JpaGenreTests.class);
|
||||
@Autowired
|
||||
private GenreService genreService;
|
||||
@Test
|
||||
void testGenresCreate(){
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Фантастика");
|
||||
final Genre genre2 = genreService.addGenre("Комедия");
|
||||
log.info("testCreateGenre " + genre1.toString());
|
||||
log.info("testCreateGenre " + genre2.toString());
|
||||
Assertions.assertNotNull(genre1.getId());
|
||||
Assertions.assertNotNull(genre2.getId());
|
||||
}
|
||||
@Test
|
||||
void testGenreRead() {
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre = genreService.addGenre("Ужасы");
|
||||
log.info("testGenreRead[0]: " + genre.toString());
|
||||
final Genre findGenre = genreService.findGenre(genre.getId());
|
||||
log.info("testGenreRead[1]: " + findGenre.toString());
|
||||
Assertions.assertEquals(genre, findGenre);
|
||||
}
|
||||
@Test
|
||||
void testGenreReadNotFound() {
|
||||
genreService.deleteAllGenres();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> genreService.findGenre(-1L));
|
||||
}
|
||||
@Test
|
||||
void testGenreReadAll() {
|
||||
genreService.deleteAllGenres();
|
||||
genreService.addGenre("Драма");
|
||||
genreService.addGenre("Триллер");
|
||||
final List<Genre> genres = genreService.findAllGenres();
|
||||
log.info("testGenreReadAll: " + genres.toString());
|
||||
Assertions.assertEquals(genres.size(), 2);
|
||||
genreService.deleteAllGenres();
|
||||
}
|
||||
@Test
|
||||
void testGenreReadAllEmpty() {
|
||||
genreService.deleteAllGenres();
|
||||
final List<Genre> genres = genreService.findAllGenres();
|
||||
log.info("testGenreReadAllEmpty: " + genres.toString());
|
||||
Assertions.assertEquals(genres.size(), 0);
|
||||
}*/
|
||||
}
|
13
src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java
Normal file
13
src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java
Normal file
@ -0,0 +1,13 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Lab1ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
spring.datasource.url=jdbc:h2:mem:testdb
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
Loading…
Reference in New Issue
Block a user