Compare commits
No commits in common. "LabWork04" and "main" have entirely different histories.
4
.gitignore
vendored
4
.gitignore
vendored
@ -18,9 +18,6 @@ bin/
|
|||||||
!**/src/test/**/bin/
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
*.png
|
|
||||||
*.jpeg
|
|
||||||
*.webp
|
|
||||||
.idea
|
.idea
|
||||||
*.iws
|
*.iws
|
||||||
*.iml
|
*.iml
|
||||||
@ -38,4 +35,3 @@ out/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
/frontend/node_modules/
|
|
||||||
|
11
build.gradle
11
build.gradle
@ -6,23 +6,14 @@ plugins {
|
|||||||
|
|
||||||
group = 'ru.ulstu.is'
|
group = 'ru.ulstu.is'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = '19'
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/commons-io/commons-io
|
|
||||||
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
||||||
implementation 'com.h2database:h2:2.1.210'
|
|
||||||
|
|
||||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
|
||||||
|
|
||||||
implementation 'org.hibernate.validator:hibernate-validator:6.0.17.Final'
|
|
||||||
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
frontend/spa-vue/.gitignore
vendored
24
frontend/spa-vue/.gitignore
vendored
@ -1,24 +0,0 @@
|
|||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
node_modules
|
|
||||||
dist
|
|
||||||
dist-ssr
|
|
||||||
*.local
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.idea
|
|
||||||
.DS_Store
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw?
|
|
@ -1,7 +0,0 @@
|
|||||||
# Vue 3 + Vite
|
|
||||||
|
|
||||||
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
|
||||||
|
|
||||||
## Recommended IDE Setup
|
|
||||||
|
|
||||||
- [VS Code](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).
|
|
@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
"Devices": [
|
|
||||||
{
|
|
||||||
"name": "Компьютер"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Телефон"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Видеокарта"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Products": [
|
|
||||||
{
|
|
||||||
"type": "Компьютер",
|
|
||||||
"price": 435,
|
|
||||||
"count": 345,
|
|
||||||
"id": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"type": "123123",
|
|
||||||
"price": 324,
|
|
||||||
"count": 124124,
|
|
||||||
"ame": "345345"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 10,
|
|
||||||
"type": "123123",
|
|
||||||
"price": 2342,
|
|
||||||
"count": 123,
|
|
||||||
"ame": "123"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Главная страница</title>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
4977
frontend/spa-vue/package-lock.json
generated
4977
frontend/spa-vue/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "spa-vue",
|
|
||||||
"private": true,
|
|
||||||
"version": "1.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"fake-server": "json-server --watch data.json -p 8079",
|
|
||||||
"start": "npm-run-all --parallel dev fake-server",
|
|
||||||
"build": "vite build",
|
|
||||||
"preview": "vite preview"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"vue": "^3.2.41",
|
|
||||||
"vue-router": "^4.1.6",
|
|
||||||
"axios": "^1.1.3",
|
|
||||||
"bootstrap": "^5.2.2",
|
|
||||||
"@fortawesome/fontawesome-free": "^6.2.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"vite": "^3.2.3",
|
|
||||||
"@vitejs/plugin-vue": "^3.2.0",
|
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"json-server": "^0.17.1"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<script>
|
|
||||||
import Header from "./components/Header.vue";
|
|
||||||
export default{
|
|
||||||
components:{
|
|
||||||
Header
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Header></Header>
|
|
||||||
<router-view>
|
|
||||||
|
|
||||||
</router-view>
|
|
||||||
</template>
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
#banner {
|
|
||||||
margin: 15px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex-direction: column;
|
|
||||||
min-height: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#banner img {
|
|
||||||
border-radius: 15px;
|
|
||||||
width: 100%;
|
|
||||||
max-height: 500px;
|
|
||||||
max-width: 70%;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
<template>
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
||||||
<div class="container-fluid">
|
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
|
||||||
<ul class="navbar-nav justify-content-center">
|
|
||||||
<li class="nav-item">
|
|
||||||
<router-link to="/manufacturer" class="nav-link">Производители</router-link>
|
|
||||||
<router-link to="/category" class="nav-link">Категории</router-link>
|
|
||||||
<router-link to="/product" class="nav-link">Продукты</router-link>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.navbar-brand {
|
|
||||||
font-size: 2rem;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-link {
|
|
||||||
color: black;
|
|
||||||
font-weight: bold;
|
|
||||||
text-transform: uppercase;
|
|
||||||
transition: color 0.3s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-link:hover {
|
|
||||||
color: #dc3545;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,7 +0,0 @@
|
|||||||
import { createApp } from 'vue'
|
|
||||||
import './styles.css'
|
|
||||||
import './banner.css'
|
|
||||||
import App from './App.vue'
|
|
||||||
import router from "./routes.js"
|
|
||||||
|
|
||||||
createApp(App).use(router).mount('#app')
|
|
@ -1,6 +0,0 @@
|
|||||||
export default class Category{
|
|
||||||
constructor(data) {
|
|
||||||
this.id = data?.id;
|
|
||||||
this.name = data?.name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
export default class Manufacturer{
|
|
||||||
constructor(data) {
|
|
||||||
this.id = data?.id;
|
|
||||||
this.name = data?.name;
|
|
||||||
this.address = data?.address;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
export default class Product{
|
|
||||||
constructor(data){
|
|
||||||
this.id = data?.id;
|
|
||||||
this.name = data?.name;
|
|
||||||
this.price = data?.price;
|
|
||||||
this.photo = data?.photo;
|
|
||||||
this.categoryId = data?.categoryId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="container mt-4">
|
|
||||||
<h1 class="text-center mb-4">Categories Table</h1>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Название</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="categor in categories" :key="categor.id">
|
|
||||||
<td>{{ categor.name }}</td>
|
|
||||||
<td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('edit', categor)">Изменить</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-danger" @click="deleteCategory(categor.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="editedCategory.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="editedCategory.status === 'create'" @click="addCategory(editedCategory)">Создать</button>
|
|
||||||
<button type="button" class="btn btn-primary" v-else @click="editCategory(editedCategory)">Сохранить</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- Модальное окно для просмотра студентов в группе-->
|
|
||||||
<div class="modal" tabindex="-1" id="ModelForProducts">
|
|
||||||
<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">
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Название</th>
|
|
||||||
<th>Цена</th>
|
|
||||||
<th>Фото</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="prod in products" :key="prod.id">
|
|
||||||
<td>{{ prod.name }}</td>
|
|
||||||
<td>{{ prod.price }}</td>
|
|
||||||
<td>{{ prod.photo }}</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="ModelForStudents" @click="closeModelForProducts()">Закрыть</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script>
|
|
||||||
import 'axios';
|
|
||||||
import axios from "axios";
|
|
||||||
import Category from "../models/Category"
|
|
||||||
import Product from '../models/Product';
|
|
||||||
export default {
|
|
||||||
created() {
|
|
||||||
this.getCategories();
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
const addModal = document.getElementById('editModal');
|
|
||||||
addModal.addEventListener('shown.bs.modal', function () {
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return{
|
|
||||||
categories: [],
|
|
||||||
URL: "http://localhost:8080/",
|
|
||||||
category: new Category(),
|
|
||||||
editedCategory: new Category(),
|
|
||||||
products: [],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getCategories(){
|
|
||||||
axios.get(this.URL + "category")
|
|
||||||
.then(response => {
|
|
||||||
this.categories = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
addCategory(category) {
|
|
||||||
console.log(category);
|
|
||||||
axios
|
|
||||||
.post(this.URL + "category", category)
|
|
||||||
.then(() => {
|
|
||||||
this.getCategories();
|
|
||||||
this.closeModal();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteCategory(id){
|
|
||||||
axios.delete(this.URL + `category/${id}`)
|
|
||||||
.then(() =>{
|
|
||||||
this.getCategories();
|
|
||||||
})
|
|
||||||
},
|
|
||||||
openModal(status, category = null) {
|
|
||||||
if (status === "create") {
|
|
||||||
this.editedCategory = new Category();
|
|
||||||
this.editedCategory.status = "create";
|
|
||||||
} else if (status === "edit" && category) {
|
|
||||||
this.editedCategory = { ...category };
|
|
||||||
this.editedCategory.status = "edit";
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("editModal").style.display = "block";
|
|
||||||
},
|
|
||||||
closeModal() {
|
|
||||||
document.getElementById("editModal").style.display = "none";
|
|
||||||
},
|
|
||||||
editCategory(category) {
|
|
||||||
axios.put(this.URL + `category/${category.id}`, category)
|
|
||||||
.then(() => {
|
|
||||||
const index = this.categories.findIndex((s) => s.id === category.id);
|
|
||||||
if (index !== -1) {
|
|
||||||
this.categories[index] = { ...category };
|
|
||||||
}
|
|
||||||
this.closeModal();
|
|
||||||
this.getCategories();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
@ -1,134 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="container mt-4">
|
|
||||||
<h1 class="text-center mb-4">Manufacturer Table</h1>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Имя</th>
|
|
||||||
<th>Адресс</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="manufs in manufacturers" :key="manufs.id">
|
|
||||||
<td>{{ manufs.name }}</td>
|
|
||||||
<td>{{ manufs.address }}</td>
|
|
||||||
<td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('edit', manufs)">Изменить</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-danger" @click="deleteManufacturer(manufs.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="manufacturer.name">
|
|
||||||
<label for="adress">Адресс:</label>
|
|
||||||
<input type="text" class="form-control" id="adress" name="address" v-model="manufacturer.address">
|
|
||||||
</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="manufacturer.status === 'create'" @click="addManufacturer(manufacturer)">Создать</button>
|
|
||||||
<button type="button" class="btn btn-primary" v-else @click="editManufacturer(manufacturer)">Сохранить</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import 'axios';
|
|
||||||
import axios from "axios";
|
|
||||||
import Manufacturer from "../models/Manufacturer"
|
|
||||||
export default {
|
|
||||||
created() {
|
|
||||||
this.getManufacturers();
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
const addModal = document.getElementById('editModal');
|
|
||||||
addModal.addEventListener('shown.bs.modal', function () {
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return{
|
|
||||||
manufacturers: [],
|
|
||||||
URL: "http://localhost:8080/",
|
|
||||||
manufacturer: new Manufacturer(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getManufacturers(){
|
|
||||||
axios.get(this.URL + "manufacturer")
|
|
||||||
.then(response => {
|
|
||||||
this.manufacturers = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
addManufacturer(manufacturer){
|
|
||||||
console.log(this.manufacturers);
|
|
||||||
axios.post(this.URL + "manufacturer", manufacturer)
|
|
||||||
.then(() => {
|
|
||||||
this.getManufacturers();
|
|
||||||
this.closeModal();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteManufacturer(id){
|
|
||||||
axios.delete(this.URL + `manufacturer/${id}`)
|
|
||||||
.then(() =>{
|
|
||||||
this.getManufacturers();
|
|
||||||
})
|
|
||||||
},
|
|
||||||
editManufacturer(manufacturer){
|
|
||||||
axios.put(this.URL + `manufacturer/${manufacturer.id}`, manufacturer)
|
|
||||||
.then(() =>{
|
|
||||||
const index = this.manufacturers.findIndex((m) => m.id === manufacturer.id);
|
|
||||||
if (index !== -1) {
|
|
||||||
this.manufacturers[index] = { ...manufacturer };
|
|
||||||
}
|
|
||||||
this.closeModal();
|
|
||||||
this.getManufacturers();
|
|
||||||
})
|
|
||||||
this.closeModal();
|
|
||||||
},
|
|
||||||
openModal(status, manufacturer = null) {
|
|
||||||
if (status === "create") {
|
|
||||||
this.manufacturer = new Manufacturer();
|
|
||||||
this.manufacturer.status = "create";
|
|
||||||
} else if (status === "edit" && manufacturer) {
|
|
||||||
this.manufacturer = { ...manufacturer };
|
|
||||||
this.manufacturer.status = "edit";
|
|
||||||
}
|
|
||||||
document.getElementById("editModal").style.display = "block";
|
|
||||||
},
|
|
||||||
closeModal() {
|
|
||||||
document.getElementById("editModal").style.display = "none";
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
@ -1,346 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="container mt-4">
|
|
||||||
<h1 class="text-center mb-4">Product Table</h1>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openFiltrModel('create')">Фильтр</button>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Название</th>
|
|
||||||
<th>Цена</th>
|
|
||||||
<th>Фото</th>
|
|
||||||
<th>Категория</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="prdct in products" :key="prdct.id">
|
|
||||||
<td>{{ prdct.name }}</td>
|
|
||||||
<td>{{ prdct.price }}</td>
|
|
||||||
<td> <img :src = "prdct.photo"></td>
|
|
||||||
<td>{{ prdct && categories.find(ctgr => ctgr.id === prdct.categoryId).name }}</td>
|
|
||||||
<td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary mr-2" @click="openModal('edit', prdct)">Изменить</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-danger" @click="deleteProduct(prdct.id)">Удалить</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary" @click="product = prdct; openManyToManyModal()">Производители</button>
|
|
||||||
</td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- Модальное окно для фильтра -->
|
|
||||||
<div class="modal" tabindex="-1" id="filtrModal">
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">Filtr Products On Manufacturers</h5>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<form>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Название:</th>
|
|
||||||
<th>Редактировать запись:</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="mnfs in filtr" :key="mnfs.id">
|
|
||||||
<td>{{ mnfs.name }}</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary" type="button" @click="removeManufacturer(prod.id)">Удалить</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="input-group mb-3">
|
|
||||||
<select class="form-select" v-model="manufacturerId">
|
|
||||||
<option v-for="mnfctr in manufacturers" :key="mnfctr.id" :value="mnfctr.id">{{ mnfctr.name }}</option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-outline-secondary" type="button" @click="addManufacturerFiltr()">Добавить</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="executeFiltr()">Применить</button>
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeManufacturerFiltr()">Закрыть</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</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="product.name">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="price">Цена:</label>
|
|
||||||
<input type="text" class="form-control" id="price" name="price" v-model="product.price">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="form-control" type="file" id="cover" name="cover" @change="toBase64">
|
|
||||||
<img :src="product.photo" class="img-thumbnail"/>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="category">Категория:</label>
|
|
||||||
<select v-model="product.categoryId" class="form-control">
|
|
||||||
<option v-for="(category, index) in categories" :key="index" :value="category.id">
|
|
||||||
{{ category.name }}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</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="product.status === 'create'" @click="addProduct">Создать</button>
|
|
||||||
<button type="button" class="btn btn-primary" v-else @click="editProduct(product)">Сохранить</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal" tabindex="-1" id="manyToManyModal">
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">Add Manufacturers to Product</h5>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<form>
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Название:</th>
|
|
||||||
<th>Редактировать запись:</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="prod in productManufacturers" :key="prod.id">
|
|
||||||
<td>{{ prod.name }}</td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-primary" type="button" @click="removeManufacturer(prod.id)">Удалить</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="input-group mb-3">
|
|
||||||
<select class="form-select" v-model="manufacturerId">
|
|
||||||
<option v-for="mnfctr in manufacturers" :key="mnfctr.id" :value="mnfctr.id">{{ mnfctr.name }}</option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-outline-secondary" type="button" @click="addManufacturer()">Добавить</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeManyToManyModal()">Закрыть</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script>
|
|
||||||
import 'axios';
|
|
||||||
import axios from "axios";
|
|
||||||
import Product from "../models/Product";
|
|
||||||
export default {
|
|
||||||
created() {
|
|
||||||
this.getProducts();
|
|
||||||
this.getCategories();
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
const addModal = document.getElementById('editModal');
|
|
||||||
addModal.addEventListener('shown.bs.modal', function () {
|
|
||||||
})
|
|
||||||
const addFiltrModal = document.getElementById('filtrModal');
|
|
||||||
addFiltrModal.addEventListener('shown.bs.modal', function () {
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return{
|
|
||||||
products: [],
|
|
||||||
categories: [],
|
|
||||||
manufacturers: [],
|
|
||||||
productManufacturers: [],
|
|
||||||
filtr: [],
|
|
||||||
manufacturerId: 0,
|
|
||||||
URL: "http://localhost:8080/",
|
|
||||||
product: new Product(),
|
|
||||||
editedProduct: new Product(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getProducts(){
|
|
||||||
axios.get(this.URL + "product")
|
|
||||||
.then(response => {
|
|
||||||
this.products = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getCategories(){
|
|
||||||
axios.get(this.URL + "category")
|
|
||||||
.then(response => {
|
|
||||||
this.categories = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async addProduct(){
|
|
||||||
await this.toBase64();
|
|
||||||
this.product.price = parseInt(this.product.price);
|
|
||||||
console.log(this.product);
|
|
||||||
axios.post(this.URL + "product", this.product)
|
|
||||||
.then((response) => {
|
|
||||||
this.getProducts();
|
|
||||||
this.closeModal();
|
|
||||||
this.product = response.data;
|
|
||||||
this.openManyToManyModal();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteProduct(id){
|
|
||||||
axios.delete(this.URL + `product/${id}`)
|
|
||||||
.then(() =>{
|
|
||||||
this.getProducts();
|
|
||||||
})
|
|
||||||
},
|
|
||||||
async editProduct(product){
|
|
||||||
if(product.photo === undefined) await this.toBase64();
|
|
||||||
console.log(product);
|
|
||||||
axios.put(this.URL + `product/${product.id}`, product)
|
|
||||||
.then(() =>{
|
|
||||||
const index = this.products.findIndex((s) => s.id === product.id);
|
|
||||||
if (index !== -1) {
|
|
||||||
this.products[index] = { ...product };
|
|
||||||
}
|
|
||||||
this.closeModal();
|
|
||||||
this.getProducts();
|
|
||||||
})
|
|
||||||
this.closeModal();
|
|
||||||
},
|
|
||||||
openModal(status, product = null) {
|
|
||||||
this.getCategories();
|
|
||||||
if (status === "create") {
|
|
||||||
this.product = new Product();
|
|
||||||
this.product.status = "create";
|
|
||||||
} else if (status === "edit" && product) {
|
|
||||||
this.product = { ...product };
|
|
||||||
this.product.status = "edit";
|
|
||||||
}
|
|
||||||
document.getElementById("editModal").style.display = "block";
|
|
||||||
},
|
|
||||||
closeModal() {
|
|
||||||
document.getElementById("editModal").style.display = "none";
|
|
||||||
},
|
|
||||||
async toBase64(){
|
|
||||||
var file = document.getElementById("cover").files[0];
|
|
||||||
var reader = new FileReader();
|
|
||||||
var phototemp = this.product;
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
reader.onload = function () {
|
|
||||||
phototemp.photo = reader.result;
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
reader.onerror = function (error) {
|
|
||||||
console.log('Error: ', error);
|
|
||||||
reject(error);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
openManyToManyModal(){
|
|
||||||
this.getAllManufacturers();
|
|
||||||
this.getProductManufacturers();
|
|
||||||
document.getElementById("manyToManyModal").style.display = "block";
|
|
||||||
},
|
|
||||||
closeManyToManyModal() {
|
|
||||||
document.getElementById("manyToManyModal").style.display = "none";
|
|
||||||
},
|
|
||||||
getAllManufacturers(){
|
|
||||||
axios.get(this.URL + "manufacturer")
|
|
||||||
.then(response => {
|
|
||||||
this.manufacturers = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getProductManufacturers(){
|
|
||||||
console.log(this.product.id);
|
|
||||||
axios.get(this.URL + `product/${this.product.id}/manufacturers`)
|
|
||||||
.then(response => {
|
|
||||||
this.productManufacturers = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
addManufacturer(){
|
|
||||||
axios.post(this.URL + `product/${this.product.id}/Manufacturer/${this.manufacturerId}`)
|
|
||||||
.then(() => {
|
|
||||||
this.getProductManufacturers();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
removeManufacturer(id){
|
|
||||||
axios.delete(this.URL + `product/${this.product.id}/Manufacturer/${id}`)
|
|
||||||
.then(() =>{
|
|
||||||
this.getProductManufacturers();
|
|
||||||
})
|
|
||||||
},
|
|
||||||
openFiltrModel() {
|
|
||||||
this.getAllManufacturers();
|
|
||||||
document.getElementById("filtrModal").style.display = "block";
|
|
||||||
},
|
|
||||||
addManufacturerFiltr() {
|
|
||||||
const selectedManufacturer = this.manufacturers.find(mnfctr => mnfctr.id === this.manufacturerId);
|
|
||||||
if (selectedManufacturer) {
|
|
||||||
this.filtr.push(selectedManufacturer);
|
|
||||||
console.log(this.filtr);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
closeManufacturerFiltr() {
|
|
||||||
document.getElementById("filtrModal").style.display = "none";
|
|
||||||
},
|
|
||||||
executeFiltr() {
|
|
||||||
console.log(this.filtr);
|
|
||||||
const manufacturers = this.filtr;
|
|
||||||
axios.post(this.URL + "product/by-manufacturers", manufacturers)
|
|
||||||
.then(response => {
|
|
||||||
this.products = response.data;
|
|
||||||
console.log(response.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
@ -1,18 +0,0 @@
|
|||||||
import manufacturers from './pages/manufacturers.vue'
|
|
||||||
import categories from './pages/categories.vue'
|
|
||||||
import products from './pages/products.vue'
|
|
||||||
import {createRouter, createWebHistory} from "vue-router"
|
|
||||||
|
|
||||||
const routes = [
|
|
||||||
{path: '/manufacturer', component: manufacturers},
|
|
||||||
{path: '/category', component: categories},
|
|
||||||
{path: '/product', component: products},
|
|
||||||
]
|
|
||||||
|
|
||||||
const router = createRouter({
|
|
||||||
history: createWebHistory(),
|
|
||||||
linkActiveClass: 'active',
|
|
||||||
routes
|
|
||||||
})
|
|
||||||
|
|
||||||
export default router;
|
|
@ -1,42 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
function toJSON(data) {
|
|
||||||
const jsonObj = {};
|
|
||||||
const fields = Object.getOwnPropertyNames(data);
|
|
||||||
for (const field of fields) {
|
|
||||||
if (data[field] === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
jsonObj[field.substring(1)] = data[field];
|
|
||||||
}
|
|
||||||
return jsonObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class DataService {
|
|
||||||
static dataUrlPrefix = 'http://localhost:8079/';
|
|
||||||
|
|
||||||
static async readAll(url, transformer) {
|
|
||||||
const response = await axios.get(this.dataUrlPrefix + url);
|
|
||||||
return response.data.map(item => transformer(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
static async read(url, transformer) {
|
|
||||||
const response = await axios.get(this.dataUrlPrefix + url);
|
|
||||||
return transformer(response.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async create(url, data) {
|
|
||||||
const response = await axios.post(this.dataUrlPrefix + url, toJSON(data));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async update(url, data) {
|
|
||||||
const response = await axios.put(this.dataUrlPrefix + url, toJSON(data));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async delete(url) {
|
|
||||||
const response = await axios.delete(this.dataUrlPrefix + url);
|
|
||||||
return response.data.id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
:root {
|
|
||||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
||||||
line-height: 1.5;
|
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
-webkit-text-size-adjust: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
place-items: center;
|
|
||||||
min-width: 320px;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
|
||||||
max-width: 1280px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
color: #213547;
|
|
||||||
background-color: #ffffff;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
html {
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav {
|
|
||||||
font-size: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav a {
|
|
||||||
color: white;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbar-nav .nav-link {
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
transition: 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card:hover {
|
|
||||||
box-shadow: 0px 0px 3px 4px gray;
|
|
||||||
transform: scale(1.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#brands {
|
|
||||||
margin-top: 5rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#main {
|
|
||||||
margin-top: 5rem;
|
|
||||||
margin-bottom: 5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#lc_main {
|
|
||||||
padding-top: 2rem;
|
|
||||||
padding-bottom: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#cart_main {
|
|
||||||
margin-top: 2rem;
|
|
||||||
margin-bottom: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#secondStr {
|
|
||||||
padding-top: 1rem;
|
|
||||||
padding-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#firstRow {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#catalog_main .btn {
|
|
||||||
background: orange;
|
|
||||||
border: 2px solid darkgray;
|
|
||||||
}
|
|
||||||
|
|
||||||
#catalog_main .btn:hover {
|
|
||||||
background: lightgreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#catalog_main .card {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#catalog_main {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#footer_catalog {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
#information_main {
|
|
||||||
padding-top: 3rem;
|
|
||||||
padding-left: 1rem;
|
|
||||||
padding-right: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#information_main {
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#information_main .card {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#main {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
#registrationForm {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#submitBtn {
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
max-width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input.error {
|
|
||||||
border-color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
.checkbox__input.error + .checkbox__label {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
#frm-items {
|
|
||||||
padding: 32px;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tbl {
|
|
||||||
padding-left: 32px;
|
|
||||||
padding-right: 32px;
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
import vue from '@vitejs/plugin-vue'
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [vue()],
|
|
||||||
})
|
|
@ -1,48 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.CategoryService;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.xml.crypto.dsig.CanonicalizationMethod;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/category")
|
|
||||||
public class CategoryController {
|
|
||||||
private final CategoryService categoryService;
|
|
||||||
|
|
||||||
public CategoryController(CategoryService categoryService) {
|
|
||||||
this.categoryService = categoryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public CategoryDTO getCategory(@PathVariable Long id) {
|
|
||||||
return new CategoryDTO(categoryService.findCategory(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<CategoryDTO> getCategories() {
|
|
||||||
return categoryService.findAllCategories().stream()
|
|
||||||
.map(CategoryDTO::new)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public CategoryDTO createCategory(@RequestBody @Valid CategoryDTO categoryDTO) throws IOException {
|
|
||||||
return new CategoryDTO(categoryService.addCategory(categoryDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public CategoryDTO updateCategory(@PathVariable Long id, @RequestBody @Valid CategoryDTO categoryDTO) {
|
|
||||||
return new CategoryDTO(categoryService.updateCategory(id, categoryDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public CategoryDTO deleteCategory(@PathVariable Long id) {
|
|
||||||
return new CategoryDTO(categoryService.deleteCategory(id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class CategoryDTO {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public CategoryDTO() {}
|
|
||||||
|
|
||||||
public CategoryDTO(Category category) {
|
|
||||||
this.id = category.getId();
|
|
||||||
this.name = category.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.ManufacturerService;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/manufacturer")
|
|
||||||
public class ManufacturerController {
|
|
||||||
private final ManufacturerService manufacturerService;
|
|
||||||
|
|
||||||
public ManufacturerController(ManufacturerService manufacturerService) {
|
|
||||||
this.manufacturerService = manufacturerService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ManufacturerDTO getManufacturer(@PathVariable Long id) {
|
|
||||||
return new ManufacturerDTO(manufacturerService.findManufacturer(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping()
|
|
||||||
public List<ManufacturerDTO> getManufacturers() {
|
|
||||||
return manufacturerService.findAllManufacturers().stream()
|
|
||||||
.map(ManufacturerDTO::new)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public ManufacturerDTO createManufacturer(@RequestBody @Valid ManufacturerDTO manufacturerDTO) throws IOException {
|
|
||||||
return new ManufacturerDTO(manufacturerService.addManufacturer(manufacturerDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ManufacturerDTO updateManufacturer(@PathVariable Long id, @RequestBody @Valid ManufacturerDTO manufacturerDTO) throws IOException {
|
|
||||||
return new ManufacturerDTO(manufacturerService.updateManufacturer(id, manufacturerDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ManufacturerDTO deleteManufacturer(@PathVariable Long id) {
|
|
||||||
return new ManufacturerDTO(manufacturerService.deleteManufacturer(id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class ManufacturerDTO {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
public ManufacturerDTO() {}
|
|
||||||
|
|
||||||
public ManufacturerDTO(Manufacturer manufacturer) {
|
|
||||||
this.id = manufacturer.getId();
|
|
||||||
this.name = manufacturer.getName();
|
|
||||||
this.address = manufacturer.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.ManufacturerService;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.ProductService;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/product")
|
|
||||||
public class ProductController {
|
|
||||||
|
|
||||||
private final ProductService productService;
|
|
||||||
|
|
||||||
public ProductController(ProductService productService) {
|
|
||||||
this.productService = productService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ProductDTO getProduct(@PathVariable Long id) {
|
|
||||||
return new ProductDTO(productService.findProduct(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<ProductDTO> getProducts() {
|
|
||||||
return productService.findAllProducts().stream()
|
|
||||||
.map(ProductDTO::new)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}/manufacturers")
|
|
||||||
public List<ManufacturerDTO> getProductManufacturers(@PathVariable Long id){
|
|
||||||
return productService.getProductManufacturers(id).stream().map(ManufacturerDTO::new).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/by-manufacturers")
|
|
||||||
public List<Product> getProductsByManufacturers(@RequestBody List<Manufacturer> manufacturers) {
|
|
||||||
return productService.getProductsByManufacturers(manufacturers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public ProductDTO createProduct(@RequestBody @Valid ProductDTO productDTO) throws IOException{
|
|
||||||
return new ProductDTO(productService.addProduct(productDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ProductDTO updateProduct(@PathVariable Long id, @RequestBody @Valid ProductDTO productDTO) {
|
|
||||||
return new ProductDTO(productService.updateProduct(id, productDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/{id}/Manufacturer/{manufacturerId}")
|
|
||||||
public void addManufacturer(@PathVariable Long id, @PathVariable Long manufacturerId) {
|
|
||||||
productService.addManufacturersToProduct(id, manufacturerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}/Manufacturer/{manufacturerId}")
|
|
||||||
public void removeManufacturer(@PathVariable Long id, @PathVariable Long manufacturerId) {
|
|
||||||
productService.removeManufacturersToProduct(id, manufacturerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ProductDTO deleteProduct(@PathVariable Long id) {
|
|
||||||
return new ProductDTO(productService.deleteProduct(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping
|
|
||||||
public void deleteAll() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.controller;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class ProductDTO {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private Integer price;
|
|
||||||
|
|
||||||
private String photo;
|
|
||||||
|
|
||||||
@JsonProperty("categoryId")
|
|
||||||
private Long category_id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public ProductDTO() {}
|
|
||||||
|
|
||||||
public ProductDTO(Product product) {
|
|
||||||
this.id = product.getId();
|
|
||||||
this.name = product.getName();
|
|
||||||
this.price = product.getPrice();
|
|
||||||
this.photo = new String(product.getPhoto(), StandardCharsets.UTF_8);
|
|
||||||
this.category_id = product.getCategory().getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
|
|
||||||
public Integer getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhoto() {
|
|
||||||
return photo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getCategory_id() {
|
|
||||||
return category_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhoto(String photo) { this.photo = photo; }
|
|
||||||
|
|
||||||
public void setName(String name) { this.name = name; }
|
|
||||||
|
|
||||||
public void setPrice(Integer price) { this.price = price; }
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.models;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.CategoryDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ProductDTO;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Category {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public Category() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Category(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Category(CategoryDTO categoryDTO){
|
|
||||||
this.name = categoryDTO.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
Category category = (Category) o;
|
|
||||||
return Objects.equals(id, category.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Category{" +
|
|
||||||
"id=" + id +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.models;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.CategoryDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ManufacturerDTO;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Manufacturer {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER,
|
|
||||||
mappedBy = "manufacturerList")
|
|
||||||
private List<Product> productList;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String name;
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
|
|
||||||
public Manufacturer() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manufacturer(String name, String address) {
|
|
||||||
this.name = name;
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manufacturer(ManufacturerDTO manufacturerDTO){
|
|
||||||
this.name = manufacturerDTO.getName();
|
|
||||||
this.address = manufacturerDTO.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() { return id;}
|
|
||||||
|
|
||||||
public void setId(Long id) { this.id = id; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
|
|
||||||
public String getAddress() { return address; }
|
|
||||||
|
|
||||||
public List<Product> getProductList() { return productList; }
|
|
||||||
public void setName(String name) { this.name = name; }
|
|
||||||
|
|
||||||
public void setAddress(String address) { this.address = address; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Manufacturer manufacturer = (Manufacturer) o;
|
|
||||||
return Objects.equals(id, manufacturer.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Manufacturer{" +
|
|
||||||
"id=" + id +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", address='" + address + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.models;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ProductDTO;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.groups.ConvertGroup;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Product {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "category_id")
|
|
||||||
private Category category;
|
|
||||||
|
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
@JoinTable(name = "products_manufacturers",
|
|
||||||
joinColumns = @JoinColumn(name = "product_fk"),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "manufacturer_fk"))
|
|
||||||
private List<Manufacturer> manufacturerList;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private Integer price;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Lob
|
|
||||||
private byte[] photo;
|
|
||||||
|
|
||||||
public Product() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product(Integer price, byte[] photo, String name)
|
|
||||||
{
|
|
||||||
this.price = price;
|
|
||||||
this.photo = photo;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product(ProductDTO productDTO){
|
|
||||||
this.price = productDTO.getPrice();
|
|
||||||
this.photo = productDTO.getPhoto().getBytes();
|
|
||||||
this.name = productDTO.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() { return id; }
|
|
||||||
|
|
||||||
public Integer getPrice() { return price; }
|
|
||||||
|
|
||||||
public byte[] getPhoto() { return photo; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
|
|
||||||
public void setName(String name) { this.name = name; }
|
|
||||||
|
|
||||||
public void setPrice(Integer price) { this.price = price; }
|
|
||||||
|
|
||||||
public void setPhoto(byte[] photo) { this.photo = photo; }
|
|
||||||
|
|
||||||
public List<Manufacturer> getManufacturerList() { return manufacturerList; }
|
|
||||||
|
|
||||||
public Category getCategory() { return category; }
|
|
||||||
|
|
||||||
public void setCategory(Category category) { this.category = category; }
|
|
||||||
|
|
||||||
public void addManufacturer(Manufacturer manufacturer) {
|
|
||||||
manufacturerList.add(manufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeManufacturer(Manufacturer manufacturer) {
|
|
||||||
manufacturerList.remove(manufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Product product = (Product) o;
|
|
||||||
return Objects.equals(id, product.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Product{" +
|
|
||||||
"id=" + id +
|
|
||||||
", price='" + price + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface CategoryRepository extends JpaRepository<Category, Long> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ManufacturerRepository extends JpaRepository<Manufacturer, Long> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.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.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ProductRepository extends JpaRepository<Product, Long> {
|
|
||||||
@Query("SELECT p FROM Product p WHERE p.manufacturerList IN :manufacturers")
|
|
||||||
List<Product> findByManufacturers(@Param("manufacturers") List<Manufacturer> manufacturers);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
public class CategoryNotFoundException extends RuntimeException {
|
|
||||||
public CategoryNotFoundException(Long id) {
|
|
||||||
super(String.format("Category with id [%s] is not found", id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.CategoryDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ProductDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.repository.CategoryRepository;
|
|
||||||
import ru.ulstu.is.sbapp.Util.Validation.ValidatorUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CategoryService {
|
|
||||||
@Autowired
|
|
||||||
private final CategoryRepository categoryRepository;
|
|
||||||
@Autowired
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public CategoryService(CategoryRepository categoryRepository, ValidatorUtil validatorUtil) {
|
|
||||||
this.categoryRepository = categoryRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Category addCategory(CategoryDTO categoryDTO) throws IOException {
|
|
||||||
final Category category = new Category(categoryDTO);
|
|
||||||
validatorUtil.validate(category);
|
|
||||||
return categoryRepository.save(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Category addCategory(String name) {
|
|
||||||
final Category category = new Category(name);
|
|
||||||
validatorUtil.validate(category);
|
|
||||||
return categoryRepository.save(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveCategory(Category category) {
|
|
||||||
categoryRepository.save(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Category findCategory(Long id) {
|
|
||||||
final Optional<Category> client = categoryRepository.findById(id);
|
|
||||||
return client.orElseThrow(() -> new CategoryNotFoundException(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<Category> findAllCategories() {
|
|
||||||
return categoryRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Category updateCategory(Long id, String name) {
|
|
||||||
final Category currentCategory = findCategory(id);
|
|
||||||
currentCategory.setName(name);
|
|
||||||
validatorUtil.validate(currentCategory);
|
|
||||||
return categoryRepository.save(currentCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Category updateCategory(Long id, CategoryDTO categoryDTO) {
|
|
||||||
final Category currentCategory = findCategory(id);
|
|
||||||
currentCategory.setName(categoryDTO.getName());
|
|
||||||
validatorUtil.validate(currentCategory);
|
|
||||||
return categoryRepository.save(currentCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Category deleteCategory(Long id) {
|
|
||||||
final Category currentCategory = findCategory(id);
|
|
||||||
categoryRepository.delete(currentCategory);
|
|
||||||
return currentCategory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllCategories() {
|
|
||||||
categoryRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
public class ManufacturerNotFoundException extends RuntimeException {
|
|
||||||
public ManufacturerNotFoundException(Long id) {
|
|
||||||
super(String.format("Manufacturer with id [%s] is not found", id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ManufacturerDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ProductDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.repository.ManufacturerRepository;
|
|
||||||
import ru.ulstu.is.sbapp.Util.Validation.ValidatorUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ManufacturerService {
|
|
||||||
@Autowired
|
|
||||||
private final ManufacturerRepository manufacturerRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public ManufacturerService(ManufacturerRepository manufacturerRepository, ValidatorUtil validatorUtil) {
|
|
||||||
this.manufacturerRepository = manufacturerRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Manufacturer addManufacturer(String name, String address) {
|
|
||||||
final Manufacturer manufacturer = new Manufacturer(name, address);
|
|
||||||
validatorUtil.validate(manufacturer);
|
|
||||||
return manufacturerRepository.save(manufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Manufacturer addManufacturer(ManufacturerDTO manufacturerDTO) throws IOException {
|
|
||||||
final Manufacturer manufacturer = new Manufacturer(manufacturerDTO);
|
|
||||||
validatorUtil.validate(manufacturer);
|
|
||||||
return manufacturerRepository.save(manufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveManufacturer(Manufacturer manufacturer) {
|
|
||||||
manufacturerRepository.save(manufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Manufacturer findManufacturer(Long id) {
|
|
||||||
final Optional<Manufacturer> client = manufacturerRepository.findById(id);
|
|
||||||
return client.orElseThrow(() -> new ManufacturerNotFoundException(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<Manufacturer> findAllManufacturers() {
|
|
||||||
return manufacturerRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Manufacturer updateManufacturer(Long id, String name, String address) {
|
|
||||||
final Manufacturer currentManufacturer = findManufacturer(id);
|
|
||||||
currentManufacturer.setName(name);
|
|
||||||
currentManufacturer.setAddress(address);
|
|
||||||
validatorUtil.validate(currentManufacturer);
|
|
||||||
return manufacturerRepository.save(currentManufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Manufacturer updateManufacturer(Long id, ManufacturerDTO manufacturerDTO) {
|
|
||||||
final Manufacturer currentManufacturer = findManufacturer(id);
|
|
||||||
currentManufacturer.setName(manufacturerDTO.getName());
|
|
||||||
currentManufacturer.setAddress(manufacturerDTO.getAddress());
|
|
||||||
validatorUtil.validate(currentManufacturer);
|
|
||||||
return manufacturerRepository.save(currentManufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Manufacturer deleteManufacturer(Long id) {
|
|
||||||
final Manufacturer currentManufacturer = findManufacturer(id);
|
|
||||||
manufacturerRepository.delete(currentManufacturer);
|
|
||||||
return currentManufacturer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllManufacturers() {
|
|
||||||
manufacturerRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
public class ProductNotFoundException extends RuntimeException {
|
|
||||||
public ProductNotFoundException(Long id) {
|
|
||||||
super(String.format("Product with id [%s] is not found", id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.HardwareShop.services;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.controller.ProductDTO;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.repository.ManufacturerRepository;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.repository.ProductRepository;
|
|
||||||
import ru.ulstu.is.sbapp.Util.Validation.ValidatorUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ProductService {
|
|
||||||
@Autowired
|
|
||||||
private final ProductRepository productRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private final ManufacturerService manufacturerService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private final CategoryService categoryService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public ProductService(ProductRepository productRepository, ValidatorUtil validatorUtil, ManufacturerService manufacturerService, CategoryService categoryService) {
|
|
||||||
this.productRepository = productRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
this.manufacturerService = manufacturerService;
|
|
||||||
this.categoryService = categoryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Product addProduct(ProductDTO productDTO) throws IOException {
|
|
||||||
final Product product = new Product(productDTO);
|
|
||||||
product.setCategory(categoryService.findCategory(productDTO.getCategory_id()));
|
|
||||||
validatorUtil.validate(product);
|
|
||||||
return productRepository.save(product);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Product addProduct(Integer price, byte[] image, String name) {
|
|
||||||
final Product product = new Product(price, image, name);
|
|
||||||
validatorUtil.validate(product);
|
|
||||||
return productRepository.save(product);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Product findProduct(Long id) {
|
|
||||||
final Optional<Product> post = productRepository.findById(id);
|
|
||||||
return post.orElseThrow(() -> new ProductNotFoundException(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveProduct(Product product) {
|
|
||||||
productRepository.save(product);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<Product> findAllProducts() {
|
|
||||||
return productRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<Product> getProductsByManufacturers(List<Manufacturer> manufacturers) {
|
|
||||||
return productRepository.findByManufacturers(manufacturers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Product updateProduct(Long id, ProductDTO productDTO) {
|
|
||||||
final Product currentProduct = findProduct(id);
|
|
||||||
currentProduct.setName(productDTO.getName());
|
|
||||||
currentProduct.setPrice(productDTO.getPrice());
|
|
||||||
currentProduct.setPhoto(productDTO.getPhoto().getBytes(StandardCharsets.UTF_8));
|
|
||||||
currentProduct.setCategory(categoryService.findCategory(productDTO.getCategory_id()));
|
|
||||||
validatorUtil.validate(currentProduct);
|
|
||||||
return productRepository.save(currentProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Product updateProduct(Long id, Integer price, byte[] image) {
|
|
||||||
final Product currentProduct = findProduct(id);
|
|
||||||
currentProduct.setPrice(price);
|
|
||||||
/*currentProduct.setPhoto(image);*/
|
|
||||||
validatorUtil.validate(currentProduct);
|
|
||||||
return productRepository.save(currentProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Product deleteProduct(Long id) {
|
|
||||||
final Product currentProduct = findProduct(id);
|
|
||||||
productRepository.delete(currentProduct);
|
|
||||||
return currentProduct;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllProducts() {
|
|
||||||
productRepository.deleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void addManufacturersToProduct(Long id, Long manufacturer_id) {
|
|
||||||
final Product currentProduct = findProduct(id);
|
|
||||||
final Manufacturer manufacturer = manufacturerService.findManufacturer(manufacturer_id);
|
|
||||||
currentProduct.addManufacturer(manufacturer);
|
|
||||||
validatorUtil.validate(currentProduct);
|
|
||||||
productRepository.save(currentProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void removeManufacturersToProduct(Long id, Long manufacturer_id) {
|
|
||||||
final Product currentProduct = findProduct(id);
|
|
||||||
currentProduct.removeManufacturer(manufacturerService.findManufacturer(manufacturer_id));
|
|
||||||
validatorUtil.validate(currentProduct);
|
|
||||||
productRepository.save(currentProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Manufacturer> getProductManufacturers(Long id){
|
|
||||||
return productRepository.findById(id).get().getManufacturerList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,4 +13,38 @@ public class SbappApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SbappApplication.class, args);
|
SpringApplication.run(SbappApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/hello")
|
||||||
|
public String hello() {
|
||||||
|
return "Hello, i'm working!";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/ToUpper")
|
||||||
|
public String ToUpper(@RequestParam(value = "", defaultValue = "default") String text) {
|
||||||
|
return String.format(text).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/calc")
|
||||||
|
public Integer calc(@RequestParam(defaultValue = "10") Integer num1,
|
||||||
|
@RequestParam(defaultValue = "10") Integer num2) {
|
||||||
|
return num1 + num2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/concate")
|
||||||
|
public String concate(@RequestParam String text) {
|
||||||
|
return "Word-"+ text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/divider")
|
||||||
|
public String IsInt(@RequestParam int num1,
|
||||||
|
@RequestParam(defaultValue = "1") int num2) {
|
||||||
|
if (num1 % num2 == 0)
|
||||||
|
{
|
||||||
|
return String.format("Делится на цело, результат: %s", num1 / num2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return String.format("Неделится на цело, результат: %s", num1 / num2 + " Остаток: " + num1 % num2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.Util.Errors;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
||||||
|
|
||||||
import ru.ulstu.is.sbapp.Util.Validation.ValidationException;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@ControllerAdvice
|
|
||||||
public class AdviceController {
|
|
||||||
@ExceptionHandler({
|
|
||||||
ValidationException.class
|
|
||||||
})
|
|
||||||
public ResponseEntity<Object> handleException(Throwable e) {
|
|
||||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
||||||
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
|
|
||||||
final ValidationException validationException = new ValidationException(
|
|
||||||
e.getBindingResult().getAllErrors().stream()
|
|
||||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
|
||||||
.collect(Collectors.toSet()));
|
|
||||||
return handleException(validationException);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public ResponseEntity<Object> handleUnknownException(Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.Util.Validation;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ValidationException extends RuntimeException {
|
|
||||||
public ValidationException(Set<String> errors) {
|
|
||||||
super(String.join("\n", errors));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp.Util.Validation;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
|
||||||
import javax.validation.Validation;
|
|
||||||
import javax.validation.Validator;
|
|
||||||
import javax.validation.ValidatorFactory;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ValidatorUtil {
|
|
||||||
private final Validator validator;
|
|
||||||
|
|
||||||
public ValidatorUtil() {
|
|
||||||
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
|
|
||||||
this.validator = factory.getValidator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void validate(T object) {
|
|
||||||
final Set<ConstraintViolation<T>> errors = validator.validate(object);
|
|
||||||
if (!errors.isEmpty()) {
|
|
||||||
throw new ValidationException(errors.stream()
|
|
||||||
.map(ConstraintViolation::getMessage)
|
|
||||||
.collect(Collectors.toSet()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class WebConfiguration implements WebMvcConfigurer {
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**").allowedMethods("*");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1 @@
|
|||||||
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
|
|
||||||
|
3
src/main/resources/static/styles.css
Normal file
3
src/main/resources/static/styles.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
h1 {
|
||||||
|
color: red;
|
||||||
|
}
|
7
src/main/resources/static/test.js
Normal file
7
src/main/resources/static/test.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
function test() {
|
||||||
|
fetch("http://localhost:8080/hello", {
|
||||||
|
mode:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
11
src/main/resources/templates/index.html
Normal file
11
src/main/resources/templates/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th = "http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="/styles.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1> IA WORK!</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -1,63 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
|
||||||
|
|
||||||
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.sbapp.HardwareShop.models.Category;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.CategoryService;
|
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
public class JpaCategoryTests {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(JpaCategoryTests.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CategoryService categoryService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCategoryCreate() {
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
final Category category = categoryService.addCategory("Электроника");
|
|
||||||
log.info(category.toString());
|
|
||||||
Assertions.assertNotNull(category.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCategoryRead() {
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
final Category category = categoryService.addCategory("Электроника");
|
|
||||||
log.info(category.toString());
|
|
||||||
final Category findCategory = categoryService.findCategory(category.getId());
|
|
||||||
log.info(findCategory.toString());
|
|
||||||
Assertions.assertEquals(category, findCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCategoryReadNotFound() {
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
Assertions.assertThrows(EntityNotFoundException.class, () -> categoryService.findCategory(-1L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCategoryReadAll() {
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
categoryService.addCategory("Электроника");
|
|
||||||
categoryService.addCategory("Электроника 2");
|
|
||||||
final List<Category> categoryList = categoryService.findAllCategories();
|
|
||||||
log.info(categoryList.toString());
|
|
||||||
Assertions.assertEquals(categoryList.size(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCategoryReadAllEmpty() {
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
final List<Category> categoryList = categoryService.findAllCategories();
|
|
||||||
log.info(categoryList.toString());
|
|
||||||
Assertions.assertEquals(categoryList.size(), 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
|
||||||
|
|
||||||
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.sbapp.HardwareShop.models.Manufacturer;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.ManufacturerService;
|
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
public class JpaManufacturerTests {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(JpaManufacturerTests.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ManufacturerService manufacturerService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testManufacturerCreate() {
|
|
||||||
manufacturerService.deleteAllManufacturers();
|
|
||||||
final Manufacturer manufacturer = manufacturerService.addManufacturer("Производитель 1", "ул.Камышинская д.107");
|
|
||||||
log.info(manufacturer.toString());
|
|
||||||
Assertions.assertNotNull(manufacturer.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testManufacturerRead() {
|
|
||||||
manufacturerService.deleteAllManufacturers();
|
|
||||||
final Manufacturer manufacturer = manufacturerService.addManufacturer("Производитель 1", "ул.Камышинская д.107");
|
|
||||||
log.info(manufacturer.toString());
|
|
||||||
final Manufacturer findManufacturer = manufacturerService.findManufacturer(manufacturer.getId());
|
|
||||||
log.info(findManufacturer.toString());
|
|
||||||
Assertions.assertEquals(manufacturer, findManufacturer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testManufacturerReadNotFound() {
|
|
||||||
manufacturerService.deleteAllManufacturers();
|
|
||||||
Assertions.assertThrows(EntityNotFoundException.class, () -> manufacturerService.findManufacturer(-1L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testManufacturerReadAll() {
|
|
||||||
manufacturerService.deleteAllManufacturers();
|
|
||||||
manufacturerService.addManufacturer("Производитель 1", "ул.Камышинская д.107");
|
|
||||||
manufacturerService.addManufacturer("Производитель 2", "ул.Камышинская д.108");
|
|
||||||
final List<Manufacturer> manufacturerList = manufacturerService.findAllManufacturers();
|
|
||||||
log.info(manufacturerList.toString());
|
|
||||||
Assertions.assertEquals(manufacturerList.size(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testManufacturerReadAllEmpty() {
|
|
||||||
manufacturerService.deleteAllManufacturers();
|
|
||||||
final List<Manufacturer> manufacturerList = manufacturerService.findAllManufacturers();
|
|
||||||
log.info(manufacturerList.toString());
|
|
||||||
Assertions.assertEquals(manufacturerList.size(), 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
|
||||||
|
|
||||||
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.FilteredClassLoader;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Category;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.CategoryService;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.models.Product;
|
|
||||||
import ru.ulstu.is.sbapp.HardwareShop.services.ProductService;
|
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
public class JpaProductTests {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(JpaProductTests.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ProductService productService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CategoryService categoryService;
|
|
||||||
|
|
||||||
private MultipartFile ConvertFile() throws IOException {
|
|
||||||
File file = new File("C:\\Users\\aleyc\\IdeaProjects\\IP_Aleikin_PIbd-22\\src\\test\\java\\ru\\ulstu\\is\\sbapp\\cart.png");
|
|
||||||
String name = "file";
|
|
||||||
String originalFileName = file.getName();
|
|
||||||
String contentType = "image/jpeg";
|
|
||||||
byte[] content = new byte[(int) file.length()];
|
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
|
||||||
inputStream.read(content);
|
|
||||||
MultipartFile multipartFile = new MockMultipartFile(name, originalFileName, contentType, content);
|
|
||||||
return multipartFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductCreate() throws Exception {
|
|
||||||
MultipartFile localFile = ConvertFile();
|
|
||||||
String strImage;
|
|
||||||
strImage = ("data:" + localFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(localFile.getBytes()));
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
final Product product = productService.addProduct(15000, strImage.getBytes(), "1412");
|
|
||||||
log.info(product.toString());
|
|
||||||
Assertions.assertNotNull(product.getId());
|
|
||||||
Assertions.assertNotNull(product.getPhoto());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*@Test
|
|
||||||
void testProductRead() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
final Product product = productService.addProduct(15000);
|
|
||||||
log.info(product.toString());
|
|
||||||
final Product findProduct = productService.findProduct(product.getId());
|
|
||||||
log.info(findProduct.toString());
|
|
||||||
Assertions.assertEquals(product, findProduct);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductReadNotFound() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
Assertions.assertThrows(EntityNotFoundException.class, () -> productService.findProduct(-1L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductReadAll() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
productService.addProduct(15000);
|
|
||||||
productService.addProduct(20000);
|
|
||||||
final List<Product> productList = productService.findAllProducts();
|
|
||||||
log.info(productList.toString());
|
|
||||||
Assertions.assertEquals(productList.size(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductReadAllEmpty() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
final List<Product> productList = productService.findAllProducts();
|
|
||||||
log.info(productList.toString());
|
|
||||||
Assertions.assertEquals(productList.size(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductUpdate() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
final Product product = productService.addProduct(15000);
|
|
||||||
log.info(product.toString());
|
|
||||||
productService.updateProduct(product.getId(), 20000);
|
|
||||||
log.info(product.toString());
|
|
||||||
Assertions.assertEquals(product.getPrice(), 20000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testProductAddCategory() {
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
final Product product = productService.addProduct(15000);
|
|
||||||
final Category category = categoryService.addCategory("Электроника");
|
|
||||||
product.addCategory(category);
|
|
||||||
log.info(product.toString() + product.getCategory().getName());
|
|
||||||
Assertions.assertEquals(product.getCategory().getName(), "Электроника");
|
|
||||||
productService.deleteAllProducts();
|
|
||||||
categoryService.deleteAllCategories();
|
|
||||||
}*/
|
|
||||||
}
|
|
@ -1,91 +1,13 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
package ru.ulstu.is.sbapp;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import ru.ulstu.is.sbapp.calc.service.CalculatorService;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class SbappApplicationTests {
|
class SbappApplicationTests {
|
||||||
@Autowired
|
|
||||||
CalculatorService calculatorService;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void IntSum() {
|
void contextLoads() {
|
||||||
final String res = calculatorService.getSum(3, 6, "int").toString();
|
|
||||||
Assertions.assertEquals("9", res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void IntDiff() {
|
|
||||||
final String res = calculatorService.getDiff(15, 3, "int").toString();
|
|
||||||
Assertions.assertEquals("12", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void IntMul() {
|
|
||||||
final String res = calculatorService.getMul(12, 3, "int").toString();
|
|
||||||
Assertions.assertEquals("36", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void IntDiv() {
|
|
||||||
final String res = calculatorService.getDiv(12, 3, "int").toString();
|
|
||||||
Assertions.assertEquals("4", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void StringSum() {
|
|
||||||
final String res = calculatorService.getSum("abc", 6, "string").toString();
|
|
||||||
Assertions.assertEquals("abc6", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void StringDiff() {
|
|
||||||
final String res = calculatorService.getDiff("abc", 2, "string").toString();
|
|
||||||
Assertions.assertEquals("a", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void StringMul() {
|
|
||||||
final String res = calculatorService.getMul("abc", 3, "string").toString();
|
|
||||||
Assertions.assertEquals("abcabcabc", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void StringDiv() {
|
|
||||||
final String res = calculatorService.getDiv("abc", 3, "string").toString();
|
|
||||||
Assertions.assertEquals("a", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void FloatArraySum() {
|
|
||||||
final String res = calculatorService.getSum("3.2;5.6", 3, "floatArray").toString();
|
|
||||||
Assertions.assertEquals("[6.2, 8.6]", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void FloatArrayDiff() {
|
|
||||||
final String res = calculatorService.getDiff("3.2;5.6", 2, "floatArray").toString();
|
|
||||||
Assertions.assertEquals("[1.2, 3.6]", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void FloatArrayMul() {
|
|
||||||
final String res = calculatorService.getMul("3.2;5.6", 2, "floatArray").toString();
|
|
||||||
Assertions.assertEquals("[6.4, 11.2]", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void FloatArrayDiv() {
|
|
||||||
final String res = calculatorService.getDiv("3.2;5.6", 2, "floatArray").toString();
|
|
||||||
Assertions.assertEquals("[1.6, 2.8]", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testErrorErrorWired() {
|
|
||||||
Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> calculatorService.getSum(1, 2, "date"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Loading…
Reference in New Issue
Block a user