Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c0eaf9e8fd | ||
|
dd1fdae060 | ||
|
157ba0f38b | ||
|
7512de70c2 | ||
|
4246c98078 | ||
|
22ae31f5c6 | ||
|
03a0ed7f5d | ||
|
9fb6531f82 | ||
|
57596deb85 | ||
|
72cc3edb7d | ||
|
1126696bb9 | ||
|
446e83c38e | ||
|
e1fe87f1fa | ||
|
c9132c20eb | ||
|
01d5b136ef | ||
|
04fea2fcc8 | ||
|
411eb34bab | ||
|
3d47fb12ef | ||
|
361d0a65ff | ||
|
b07faa67c5 | ||
|
1d1b1404b0 | ||
|
49b8125146 | ||
|
da683c642b | ||
|
8b69f68e7a | ||
|
da4a1da4b6 | ||
|
b159ec0dd7 | ||
|
fab6531bdd | ||
|
52373b5692 | ||
|
882ef19a8d | ||
|
78116eb994 | ||
|
3e57102a6d | ||
|
8baede6bca | ||
|
de105ade49 | ||
|
1880d0dc53 | ||
|
3ef4a530ee | ||
|
3df09259bd | ||
|
dfe84a7b21 | ||
|
46ecf5eac3 | ||
|
aac82d37ee | ||
|
84c206fb61 | ||
|
f68abec3fa |
28
Frontend/vue-project/.gitignore
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
# 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?
|
29
Frontend/vue-project/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# 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
|
||||
```
|
15
Frontend/vue-project/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!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
Normal file
26
Frontend/vue-project/package.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
BIN
Frontend/vue-project/public/favicon.ico
Normal file
After Width: | Height: | Size: 4.2 KiB |
34
Frontend/vue-project/src/App.vue
Normal file
@ -0,0 +1,34 @@
|
||||
<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>
|
243
Frontend/vue-project/src/components/CatalogCollections.vue
Normal file
@ -0,0 +1,243 @@
|
||||
<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>
|
217
Frontend/vue-project/src/components/CatalogFilms.vue
Normal file
@ -0,0 +1,217 @@
|
||||
<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>
|
132
Frontend/vue-project/src/components/CatalogGenres.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<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>
|
23
Frontend/vue-project/src/components/Catalogs.vue
Normal file
@ -0,0 +1,23 @@
|
||||
<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>
|
70
Frontend/vue-project/src/components/DataTable.vue
Normal file
@ -0,0 +1,70 @@
|
||||
<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>
|
20
Frontend/vue-project/src/components/Footer.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<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>
|
37
Frontend/vue-project/src/components/Header.vue
Normal file
@ -0,0 +1,37 @@
|
||||
<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>
|
57
Frontend/vue-project/src/components/Index.vue
Normal file
@ -0,0 +1,57 @@
|
||||
<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>
|
76
Frontend/vue-project/src/components/Report.vue
Normal file
@ -0,0 +1,76 @@
|
||||
<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>
|
BIN
Frontend/vue-project/src/images/banner1.jpg
Normal file
After Width: | Height: | Size: 71 KiB |
BIN
Frontend/vue-project/src/images/banner2.jpg
Normal file
After Width: | Height: | Size: 152 KiB |
BIN
Frontend/vue-project/src/images/banner3.jpg
Normal file
After Width: | Height: | Size: 123 KiB |
BIN
Frontend/vue-project/src/images/name.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
Frontend/vue-project/src/images/Фон1.jpg
Normal file
After Width: | Height: | Size: 77 KiB |
25
Frontend/vue-project/src/main.js
Normal file
@ -0,0 +1,25 @@
|
||||
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')
|
7
Frontend/vue-project/src/models/Collection.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default class Collection {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
this.filmIds = data?.filmIds;
|
||||
}
|
||||
}
|
7
Frontend/vue-project/src/models/Film.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default class Film {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
this.genreIds = data?.genreIds;
|
||||
}
|
||||
}
|
6
Frontend/vue-project/src/models/Genre.js
Normal file
@ -0,0 +1,6 @@
|
||||
export default class Genre {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.name = data?.name;
|
||||
}
|
||||
}
|
15
Frontend/vue-project/vite.config.js
Normal file
@ -0,0 +1,15 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
})
|
19
build.gradle
@ -14,6 +14,25 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
||||
|
||||
implementation 'org.webjars:bootstrap:5.1.3'
|
||||
implementation 'org.webjars:jquery:3.6.0'
|
||||
implementation 'org.webjars:font-awesome:6.1.0'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
|
||||
|
||||
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
Normal file
@ -0,0 +1,7 @@
|
||||
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> {
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
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> {
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package ru.ulstu.is.lab1.DataBase.Repository;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface IUserRepository extends JpaRepository<User, Long> {
|
||||
User findOneByLoginIgnoreCase(String login);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.CollectionService;
|
||||
import ru.ulstu.is.lab1.WebConfiguration;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(WebConfiguration.REST_API + "/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));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
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; }
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.CollectionService;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Film;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/collection")
|
||||
public class CollectionMvcController {
|
||||
private final CollectionService collectionService;
|
||||
private final FilmService filmService;
|
||||
|
||||
public CollectionMvcController(CollectionService collectionService, FilmService filmService)
|
||||
{
|
||||
this.collectionService = collectionService;
|
||||
this.filmService = filmService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getCollections(Model model) {
|
||||
model.addAttribute("collections",
|
||||
collectionService.findAllCollections().stream()
|
||||
.map(CollectionDTO::new)
|
||||
.toList());
|
||||
return "collection";
|
||||
}
|
||||
|
||||
@GetMapping("/films/{id}")
|
||||
public String getFilmsFromCollection(@PathVariable Long id, Model model) {
|
||||
List<Film> films = collectionService.getFilmsFromCollection(id);
|
||||
model.addAttribute("films", films);
|
||||
model.addAttribute("collectionId", id);
|
||||
return "view-films";
|
||||
}
|
||||
|
||||
@GetMapping("getFilms/{id}")
|
||||
public String getFilms(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("films",
|
||||
filmService.findAllFilms().stream()
|
||||
.map(FilmDTO::new)
|
||||
.toList());
|
||||
model.addAttribute("collectionId", id);
|
||||
return "add-film";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editCollection(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("collectionDTO", new CollectionDTO());
|
||||
} else {
|
||||
model.addAttribute("collectionId", id);
|
||||
model.addAttribute("collectionDTO", new CollectionDTO(collectionService.findCollection(id)));
|
||||
}
|
||||
return "collection-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveCollection(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid CollectionDTO collectionDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "collection-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
collectionService.addCollection(collectionDTO.getName());
|
||||
} else {
|
||||
collectionService.updateCollection(id, collectionDTO.getName());
|
||||
}
|
||||
return "redirect:/collection";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteCollection(@PathVariable Long id) {
|
||||
collectionService.deleteCollection(id);
|
||||
return "redirect:/collection";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/add_film/{id}")
|
||||
public String addFilm(@PathVariable(value = "id") Long id,
|
||||
@RequestParam("filmId") String filmId) {
|
||||
Long filmIdAsLong = Long.parseLong(filmId);
|
||||
collectionService.addFilm(id, filmIdAsLong);
|
||||
return "redirect:../films/{id}";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/del_film/{id}/{filmId}")
|
||||
public String deleteFilm(@PathVariable(value = "id") Long id,
|
||||
@PathVariable(value = "filmId") Long filmId) {
|
||||
collectionService.deleteFilm(id, filmId);
|
||||
return "redirect:/collection/films/{id}";
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
import ru.ulstu.is.lab1.WebConfiguration;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(WebConfiguration.REST_API + "/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));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
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; }
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
import ru.ulstu.is.lab1.DataBase.model.Genre;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/film")
|
||||
public class FilmMvcController {
|
||||
private final FilmService filmService;
|
||||
private final GenreService genreService;
|
||||
|
||||
public FilmMvcController(FilmService filmService, GenreService genreService)
|
||||
{
|
||||
this.filmService = filmService;
|
||||
this.genreService = genreService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getFilms(Model model) {
|
||||
model.addAttribute("films",
|
||||
filmService.findAllFilms().stream()
|
||||
.map(FilmDTO::new)
|
||||
.toList());
|
||||
return "film";
|
||||
}
|
||||
|
||||
@GetMapping("/genres/{id}")
|
||||
public String getGenresFromFilm(@PathVariable Long id, Model model) {
|
||||
List<Genre> genres = filmService.getGenresFromFilm(id);
|
||||
model.addAttribute("genres", genres);
|
||||
model.addAttribute("filmId", id);
|
||||
return "view-genres";
|
||||
}
|
||||
|
||||
@GetMapping("getGenres/{id}")
|
||||
public String getGenres(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("genres",
|
||||
genreService.findAllGenres().stream()
|
||||
.map(GenreDTO::new)
|
||||
.toList());
|
||||
model.addAttribute("filmId", id);
|
||||
return "add-genre";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editFilm(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("filmDTO", new FilmDTO());
|
||||
} else {
|
||||
model.addAttribute("filmId", id);
|
||||
model.addAttribute("filmDTO", new FilmDTO(filmService.findFilm(id)));
|
||||
}
|
||||
return "film-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveFilm(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid FilmDTO filmDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "film-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
filmService.addFilm(filmDTO.getName());
|
||||
} else {
|
||||
filmService.updateFilm(id, filmDTO.getName());
|
||||
}
|
||||
return "redirect:/film";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteFilm(@PathVariable Long id) {
|
||||
filmService.deleteFilm(id);
|
||||
return "redirect:/film";
|
||||
}
|
||||
|
||||
@PostMapping("/add_genres/{id}")
|
||||
public String addGenres(@PathVariable Long id,
|
||||
@RequestParam("genreId") List<String> genreIds){
|
||||
List<Long> genreIdsAsLong = genreIds.stream()
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
filmService.addGenres(id, genreIdsAsLong);
|
||||
return "redirect:../genres/{id}";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/del_genre/{id}/{genreId}")
|
||||
public String deleteFilm(@PathVariable(value = "id") Long id,
|
||||
@PathVariable(value = "genreId") Long genreId) {
|
||||
filmService.deleteGenre(id, genreId);
|
||||
return "redirect:/film/genres/{id}";
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
import ru.ulstu.is.lab1.WebConfiguration;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(WebConfiguration.REST_API + "/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();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.lab1.DataBase.service.GenreService;
|
||||
import ru.ulstu.is.lab1.DataBase.service.FilmService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/genre")
|
||||
public class GenreMvcController {
|
||||
private final GenreService genreService;
|
||||
public GenreMvcController(GenreService genreService) {
|
||||
this.genreService = genreService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getGenres(Model model) {
|
||||
model.addAttribute("genres",
|
||||
genreService.findAllGenres().stream()
|
||||
.map(GenreDTO::new)
|
||||
.toList());
|
||||
return "genre";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editGenre(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("genreDTO", new GenreDTO());
|
||||
} else {
|
||||
model.addAttribute("genreId", id);
|
||||
model.addAttribute("genreDTO", new GenreDTO(genreService.findGenre(id)));
|
||||
}
|
||||
return "genre-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
public String saveGenre(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid GenreDTO genreDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "genre-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
genreService.addGenre(genreDTO.getName());
|
||||
} else {
|
||||
genreService.updateGenre(id, genreDTO.getName());
|
||||
}
|
||||
return "redirect:/genre";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteGenre(@PathVariable Long id) {
|
||||
genreService.deleteGenre(id);
|
||||
return "redirect:/genre";
|
||||
}
|
||||
@GetMapping("/report/{id}")
|
||||
public String findFilmsOnGenre(@PathVariable(required = false) Long id, Model model){
|
||||
model.addAttribute("cathegory", "Фильмы по жанру: " + genreService.findGenre(id).getName());
|
||||
model.addAttribute("films", genreService.findFilmOnGenre(id).stream()
|
||||
.map(FilmDTO::new)
|
||||
.toList());
|
||||
model.addAttribute("page", "genre");
|
||||
return "report";
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.User;
|
||||
import ru.ulstu.is.lab1.DataBase.model.UserRole;
|
||||
|
||||
public class UserDTO {
|
||||
private final long id;
|
||||
private final String login;
|
||||
private final UserRole role;
|
||||
public UserDTO(User user) {
|
||||
this.id = user.getId();
|
||||
this.login = user.getLogin();
|
||||
this.role = user.getRole();
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.UserRole;
|
||||
import ru.ulstu.is.lab1.DataBase.service.UserService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/users")
|
||||
public class UserMvcController {
|
||||
private final UserService userService;
|
||||
public UserMvcController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@GetMapping
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public String getUsers(@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "5") int size,
|
||||
Model model) {
|
||||
final Page<UserDTO> users = userService.findAllPages(page, size)
|
||||
.map(UserDTO::new);
|
||||
model.addAttribute("users", users);
|
||||
final int totalPages = users.getTotalPages();
|
||||
final List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
||||
.boxed()
|
||||
.toList();
|
||||
model.addAttribute("pages", pageNumbers);
|
||||
model.addAttribute("totalPages", totalPages);
|
||||
return "users";
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public class UserSignupDTO {
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String login;
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String password;
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String passwordConfirm;
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getPasswordConfirm() {
|
||||
return passwordConfirm;
|
||||
}
|
||||
public void setPasswordConfirm(String passwordConfirm) {
|
||||
this.passwordConfirm = passwordConfirm;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package ru.ulstu.is.lab1.DataBase.controller;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.User;
|
||||
import ru.ulstu.is.lab1.DataBase.service.UserService;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidationException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(UserSignupMvcController.SIGNUP_URL)
|
||||
public class UserSignupMvcController {
|
||||
public static final String SIGNUP_URL = "/signup";
|
||||
private final UserService userService;
|
||||
public UserSignupMvcController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@GetMapping
|
||||
public String showSignupForm(Model model) {
|
||||
model.addAttribute("UserDTO", new UserSignupDTO());
|
||||
return "signup";
|
||||
}
|
||||
@PostMapping
|
||||
public String signup(@ModelAttribute("UserDTO") @Valid UserSignupDTO userSignupDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "signup";
|
||||
}
|
||||
try {
|
||||
final User user = userService.createUser(
|
||||
userSignupDTO.getLogin(), userSignupDTO.getPassword(), userSignupDTO.getPasswordConfirm());
|
||||
return "redirect:/login?created=" + user.getLogin();
|
||||
} catch (ValidationException e) {
|
||||
model.addAttribute("errors", e.getMessage());
|
||||
return "signup";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
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()) +
|
||||
'}';
|
||||
}
|
||||
}
|
114
src/main/java/ru/ulstu/is/lab1/DataBase/model/Film.java
Normal file
@ -0,0 +1,114 @@
|
||||
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()) +
|
||||
'}';
|
||||
}
|
||||
}
|
54
src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java
Normal file
@ -0,0 +1,54 @@
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
83
src/main/java/ru/ulstu/is/lab1/DataBase/model/User.java
Normal file
@ -0,0 +1,83 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User
|
||||
{
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(nullable = false, unique = true, length = 64)
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String login;
|
||||
@Column(nullable = false, length = 64)
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String password;
|
||||
private UserRole role;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String login, String password) {
|
||||
this(login, password, UserRole.USER);
|
||||
}
|
||||
|
||||
public User(String login, String password, UserRole role) {
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
User user = (User) o;
|
||||
return Objects.equals(id, user.id) && Objects.equals(login, user.login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, login);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", login='" + login + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", role='" + role + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
17
src/main/java/ru/ulstu/is/lab1/DataBase/model/UserRole.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
public enum UserRole implements GrantedAuthority {
|
||||
ADMIN,
|
||||
USER;
|
||||
private static final String PREFIX = "ROLE_";
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return PREFIX + this.name();
|
||||
}
|
||||
public static final class AsString {
|
||||
public static final String ADMIN = PREFIX + "ADMIN";
|
||||
public static final String USER = PREFIX + "USER";
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Film> getFilmsFromCollection(Long collectionId){
|
||||
Optional<Collection> collectionOptional = collectionRepository.findById(collectionId);
|
||||
if (collectionOptional.isPresent()) {
|
||||
Collection collection = collectionOptional.get();
|
||||
return collection.getFilms();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Collection not found with id: " + collectionId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
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));
|
||||
}
|
||||
}
|
109
src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java
Normal file
@ -0,0 +1,109 @@
|
||||
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));
|
||||
}
|
||||
for(Long genreId : genreIds) {
|
||||
final Genre genre = genreService.findGenre(genreId);
|
||||
film.addGenre(genre);
|
||||
}
|
||||
return filmRepository.save(film);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film deleteGenre(Long filmId, Long genreId) {
|
||||
Film film = findFilm(filmId);
|
||||
if (film == null) {
|
||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId));
|
||||
}
|
||||
final Genre genre = genreService.findGenre(genreId);
|
||||
if (genre == null) {
|
||||
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId));
|
||||
}
|
||||
|
||||
film.removeGenre(genre);
|
||||
return filmRepository.save(film);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Genre> getGenresFromFilm(Long filmId){
|
||||
Optional<Film> filmOptional = filmRepository.findById(filmId);
|
||||
if (filmOptional.isPresent()) {
|
||||
Film film = filmOptional.get();
|
||||
return film.getGenres();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Film not found with id: " + filmId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ru.ulstu.is.lab1.DataBase.service;
|
||||
|
||||
import ru.ulstu.is.lab1.DataBase.model.User;
|
||||
import ru.ulstu.is.lab1.DataBase.model.UserRole;
|
||||
import ru.ulstu.is.lab1.DataBase.Repository.IUserRepository;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidationException;
|
||||
import ru.ulstu.is.lab1.util.validation.ValidatorUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class UserService implements UserDetailsService {
|
||||
private final IUserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
public UserService(IUserRepository userRepository,
|
||||
PasswordEncoder passwordEncoder,
|
||||
ValidatorUtil validatorUtil) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
public Page<User> findAllPages(int page, int size) {
|
||||
return userRepository.findAll(PageRequest.of(page - 1, size, Sort.by("id").ascending()));
|
||||
}
|
||||
public User findByLogin(String login) {
|
||||
return userRepository.findOneByLoginIgnoreCase(login);
|
||||
}
|
||||
public User createUser(String login, String password, String passwordConfirm) {
|
||||
return createUser(login, password, passwordConfirm, UserRole.USER);
|
||||
}
|
||||
public User createUser(String login, String password, String passwordConfirm, UserRole role) {
|
||||
if (findByLogin(login) != null) {
|
||||
throw new ValidationException(String.format("User '%s' already exists", login));
|
||||
}
|
||||
final User user = new User(login, passwordEncoder.encode(password), role);
|
||||
validatorUtil.validate(user);
|
||||
if (!Objects.equals(password, passwordConfirm)) {
|
||||
throw new ValidationException("Passwords not equals");
|
||||
}
|
||||
return userRepository.save(user);
|
||||
}
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
final User userEntity = findByLogin(username);
|
||||
if (userEntity == null) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
return new org.springframework.security.core.userdetails.User(
|
||||
userEntity.getLogin(), userEntity.getPassword(), Collections.singleton(userEntity.getRole()));
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@ 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
|
||||
@ -13,8 +11,4 @@ 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class PasswordEncoderConfiguration {
|
||||
@Bean
|
||||
public PasswordEncoder createPasswordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
68
src/main/java/ru/ulstu/is/lab1/SecurityConfiguration.java
Normal file
@ -0,0 +1,68 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import ru.ulstu.is.lab1.DataBase.controller.UserSignupMvcController;
|
||||
import ru.ulstu.is.lab1.DataBase.model.UserRole;
|
||||
import ru.ulstu.is.lab1.DataBase.service.UserService;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(securedEnabled = true)
|
||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
||||
private static final String LOGIN_URL = "/login";
|
||||
private final UserService userService;
|
||||
|
||||
public SecurityConfiguration(UserService userService) {
|
||||
this.userService = userService;
|
||||
createAdminOnStartup();
|
||||
}
|
||||
|
||||
private void createAdminOnStartup() {
|
||||
final String admin = "admin";
|
||||
if (userService.findByLogin(admin) == null) {
|
||||
log.info("Admin user successfully created");
|
||||
userService.createUser(admin, admin, admin, UserRole.ADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.headers().frameOptions().sameOrigin().and()
|
||||
.cors().and()
|
||||
.csrf().disable()
|
||||
.authorizeRequests()
|
||||
.antMatchers(UserSignupMvcController.SIGNUP_URL).permitAll()
|
||||
.antMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage(LOGIN_URL).permitAll()
|
||||
.and()
|
||||
.logout().permitAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) {
|
||||
web.ignoring()
|
||||
.antMatchers("/css/**")
|
||||
.antMatchers("/images/**")
|
||||
.antMatchers("/js/**")
|
||||
.antMatchers("/templates/**")
|
||||
.antMatchers("/webjars/**");
|
||||
}
|
||||
}
|
20
src/main/java/ru/ulstu/is/lab1/WebConfiguration.java
Normal file
@ -0,0 +1,20 @@
|
||||
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.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
public static final String REST_API = "/api";
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
WebMvcConfigurer.super.addViewControllers(registry);
|
||||
registry.addViewController("login");
|
||||
}
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry){
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package ru.ulstu.is.lab1.util.validation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ValidationException extends RuntimeException{
|
||||
public <T> ValidationException(Set<String> errors) {
|
||||
super(String.join("\n", errors));
|
||||
}
|
||||
|
||||
public <T> ValidationException(String error) { super(error); }
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
11
src/main/resources/application.properties
Normal file
@ -0,0 +1,11 @@
|
||||
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
|
50
src/main/resources/static/css/style.css
Normal file
@ -0,0 +1,50 @@
|
||||
header{
|
||||
font-size: 28px;
|
||||
}
|
||||
.logo{
|
||||
font-size: 64px;
|
||||
line-height: 76px;
|
||||
}
|
||||
footer{
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
margin: 0 !important;
|
||||
}
|
||||
body {
|
||||
background: fixed;
|
||||
background-color: blue !important;
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
.first_page{
|
||||
background-image: url(../images/Фон1.jpg);
|
||||
min-height: 100vh;
|
||||
width: 100%;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
.banner-block {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.banner-card {
|
||||
width: 0;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
opacity: 0.2;
|
||||
transition: 0.5s opacity ease;
|
||||
}
|
||||
|
||||
.banner-card.active {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
opacity: 1;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.banner-card.active img {
|
||||
height: 75vh;
|
||||
}
|
BIN
src/main/resources/static/images/banner1.jpg
Normal file
After Width: | Height: | Size: 71 KiB |
BIN
src/main/resources/static/images/banner2.jpg
Normal file
After Width: | Height: | Size: 152 KiB |
BIN
src/main/resources/static/images/banner3.jpg
Normal file
After Width: | Height: | Size: 123 KiB |
BIN
src/main/resources/static/images/name.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
src/main/resources/static/images/Фон1.jpg
Normal file
After Width: | Height: | Size: 77 KiB |
28
src/main/resources/templates/add-film.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div layout:fragment="content">
|
||||
<form action="#" th:action="@{/collection/add_film/{id}(id=${collectionId})}" method="post">
|
||||
<div class="form-group">
|
||||
<h2 class="text-danger mt-3">Выберите фильм:</h2>
|
||||
<select class="form-select" name="filmId" id="films" required>
|
||||
<option th:each="film, iterator: ${films}" th:text="${film.name}" th:value="${film.id}">
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/collection}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
33
src/main/resources/templates/add-genre.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div layout:fragment="content">
|
||||
<form action="#" th:action="@{/film/add_genres/{id}(id=${filmId})}" method="post">
|
||||
<div class="form-group">
|
||||
<h2 class="text-danger mt-3">Выберите жанры:</h2>
|
||||
<ul class="list-group mt-3">
|
||||
<li class="list-group-item" th:each="genre, iterator: ${genres}">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="genreId" th:value="${genre.id}">
|
||||
<label class="form-check-label" th:text="${genre.name}"></label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/film}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
src/main/resources/templates/collection-edit.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/collection/{id}(id=${id})}" th:object="${collectionDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label text-light">Название</label>
|
||||
<input type="text" class="form-control" id="name" th:field="${collectionDTO.name}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">
|
||||
<span th:if="${collectionId == null}">Добавить</span>
|
||||
<span th:if="${collectionId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/collection}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
56
src/main/resources/templates/collection.html
Normal file
@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center text-danger mb-4">Коллекции</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/collection/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="collection, iterator: ${collections}">
|
||||
<td th:text="${collection.name}"></td>
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/collection/edit/{id}(id=${collection.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${collection.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
<a class="btn btn-success button-fixed button-sm"
|
||||
th:href="@{/collection/films/{id}(id=${collection.id})}">
|
||||
<i class="fa-solid fa-eye"></i>Посмотреть фильмы</a>
|
||||
<a class="btn btn-success button-fixed button-sm"
|
||||
th:href="@{/collection/getFilms/{id}(id=${collection.id})}">
|
||||
<i class="fa-solid fa-plus"></i>Добавить фильмы</a>
|
||||
</div>
|
||||
<form th:action="@{/collection/delete/{id}(id=${collection.id})}" method="post">
|
||||
<button th:id="'remove-' + ${collection.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
48
src/main/resources/templates/default.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>VIDEO | FILMS</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
||||
<link rel="stylesheet" href="../static/css/style.css" th:href="@{/css/style.css}"/>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-dark navbar-expand-xl bg-black">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/"><img src="../static/images/name.png" th:src="@{/images/name.png}"></a>
|
||||
<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">
|
||||
<a class="nav-link" href="/" th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная</a>
|
||||
<a class="nav-link" href="/genre" th:classappend="${#strings.equals(activeLink, '/genre')} ? 'active' : ''">Жанры</a>
|
||||
<a class="nav-link" href="/film" th:classappend="${#strings.equals(activeLink, '/film')} ? 'active' : ''">Фильмы</a>
|
||||
<a class="nav-link" href="/collection" th:classappend="${#strings.equals(activeLink, '/collection')} ? 'active' : ''">Коллекции</a>
|
||||
<a class="nav-link" href="/users" sec:authorize="hasRole('ROLE_ADMIN')" th:classappend="${#strings.equals(activeLink, '/users')} ? 'active' : ''">Пользователи</a>
|
||||
<a class="nav-link" href="/logout" th:classappend="${#strings.equals(activeLink, '/login')} ? 'active' : ''">Выход</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container-fluid">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
13
src/main/resources/templates/error.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div><span th:text="${error}"></span></div>
|
||||
<a href="/">На главную</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
src/main/resources/templates/film-edit.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/film/{id}(id=${id})}" th:object="${filmDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label text-light">Название</label>
|
||||
<input type="text" class="form-control" id="name" th:field="${filmDTO.name}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">
|
||||
<span th:if="${filmId == null}">Добавить</span>
|
||||
<span th:if="${filmId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/film}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
56
src/main/resources/templates/film.html
Normal file
@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center text-danger mb-4">Фильмы</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/film/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="film, iterator: ${films}">
|
||||
<td th:text="${film.name}"></td>
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/film/edit/{id}(id=${film.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${film.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
<a class="btn btn-success button-fixed button-sm"
|
||||
th:href="@{/film/genres/{id}(id=${film.id})}">
|
||||
<i class="fa-solid fa-eye"></i>Посмотреть жанры</a>
|
||||
<a class="btn btn-success button-fixed button-sm"
|
||||
th:href="@{/film/getGenres/{id}(id=${film.id})}">
|
||||
<i class="fa-solid fa-plus"></i>Добавить жанры</a>
|
||||
</div>
|
||||
<form th:action="@{/film/delete/{id}(id=${film.id})}" method="post">
|
||||
<button th:id="'remove-' + ${film.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
src/main/resources/templates/genre-edit.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/genre/{id}(id=${id})}" th:object="${genreDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label text-light">Название</label>
|
||||
<input type="text" class="form-control" id="name" th:field="${genreDTO.name}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">
|
||||
<span th:if="${genreId == null}">Добавить</span>
|
||||
<span th:if="${genreId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/genre}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
54
src/main/resources/templates/genre.html
Normal file
@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center text-danger mb-4">Жанры</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/genre/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="genre, iterator: ${genres}">
|
||||
<td th:text="${genre.name}"></td>
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/genre/edit/{id}(id=${genre.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${genre.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
<a class="btn btn-success button-fixed button-sm"
|
||||
th:href="@{/genre/report/{id}(id=${genre.id})}">
|
||||
<i class="fa fa-book" aria-hidden="true"></i> Отчет
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{/genre/delete/{id}(id=${genre.id})}" method="post">
|
||||
<button th:id="'remove-' + ${genre.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
33
src/main/resources/templates/index.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<section class="first_page" layout:fragment="content">
|
||||
<div class="banner-block" id="banner">
|
||||
<div class="banner-card active">
|
||||
<img src="/images/banner1.jpg"/>
|
||||
</div>
|
||||
<div class="banner-card">
|
||||
<img src="/images/banner2.jpg"/>
|
||||
</div>
|
||||
<div class="banner-card">
|
||||
<img src="/images/banner3.jpg"/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<th:block layout:fragment="scripts">
|
||||
<script>
|
||||
let active = 0;
|
||||
let banner = document.getElementById("banner")
|
||||
setInterval(() => {
|
||||
active += active == 2 ? -2 : 1;
|
||||
document.querySelector(".banner-card.active").classList.remove("active");
|
||||
banner.children[active].classList.add("active");
|
||||
}, 3000);
|
||||
</script>
|
||||
</th:block>
|
||||
</body>
|
||||
</html>
|
33
src/main/resources/templates/login.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:if="${param.error}" class="alert alert-danger margin-bottom">
|
||||
Пользователь не найден или пароль указан не верно
|
||||
</div>
|
||||
<div th:if="${param.logout}" class="alert alert-success margin-bottom">
|
||||
Выход успешно произведен
|
||||
</div>
|
||||
<div th:if="${param.created}" class="alert alert-success margin-bottom">
|
||||
Пользователь '<span th:text="${param.created}"></span>' успешно создан
|
||||
</div>
|
||||
<form th:action="@{/login}" method="post" class="container-padding">
|
||||
<div class="mb-3">
|
||||
<input type="text" name="username" id="username" class="form-control"
|
||||
placeholder="Логин" required="true" autofocus="true"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" name="password" id="password" class="form-control"
|
||||
placeholder="Пароль" required="true"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success button-fixed">Войти</button>
|
||||
<a class="btn btn-primary button-fixed" href="/signup">Регистрация</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
32
src/main/resources/templates/report.html
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h5 th:text="${cathegory}" class="d-flex justify-content-center mb-3"></h5>
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div layout:fragment="content">
|
||||
<div th:if="${id != null}" class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Название</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="film, iterator: ${films}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"></th>
|
||||
<td th:text="${film.name}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<a class="btn btn-secondary" th:href="@{/} + ${page}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
31
src/main/resources/templates/signup.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
<div th:if="${errors}" th:text="${errors}" class="margin-bottom alert alert-danger"></div>
|
||||
<form action="#" th:action="@{/signup}" th:object="${UserDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" th:field="${UserDTO.login}"
|
||||
placeholder="Логин" required="true" autofocus="true" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" th:field="${UserDTO.password}"
|
||||
placeholder="Пароль" required="true" minlength="6" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" th:field="${UserDTO.passwordConfirm}"
|
||||
placeholder="Пароль (подтверждение)" required="true" minlength="6" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success button-fixed">Создать</button>
|
||||
<a class="btn btn-primary button-fixed" href="/login">Назад</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
40
src/main/resources/templates/users.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Логин</th>
|
||||
<th scope="col">Роль</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="user, iterator: ${users}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"></th>
|
||||
<td th:text="${user.id}"></td>
|
||||
<td th:text="${user.login}" style="width: 60%"></td>
|
||||
<td th:text="${user.role}" style="width: 20%"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div th:if="${totalPages > 0}" class="pagination text-light">
|
||||
<span style="float: left; padding: 5px 5px;">Страницы:</span>
|
||||
<a th:each="page : ${pages}"
|
||||
th:href="@{/users(page=${page}, size=${users.size})}"
|
||||
th:text="${page}"
|
||||
th:class="${page == users.number + 1} ? active">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
34
src/main/resources/templates/view-films.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="film, iterator: ${films}">
|
||||
<td th:text="${film.name}"></td>
|
||||
<td>
|
||||
<form method="post" th:action="@{/collection/del_film/{id}/{filmId}(id=${id}, filmId=${film.id})}">
|
||||
<button type="submit" class="btn btn-danger button-fixed button-sm">Удалить</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/collection}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
34
src/main/resources/templates/view-genres.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table text-light">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="genre, iterator: ${genres}">
|
||||
<td th:text="${genre.name}"></td>
|
||||
<td>
|
||||
<form method="post" th:action="@{/film/del_genre/{id}/{genreId}(id=${id}, genreId=${genre.id})}">
|
||||
<button type="submit" class="btn btn-danger button-fixed button-sm">Удалить</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/film}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
80
src/test/java/ru/ulstu/is/lab1/JpaCollectionTests.java
Normal file
@ -0,0 +1,80 @@
|
||||
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);
|
||||
}*/
|
||||
}
|
96
src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java
Normal file
@ -0,0 +1,96 @@
|
||||
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);
|
||||
}*/
|
||||
}
|
61
src/test/java/ru/ulstu/is/lab1/JpaGenreTests.java
Normal file
@ -0,0 +1,61 @@
|
||||
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);
|
||||
}*/
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package ru.ulstu.is.lab1;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Lab1ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
6
src/test/resources/application.properties
Normal file
@ -0,0 +1,6 @@
|
||||
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
|