Перенес все на новую версию, + сделал MVC
This commit is contained in:
parent
d97e9324a7
commit
b9f3c91d08
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -1,4 +0,0 @@
|
||||
2023-05-02 12:16:50 jdbc[13]: exception
|
||||
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "SELECT * FROM BUYER CAR [*]CARS_STORES"
|
||||
Syntax error in SQL statement "SELECT * FROM BUYER CAR [*]CARS_STORES"; SQL statement:
|
||||
SELECT * FROM BUYER CAR CARS_STORES [42000-210]
|
24
frontend/.gitignore
vendored
24
frontend/.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,19 +0,0 @@
|
||||
{
|
||||
"posts": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "json-server",
|
||||
"author": "typicode"
|
||||
}
|
||||
],
|
||||
"comments": [
|
||||
{
|
||||
"id": 1,
|
||||
"body": "some comment",
|
||||
"postId": 1
|
||||
}
|
||||
],
|
||||
"profile": {
|
||||
"name": "typicode"
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"
|
||||
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.min.js"
|
||||
integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/node_modules/bootstrap/dist/css/bootstrap.min.css"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="/node_modules/@fortawesome/fontawesome-free/css/all.min.css"
|
||||
/>
|
||||
<title>Кашин Максим ПИбд-22</title>
|
||||
</head>
|
||||
<body class="d-flex flex-column h-100">
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
9838
frontend/package-lock.json
generated
9838
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,29 +0,0 @@
|
||||
{
|
||||
"name": "spa-react",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"fake-server": "json-server --watch data.json -p 8081",
|
||||
"start": "npm-run-all --parallel dev fake-server",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.4.4",
|
||||
"axios": "^1.1.3",
|
||||
"bootstrap": "^5.2.2",
|
||||
"@fortawesome/fontawesome-free": "^6.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.24",
|
||||
"@types/react-dom": "^18.0.8",
|
||||
"vite": "^3.2.3",
|
||||
"@vitejs/plugin-react": "^2.2.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"json-server": "^0.17.1"
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
nav {
|
||||
background-color: #708090;
|
||||
}
|
||||
main {
|
||||
background-color: #ffffff;
|
||||
/* min-height: 90vh; */
|
||||
}
|
||||
footer {
|
||||
background-color: #708090;
|
||||
color: black;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.size {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.card {
|
||||
background-color: #bdb1b1;
|
||||
border-color: #8c7b7b;
|
||||
}
|
||||
.card-body {
|
||||
background-color: #8c7b7b;
|
||||
}
|
||||
h1 {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
#banner {
|
||||
margin: 0px 15px 15px 15px;
|
||||
padding-top: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#banner img {
|
||||
border-radius: 5px;
|
||||
}
|
||||
#banner img.show {
|
||||
width: 100%;
|
||||
opacity: 1;
|
||||
transition: opacity 1s, visibility 0s;
|
||||
}
|
||||
|
||||
#banner img.hide {
|
||||
height: 0;
|
||||
width: 0;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 1s, visibility 0s 1s;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.btn {
|
||||
padding: 1px 5px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 768px) and (max-width: 991px) {
|
||||
.btn {
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 992px) and (max-width: 1199px) {
|
||||
.btn {
|
||||
padding: 6px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.42857143;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 1200px) {
|
||||
.btn {
|
||||
padding: 10px 16px;
|
||||
font-size: 18px;
|
||||
line-height: 1.3333333;
|
||||
border-radius: 6px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.tem {
|
||||
padding-right: 50px;
|
||||
}
|
||||
}
|
||||
.vl {
|
||||
border-left: 5px solid;
|
||||
height: 100vh;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import './App.css';
|
||||
import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom';
|
||||
import Header from './components/common/Header';
|
||||
import Footer from "./components/common/Footer";
|
||||
import CatalogBuyers from './components/catalogs/CatalogBuyers';
|
||||
import { useState } from 'react';
|
||||
import CarInfo from './components/catalogs/CarInfo';
|
||||
import CatalogStores from './components/catalogs/CatalogStores';
|
||||
import Find from './components/catalogs/Find';
|
||||
|
||||
function Router(props) {
|
||||
return useRoutes(props.rootRoute);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [car,setCar] = useState([]);
|
||||
const routes = [
|
||||
{ index: true, element: <CatalogBuyers /> },
|
||||
|
||||
{ path: "catalogs/store", element: <CatalogStores/> , label: "Магазины" },
|
||||
{ path: "catalogs/buyer", element: <CatalogBuyers />, label: "Покупатели" },
|
||||
{ path: "catalogs/car", element: <CarInfo car={car} setCar={setCar}/>, label: "Машины" },
|
||||
{ path: "catalogs/find", element: <Find/>, label: "Поиск" }
|
||||
];
|
||||
const links = routes.filter(route => route.hasOwnProperty('label'));
|
||||
const rootRoute = [
|
||||
{ path: '/', element: render(links), children: routes }
|
||||
];
|
||||
|
||||
function render(links) {
|
||||
return (
|
||||
<>
|
||||
<Header links={links} />
|
||||
<div className="container-fluid p-0">
|
||||
<Outlet />
|
||||
</div>
|
||||
<Footer></Footer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Router rootRoute={ rootRoute } />
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
import { useState, useEffect, Component } from "react";
|
||||
import CatalogCar from "./CatalogCars";
|
||||
import Store from "../../models/Store";
|
||||
import Buyer from "../../models/Buyer";
|
||||
import Car from "../../models/Car";
|
||||
import DataService from "../../services/DataService";
|
||||
export default function Menustores(props) {
|
||||
const url = "/car";
|
||||
const prodUrl = "/store";
|
||||
const workUrl = "/buyer"
|
||||
const transformer = (data) => new Car(data);
|
||||
const catalogProdHeaders = [
|
||||
{ name: "storeName", label: "Название магазина" },
|
||||
];
|
||||
const catalogWorkHeaders = [
|
||||
{ name: "buyerFirstName", label: "Имя" },
|
||||
{ name: "buyerSecondName", label: "Фамилия" },
|
||||
];
|
||||
const [data, setData] = useState(new Car());
|
||||
const [store, setStore] = useState([]);
|
||||
const [workStore, setWorkStore] = useState([]);
|
||||
const [buyer, setBuyer] = useState([]);
|
||||
const [workBuyer, setWorkBuyer] = useState([]);
|
||||
useEffect(() => {
|
||||
DataService.readAll(prodUrl, (data) => new Store(data)).then(
|
||||
(data) => setStore(data)
|
||||
);
|
||||
DataService.readAll(workUrl, (data) => new Buyer(data)).then(
|
||||
(data) => setBuyer(data)
|
||||
);
|
||||
}, []);
|
||||
|
||||
function handleOnAdd() {
|
||||
setData(new Car());
|
||||
setWorkStore([]);
|
||||
setWorkBuyer([]);
|
||||
}
|
||||
function handleOnEdit(data) {
|
||||
setData(new Car(data));
|
||||
}
|
||||
|
||||
function handleFormChange(event) {
|
||||
setData({ ...data, [event.target.id]: event.target.value });
|
||||
}
|
||||
|
||||
function handleUpdateStores(value) {
|
||||
let temp = data.storeDTOList.filter((x) => x.id != value.id);
|
||||
data.storeDTOList = [];
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
data.storeDTOList.push(temp[i]);
|
||||
}
|
||||
data.storeDTOList.push(value);
|
||||
setData(data);
|
||||
console.log(data);
|
||||
setWorkStore();
|
||||
}
|
||||
function setCar() {
|
||||
data.storeDTOList = [];
|
||||
for (let i = 0; i < workStore.length; i++) {
|
||||
data.storeDTOList.push(workStore[i]);
|
||||
}
|
||||
data.buyerDTOList = [];
|
||||
for (let i = 0; i < workBuyer.length; i++) {
|
||||
data.buyerDTOList.push(workBuyer[i]);
|
||||
}
|
||||
setData(data);
|
||||
}
|
||||
|
||||
function handleDeleteStores(value) {
|
||||
let temp = data.storeDTOList.filter((x) => x.id != value);
|
||||
data.storeDTOList = [];
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
data.storeDTOList.push(temp[i]);
|
||||
}
|
||||
console.log(data);
|
||||
setData(data);
|
||||
setWorkStore(workStore.filter((x) => x.id !== value));
|
||||
console.log(workStore);
|
||||
}
|
||||
|
||||
function handleUpdateBuyers(value){
|
||||
let temp = data.buyerDTOList.filter((x) => x.id != value.id);
|
||||
data.buyerDTOList = [];
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
data.buyerDTOList.push(temp[i]);
|
||||
}
|
||||
data.buyerDTOList.push(value);
|
||||
setData(data);
|
||||
console.log(data);
|
||||
setWorkBuyer(data.buyerDTOList);
|
||||
console.log(workBuyer);
|
||||
}
|
||||
|
||||
function handleDeleteBuyers(value) {
|
||||
let temp = data.buyerDTOList.filter((x) => x.id != value);
|
||||
data.buyerDTOList = [];
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
data.buyerDTOList.push(temp[i]);
|
||||
}
|
||||
console.log(data);
|
||||
setData(data);
|
||||
setWorkBuyer(workBuyer.filter((x) => x.id !== value));
|
||||
console.log(workBuyer);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="flex-shrink-0">
|
||||
<CatalogCar
|
||||
url={url}
|
||||
transformer={transformer}
|
||||
data={data}
|
||||
onAdd={handleOnAdd}
|
||||
onEdit={handleOnEdit}
|
||||
handleFormChange={handleFormChange}
|
||||
set={setCar}
|
||||
car={props.car}
|
||||
setCar={props.setCar}
|
||||
|
||||
store={store}
|
||||
catalogProdHeaders={catalogProdHeaders}
|
||||
workStore={workStore}
|
||||
setWorkStore={setWorkStore}
|
||||
updateStores={handleUpdateStores}
|
||||
deleteStores={handleDeleteStores}
|
||||
|
||||
buyer={buyer}
|
||||
catalogWorkHeaders={catalogWorkHeaders}
|
||||
workBuyer={workBuyer}
|
||||
setWorkBuyer={setWorkBuyer}
|
||||
updateBuyers={handleUpdateBuyers}
|
||||
deleteBuyers={handleDeleteBuyers}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import Toolbar from "../common/Toolbar";
|
||||
import Table from "../common/Table";
|
||||
import Modal from "../common/Modal";
|
||||
import DataService from '../../services/DataService';
|
||||
|
||||
export default function CatalogW(props) {
|
||||
const [items, setItems] = useState([]);
|
||||
const [modalHeader, setModalHeader] = useState('');
|
||||
const [modalConfirm, setModalConfirm] = useState('');
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [isEdit, setEdit] = useState(false);
|
||||
|
||||
let selectedItems = [];
|
||||
|
||||
useEffect(() => {
|
||||
loadItems();
|
||||
}, []);
|
||||
|
||||
function loadItems() {
|
||||
DataService.readAll(props.getAllUrl, props.transformer)
|
||||
.then(data => setItems(data));
|
||||
}
|
||||
|
||||
function saveItem() {
|
||||
console.log(props.data);
|
||||
if (!isEdit) {
|
||||
DataService.create(props.getAllUrl, props.data).then(() => loadItems());
|
||||
} else {
|
||||
DataService.update(props.url + props.data.id, props.data).then(() => loadItems());
|
||||
}
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
setEdit(false);
|
||||
setModalHeader('Добавление элемента');
|
||||
setModalConfirm('Добавить');
|
||||
setModalVisible(true);
|
||||
props.onAdd();
|
||||
}
|
||||
|
||||
function handleEdit() {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
edit(selectedItems[0]);
|
||||
}
|
||||
|
||||
function edit(editedId) {
|
||||
DataService.read(props.url + editedId, props.transformer)
|
||||
.then(data => {
|
||||
setEdit(true);
|
||||
setModalHeader('Редактирование элемента');
|
||||
setModalConfirm('Сохранить');
|
||||
setModalVisible(true);
|
||||
props.onEdit(data);
|
||||
});
|
||||
}
|
||||
|
||||
function handleRemove() {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (confirm('Удалить выбранные элементы?')) {
|
||||
const promises = [];
|
||||
selectedItems.forEach(item => {
|
||||
promises.push(DataService.delete(props.url + item));
|
||||
});
|
||||
Promise.all(promises).then((results) => {
|
||||
selectedItems.length = 0;
|
||||
loadItems();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleTableClick(tableSelectedItems) {
|
||||
selectedItems = tableSelectedItems;
|
||||
}
|
||||
|
||||
function handleTableDblClick(tableSelectedItem) {
|
||||
edit(tableSelectedItem);
|
||||
}
|
||||
|
||||
function handleModalHide() {
|
||||
setModalVisible(false);
|
||||
}
|
||||
|
||||
function handleModalDone() {
|
||||
saveItem();
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Toolbar
|
||||
onAdd={handleAdd}
|
||||
onEdit={handleEdit}
|
||||
onRemove={handleRemove}/>
|
||||
<Table
|
||||
headers={props.headers}
|
||||
items={items}
|
||||
selectable={true}
|
||||
onClick={handleTableClick}
|
||||
onDblClick={handleTableDblClick}/>
|
||||
<Modal
|
||||
header={modalHeader}
|
||||
confirm={modalConfirm}
|
||||
visible={modalVisible}
|
||||
onHide={handleModalHide}
|
||||
onDone={handleModalDone}>
|
||||
{props.children}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Catalog from './Catalog';
|
||||
import Buyer from '../../models/Buyer';
|
||||
import DataService from '../../services/DataService';
|
||||
|
||||
export default function CatalogBuyers(props) {
|
||||
const getAllUrl = '/buyer';
|
||||
const url = '/buyer/';
|
||||
const transformer = (data) => new Buyer(data);
|
||||
const catalogBuyerHeaders = [
|
||||
{ name: 'buyerFirstName', label: 'Имя' },
|
||||
{ name: 'buyerSecondName', label: 'Фамилия' },
|
||||
];
|
||||
|
||||
const [data, setData] = useState(new Buyer());
|
||||
|
||||
function handleOnAdd() {
|
||||
console.log("create buyer: " + data.buyerFirstName + "|" + data.buyerSecondName);
|
||||
setData(new Buyer());
|
||||
}
|
||||
|
||||
function handleOnEdit(data) {
|
||||
setData(new Buyer(data));
|
||||
}
|
||||
|
||||
function handleFormChange(event) {
|
||||
setData({ ...data, [event.target.id]: event.target.value })
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="flex-shrink-0" style={{ backgroundColor: "white" }}>
|
||||
<Catalog
|
||||
headers={catalogBuyerHeaders}
|
||||
getAllUrl={getAllUrl}
|
||||
url={url}
|
||||
transformer={transformer}
|
||||
data={data}
|
||||
onAdd={handleOnAdd}
|
||||
onEdit={handleOnEdit}>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="buyerFirstName" className="form-label">Имя покупателя</label>
|
||||
<input type="text" id="buyerFirstName" className="form-control" required
|
||||
value={data.buyerFirstName} onChange={handleFormChange}/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="buyerSecondName" className="form-label">Фамилия покупателя</label>
|
||||
<input type="text" id="buyerSecondName" className="form-control" required
|
||||
value={data.buyerSecondName} onChange={handleFormChange}/>
|
||||
</div>
|
||||
</Catalog>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,313 +0,0 @@
|
||||
import { useState, useEffect, Component } from "react";
|
||||
import ToolbarStore from "../common/ToolbarStore";
|
||||
import Card from "../common/Card";
|
||||
import Modal from "../common/Modal";
|
||||
import DataService from "../../services/DataService";
|
||||
import Table from "../common/Table";
|
||||
import Toolbar from "../common/Toolbar";
|
||||
|
||||
export default function catalogP(props) {
|
||||
const [items, setItems] = useState([]);
|
||||
const [modalHeader, setModalHeader] = useState("");
|
||||
const [modalConfirm, setModalConfirm] = useState("");
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [isEdit, setEdit] = useState(false);
|
||||
const [StoreL, setStoreL] = useState({});
|
||||
const [BuyerL, setBuyerL] = useState({});
|
||||
useEffect(() => {
|
||||
loadItems();
|
||||
}, []);
|
||||
function loadItems() {
|
||||
DataService.readAll(props.url, props.transformer).then((data) =>{
|
||||
setItems(data);
|
||||
});
|
||||
DataService.readAll(props.url, props.transformer).then((data) =>
|
||||
setItems(data));
|
||||
}
|
||||
const catalogCarHeaders = [
|
||||
{ name: 'carName', label: 'Название' },
|
||||
// { name: 'storeDTOList.length', label: 'Количество магазинов'}
|
||||
];
|
||||
let selectedItems = [];
|
||||
async function saveItem() {
|
||||
console.log(props.data);
|
||||
if (!isEdit) {
|
||||
await props.set();
|
||||
DataService.create(props.url, props.data).then(() => loadItems());
|
||||
} else {
|
||||
await props.set();
|
||||
DataService.update(props.url + "/" + props.data.id, props.data).then(() =>
|
||||
loadItems()
|
||||
);
|
||||
}
|
||||
}
|
||||
function handleRemoveCard(id) {
|
||||
if (confirm("Удалить выбранные элементы?")) {
|
||||
DataService.delete(props.url + "/" + id).then(() => {
|
||||
loadItems();
|
||||
});
|
||||
}
|
||||
}
|
||||
function handleRemove() {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (confirm('Удалить выбранные элементы?')) {
|
||||
const promises = [];
|
||||
selectedItems.forEach(item => {
|
||||
promises.push(DataService.delete(props.url + "/" + item));
|
||||
});
|
||||
Promise.all(promises).then((results) => {
|
||||
selectedItems.length = 0;
|
||||
loadItems();
|
||||
});
|
||||
}
|
||||
}
|
||||
function handleAdd() {
|
||||
setEdit(false);
|
||||
setModalHeader("Добавление элемента");
|
||||
setModalConfirm("Добавить");
|
||||
setModalVisible(true);
|
||||
props.onAdd();
|
||||
}
|
||||
|
||||
function handleEdit(id) {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
setStoreL(
|
||||
props.workStore.filter((x) => x.id == selectedItems[0])[0]
|
||||
);
|
||||
}
|
||||
|
||||
function edit(editedId) {
|
||||
DataService.read(props.url+ "/" + editedId, props.transformer).then((data) => {
|
||||
for(let i = 0; i < data.storeDTOList.length; i++){
|
||||
props.workStore.push(data.storeDTOList[i]);
|
||||
props.setWorkStore(props.workStore)
|
||||
}
|
||||
for(let i = 0; i < data.buyerDTOList.length; i++){
|
||||
props.workBuyer.push(data.buyerDTOList[i]);
|
||||
//props.setworkBuyer(props.workBuyer)
|
||||
}
|
||||
setEdit(true);
|
||||
setModalHeader("Редактирование элемента");
|
||||
setModalConfirm("Сохранить");
|
||||
setModalVisible(true);
|
||||
props.onEdit(data);
|
||||
});
|
||||
}
|
||||
|
||||
function handleModalDone() {
|
||||
saveItem();
|
||||
}
|
||||
function handleModalHide() {
|
||||
setModalVisible(false);
|
||||
props.setWorkStore([]);
|
||||
props.setWorkBuyer([]);
|
||||
}
|
||||
function handleRemoveStore(id, e) {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (confirm("Удалить выбранные элементы?")) {
|
||||
const promises = [];
|
||||
selectedItems.forEach((item) => {
|
||||
props.deleteStores(item);
|
||||
});
|
||||
selectedItems.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function handleRemoveBuyer(id, e) {
|
||||
if (selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (confirm("Удалить выбранные элементы?")) {
|
||||
const promises = [];
|
||||
selectedItems.forEach((item) => {
|
||||
props.deleteBuyers(item);
|
||||
});
|
||||
selectedItems.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAddStore() {
|
||||
if (props.workStore.filter((x) => x.id == StoreL.id).length == 0)
|
||||
{
|
||||
await props.updateStores(StoreL);
|
||||
setStoreL({});
|
||||
props.workStore.push(StoreL);
|
||||
await props.setWorkStore(props.workStore);
|
||||
setStoreL({});
|
||||
return;
|
||||
}
|
||||
}
|
||||
async function handleAddBuyer() {
|
||||
if (props.workBuyer.filter((x) => x.id == BuyerL.id).length == 0)
|
||||
{
|
||||
await props.updateBuyers(BuyerL);
|
||||
setBuyerL({});
|
||||
props.workBuyer.push(BuyerL);
|
||||
await props.setWorkBuyer(props.workBuyer);
|
||||
setBuyerL({});
|
||||
return;
|
||||
}
|
||||
}
|
||||
function handleFormChangeStore(event) {
|
||||
if (event.target.id === "storeName") {
|
||||
setStoreL({
|
||||
...StoreL,
|
||||
["id"]: event.target.value,
|
||||
["storeName"]: props.store
|
||||
.filter((x) => x.id == event.target.value)
|
||||
.map((x) => x.storeName)[0],
|
||||
});
|
||||
return;
|
||||
}
|
||||
setStoreL({
|
||||
...StoreL,
|
||||
[event.target.id]: Number(event.target.value),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
function handleFormChangeBuyer(event) {
|
||||
if (event.target.id === "buyerSecondName") {
|
||||
setBuyerL({
|
||||
...BuyerL,
|
||||
["id"]: event.target.value,
|
||||
["buyerFirstName"]: props.buyer
|
||||
.filter((x) => x.id == event.target.value)
|
||||
.map((x) => x.buyerFirstName)[0],
|
||||
["buyerSecondName"]: props.buyer
|
||||
.filter((x) => x.id == event.target.value)
|
||||
.map((x) => x.buyerSecondName)[0],
|
||||
});
|
||||
return;
|
||||
}
|
||||
setBuyerL({
|
||||
...BuyerL,
|
||||
[event.target.id]: Number(event.target.value),
|
||||
});
|
||||
return;
|
||||
}
|
||||
function handleTableClick(tableSelectedItems) {
|
||||
selectedItems = tableSelectedItems;
|
||||
}
|
||||
function handleTableDblClickModalProd(tableSelectedItem) {
|
||||
setStoreL(
|
||||
props.workStore.filter((x) => x.id == tableSelectedItem)[0]
|
||||
);
|
||||
}
|
||||
function handleTableDblClick(tableSelectedItem) {
|
||||
edit(tableSelectedItem);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{/* <ToolbarStore onAdd={handleAdd} />
|
||||
<Card items={items} onEdit={edit} onRemove={handleRemoveCard} car={props.car} setCar={props.setCar}/> */}
|
||||
<Modal
|
||||
header={modalHeader}
|
||||
confirm={modalConfirm}
|
||||
visible={modalVisible}
|
||||
onHide={handleModalHide}
|
||||
onDone={handleModalDone}
|
||||
>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="name" className="form-label">
|
||||
Название машины
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="carName"
|
||||
className="form-control"
|
||||
required
|
||||
value={props.data.carName}
|
||||
onChange={props.handleFormChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="groupId" className="form-label">
|
||||
Магазин
|
||||
</label>
|
||||
<select
|
||||
id="storeName"
|
||||
className="form-select"
|
||||
required
|
||||
value={StoreL.id}
|
||||
onChange={handleFormChangeStore}
|
||||
>
|
||||
<option disabled value="">
|
||||
Укажите магазин
|
||||
</option>
|
||||
{props.store.map((group) => (
|
||||
<option key={group.id} value={group.id}>
|
||||
{group.storeName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<Toolbar
|
||||
onAdd={handleAddStore}
|
||||
onEdit={handleEdit}
|
||||
onRemove={handleRemoveStore}
|
||||
/>
|
||||
<Table
|
||||
headers={props.catalogProdHeaders}
|
||||
items={props.workStore}
|
||||
allItems={props.store}
|
||||
selectable={true}
|
||||
onClick={handleTableClick}
|
||||
onDblClick={handleTableDblClickModalProd}
|
||||
/>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="groupId" className="form-label">
|
||||
Покупатель
|
||||
</label>
|
||||
<select
|
||||
id="buyerSecondName"
|
||||
className="form-select"
|
||||
required
|
||||
value={BuyerL.id}
|
||||
onChange={handleFormChangeBuyer}
|
||||
>
|
||||
<option disabled value="">
|
||||
Укажите рабочего
|
||||
</option>
|
||||
{props.buyer.map((group) => (
|
||||
<option key={group.id} value={group.id}>
|
||||
{group.buyerFirstName} {group.buyerSecondName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<Toolbar
|
||||
onAdd={handleAddBuyer}
|
||||
onEdit={handleEdit}
|
||||
onRemove={handleRemoveBuyer}
|
||||
/>
|
||||
<Table
|
||||
headers={props.catalogWorkHeaders}
|
||||
items={props.workBuyer}
|
||||
allItems={props.buyer}
|
||||
selectable={true}
|
||||
onClick={handleTableClick}
|
||||
onDblClick={handleTableDblClickModalProd}
|
||||
/>
|
||||
</Modal>
|
||||
<Toolbar
|
||||
onAdd={handleAdd}
|
||||
onEdit={handleEdit}
|
||||
onRemove={handleRemove}
|
||||
/>
|
||||
<Table
|
||||
headers={catalogCarHeaders}
|
||||
items={items}
|
||||
selectable={true}
|
||||
onClick={handleTableClick}
|
||||
onDblClick={handleTableDblClick}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Catalog from './Catalog';
|
||||
import Store from '../../models/Store';
|
||||
import DataService from '../../services/DataService';
|
||||
|
||||
export default function CatalogStores(props) {
|
||||
const getAllUrl = '/store';
|
||||
const url = '/store/';
|
||||
const transformer = (data) => new Store(data);
|
||||
const catalogStudHeaders = [
|
||||
{ name: 'storeName', label: 'Название' }
|
||||
];
|
||||
|
||||
const [data, setData] = useState(new Store());
|
||||
|
||||
function handleOnAdd() {
|
||||
setData(new Store());
|
||||
console.log("create store: " + data.storeName);
|
||||
}
|
||||
|
||||
function handleOnEdit(data) {
|
||||
setData(new Store(data));
|
||||
}
|
||||
|
||||
function handleFormChange(event) {
|
||||
setData({ ...data, [event.target.id]: event.target.value })
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="flex-shrink-0" style={{ backgroundColor: "white" }}>
|
||||
<Catalog
|
||||
headers={catalogStudHeaders}
|
||||
getAllUrl={getAllUrl}
|
||||
url={url}
|
||||
transformer={transformer}
|
||||
data={data}
|
||||
onAdd={handleOnAdd}
|
||||
onEdit={handleOnEdit}>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="storeName" className="form-label">Название</label>
|
||||
<input type="text" id="storeName" className="form-control" required
|
||||
value={data.storeName} onChange={handleFormChange}/>
|
||||
</div>
|
||||
</Catalog>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
import DataService from "../../services/DataService";
|
||||
import Buyer from "../../models/Buyer";
|
||||
import Store from "../../models/Store";
|
||||
import Table from "../common/Table";
|
||||
import { useState, useEffect, Component } from "react";
|
||||
import '../../App.css';
|
||||
export default function Find(props) {
|
||||
const prodUrl = "/store";
|
||||
const storeURL ='/store/buyer/';
|
||||
const [itemsP, setItemsP] = useState([]);
|
||||
const [StoreL, setStoreL] = useState({});
|
||||
const [store, setStore] = useState([]);
|
||||
const catalogBuyerHeaders = [
|
||||
{ name: 'buyerFirstName', label: 'Имя' },
|
||||
{ name: 'buyerSecondName', label: 'Фамилия' },
|
||||
];
|
||||
const transformer = (data) => new Buyer(data);
|
||||
function loadItems() {
|
||||
DataService.readAll(storeURL + StoreL.id, transformer)
|
||||
.then(data => setItemsP(data));
|
||||
}
|
||||
useEffect(() => {
|
||||
DataService.readAll(prodUrl, (data) => new Store(data)).then(
|
||||
(data) => setStore(data)
|
||||
);
|
||||
}, []);
|
||||
let selectedItems = [];
|
||||
function handleTableClick(tableSelectedItems) {
|
||||
selectedItems = tableSelectedItems;
|
||||
}
|
||||
|
||||
function handleTableDblClick(tableSelectedItem) {
|
||||
confirm(tableSelectedItem);
|
||||
}
|
||||
function handleFormChangeStore(event) {
|
||||
if (event.target.id === "storeName") {
|
||||
setStoreL({
|
||||
...StoreL,
|
||||
["id"]: event.target.value,
|
||||
["storeName"]: store
|
||||
.filter((x) => x.id == event.target.value)
|
||||
.map((x) => x.storeName)[0],
|
||||
});
|
||||
return;
|
||||
}
|
||||
setStoreL({
|
||||
...StoreL,
|
||||
[event.target.id]: Number(event.target.value),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
return(
|
||||
<main className="form-group" style={{ backgroundColor: "white" }}>
|
||||
<select
|
||||
id="storeName"
|
||||
className="form-select"
|
||||
value={StoreL.id}
|
||||
onChange={handleFormChangeStore}
|
||||
>
|
||||
<option disabled selected value="">
|
||||
Укажите магазин
|
||||
</option>
|
||||
{store.map((group) => (
|
||||
<option key={group.id} value={group.id}>
|
||||
{group.storeName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<a
|
||||
class="btn btn-light d-flex justify-content-center align-items-center"
|
||||
href="#"
|
||||
type="button"
|
||||
onClick={(e) => loadItems()}
|
||||
>
|
||||
Покупатели, которые пользуются выбранным магазином
|
||||
</a>
|
||||
<div className="d-flex ">
|
||||
<Table className="table"
|
||||
headers={catalogBuyerHeaders}
|
||||
items={itemsP}
|
||||
selectable={false}
|
||||
onClick={handleTableClick}
|
||||
onDblClick={handleTableDblClick}/>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
import DataService from "../../services/DataService";
|
||||
export default function Card(props) {
|
||||
function edit(id) {
|
||||
props.onEdit(id);
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
props.onRemove(id);
|
||||
}
|
||||
async function mess(id){
|
||||
let currentStore = props.store.filter(x => x.id == id.id);
|
||||
if (currentStore.length != 0){
|
||||
let temp = props.store.filter(x => x.id != id.id);
|
||||
currentStore[0].count++;
|
||||
temp.push(currentStore[0]);
|
||||
await props.setStore(temp);
|
||||
return;
|
||||
}else{
|
||||
id.count++;
|
||||
props.store.push(id);
|
||||
props.setStore(props.store);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="temp row row-cols-1 row-cols-md-3 g-4" id="tbl-items">
|
||||
{props.items.map((item) => (
|
||||
<div className="col" key={item.id}>
|
||||
<div className="card">
|
||||
<div
|
||||
className="container"
|
||||
style={{ width: "100%", height: "100px", alignItems: "center" }}
|
||||
>
|
||||
<p>{item["carName"]}</p>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<a
|
||||
href="#"
|
||||
className="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
onClick={(e) => remove(item.id, e)}
|
||||
>
|
||||
Удалить
|
||||
</a>
|
||||
<a
|
||||
href="#"
|
||||
type="button"
|
||||
className="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#staticBackdrop"
|
||||
onClick={(e) => edit(item.id, e)}
|
||||
>
|
||||
Изменить
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
export default function Footer(props) {
|
||||
return (
|
||||
<footer class="text-center p-4 p-3 mb-2 bg-light text-dark">
|
||||
Кашин Максим ПИбд-22
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
import { NavLink } from "react-router-dom";
|
||||
|
||||
export default function Header(props) {
|
||||
return (
|
||||
<nav className="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div className="container-fluid">
|
||||
<button
|
||||
className="navbar-toggler"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation"
|
||||
>
|
||||
<span className="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div className="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul className="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
{props.links.map((route) => (
|
||||
<li key={route.path} className="nav-item">
|
||||
<NavLink className="nav-link fs-4" to={route.path}>
|
||||
{route.label}
|
||||
</NavLink>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
export default function Modal(props) {
|
||||
const formRef = React.createRef();
|
||||
|
||||
function hide() {
|
||||
props.onHide();
|
||||
}
|
||||
|
||||
function done(e) {
|
||||
e.preventDefault();
|
||||
if (formRef.current.checkValidity()) {
|
||||
props.onDone();
|
||||
hide();
|
||||
} else {
|
||||
formRef.current.reportValidity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="modal fade show" tabIndex="-1" aria-hidden="true"
|
||||
style={{ display: props.visible ? 'block' : 'none' }}>
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<h1 className="modal-title fs-5" id="exampleModalLabel">{props.header}</h1>
|
||||
<button className="btn-close" type="button" aria-label="Close"
|
||||
onClick={hide}></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<form ref={formRef} onSubmit={done}>
|
||||
{props.children}
|
||||
</form>
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button className="btn btn-light" type="button" onClick={hide}>Закрыть</button>
|
||||
<button className="btn btn-light" type="button" onClick={done}>
|
||||
{props.confirm}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
import styles from './Table.module.css';
|
||||
|
||||
export default function Table(props) {
|
||||
const [tableUpdate, setTableUpdate] = useState(false);
|
||||
const [selectedItems, setSelectedItems] = useState([]);
|
||||
|
||||
function isSelected(id) {
|
||||
if (!props.selectable) {
|
||||
return false;
|
||||
}
|
||||
return selectedItems.includes(id);
|
||||
}
|
||||
|
||||
function click(id) {
|
||||
if (!props.selectable) {
|
||||
return;
|
||||
}
|
||||
if (isSelected(id)) {
|
||||
var index = selectedItems.indexOf(id);
|
||||
if (index !== -1) {
|
||||
selectedItems.splice(index, 1);
|
||||
setSelectedItems(selectedItems);
|
||||
setTableUpdate(!tableUpdate);
|
||||
}
|
||||
} else {
|
||||
selectedItems.push(id);
|
||||
setSelectedItems(selectedItems);
|
||||
setTableUpdate(!tableUpdate);
|
||||
}
|
||||
props.onClick(selectedItems);
|
||||
}
|
||||
|
||||
function dblClick(id) {
|
||||
if (!props.selectable) {
|
||||
return;
|
||||
}
|
||||
props.onDblClick(id);
|
||||
}
|
||||
|
||||
return (
|
||||
<table className={`table table-hover ${styles.table} ${props.selectable ? styles.selectable : ''}`}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
{
|
||||
props.headers.map(header =>
|
||||
<th key={header.name} scope="col">
|
||||
{header.label}
|
||||
</th>
|
||||
)
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
props.items?.map((item, index) =>
|
||||
<tr key={item.id}
|
||||
className={isSelected(item.id) ? styles.selected : ''}
|
||||
onClick={(e) => click(item.id, e)} onDoubleClick={(e) => dblClick(item.id, e)}>
|
||||
<th scope="row">{index + 1}</th>
|
||||
{
|
||||
props.headers.map(header =>
|
||||
<td key={item.id + header.name}>{item[header.name]}</td>
|
||||
)
|
||||
}
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
</tbody >
|
||||
</table >
|
||||
);
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
.table tbody tr {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.selectable tbody tr:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background-color: #808080;
|
||||
opacity: 80%;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import styles from './Toolbar.module.css';
|
||||
|
||||
export default function Toolbar(props) {
|
||||
function add() {
|
||||
props.onAdd();
|
||||
}
|
||||
|
||||
function edit() {
|
||||
props.onEdit();
|
||||
}
|
||||
|
||||
function remove() {
|
||||
props.onRemove();
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="form-group" style={{ backgroundColor: "white" }}>
|
||||
<a type="button" className="btn btn-light d-flex justify-content-center align-items-center" onClick={add}>
|
||||
Добавить
|
||||
</a>
|
||||
<a type="button" className="btn btn-light d-flex justify-content-center align-items-center" onClick={edit}>
|
||||
Изменить
|
||||
</a>
|
||||
<a type="button" className="btn btn-light d-flex justify-content-center align-items-center" onClick={remove}>
|
||||
Удалить
|
||||
</a>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
.btn {
|
||||
min-width: 140px;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
export default function ToolbarStore(props) {
|
||||
function add() {
|
||||
props.onAdd();
|
||||
}
|
||||
return (
|
||||
<div className="btn-group mt-2" role="group">
|
||||
<button
|
||||
type="button"
|
||||
className={`btn btn-outline-dark text-center d-flex justify-content-md-center mx-5 mb-3`}
|
||||
onClick={add}
|
||||
>
|
||||
Добавить
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './style.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('app')).render(
|
||||
<App />
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
export default class Buyer {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.buyerFirstName = data?.buyerFirstName || "";
|
||||
this.buyerSecondName = data?.buyerSecondName || "";
|
||||
//this.car = data?.car || null;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
export default class Car {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.carName = data?.carName || "";
|
||||
this.storeDTOList = data?.storeDTOList || [];
|
||||
this.buyerDTOList = data?.buyerDTOList || [];
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export default class Store {
|
||||
constructor(data) {
|
||||
this.id = data?.id;
|
||||
this.storeName = data?.storeName || "";
|
||||
this.carDTOList = data?.carDTOList || [];
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export default class DataService {
|
||||
static dataUrlPrefix = 'http://localhost:8080';
|
||||
|
||||
static async readAll(url, transformer) {
|
||||
const response = await fetch(this.dataUrlPrefix + url);
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
return 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 requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
console.log(JSON.stringify(data) + " " + this.dataUrlPrefix + " " + url);
|
||||
const response = await fetch(this.dataUrlPrefix + url, requestParams);
|
||||
}
|
||||
|
||||
static async update(url, data) {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
const response = await fetch(this.dataUrlPrefix + url, requestParams);
|
||||
return true;
|
||||
}
|
||||
|
||||
static async delete(url) {
|
||||
const response = await axios.delete(this.dataUrlPrefix + url);
|
||||
return response.data.id;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()]
|
||||
})
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -1 +1 @@
|
||||
rootProject.name = 'lab1'
|
||||
rootProject.name = 'maxim'
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.example.maxim.Configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class PasswordEncoderConfiguration {
|
||||
@Bean
|
||||
public PasswordEncoder createPasswordEncoder(){
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.example.maxim.Configuration;
|
||||
|
||||
import com.example.maxim.lab3.controller.UserSignUpMVCController;
|
||||
import com.example.maxim.lab3.model.UserRole;
|
||||
import com.example.maxim.lab3.service.UserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfiguration {
|
||||
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
||||
private static final String LOGIN_URL = "/login";
|
||||
private final UserService userService;
|
||||
|
||||
public SecurityConfiguration(UserService userService) {
|
||||
this.userService = userService;
|
||||
createAdminOnStartup();
|
||||
}
|
||||
|
||||
private void createAdminOnStartup() {
|
||||
final String admin = "admin";
|
||||
if (userService.findByLogin(admin) == null) {
|
||||
log.info("Admin user successfully created");
|
||||
userService.createUser(admin, admin, admin, UserRole.ADMIN);
|
||||
}
|
||||
}
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.headers().frameOptions().sameOrigin().and()
|
||||
.cors().and()
|
||||
.csrf().disable()
|
||||
.authorizeHttpRequests()
|
||||
.requestMatchers(UserSignUpMVCController.SIGNUP_URL).permitAll()
|
||||
.requestMatchers(HttpMethod.GET, LOGIN_URL)
|
||||
.permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage(LOGIN_URL).permitAll()
|
||||
.and()
|
||||
.logout().permitAll();
|
||||
return http.build();
|
||||
}
|
||||
@Bean
|
||||
public AuthenticationManager authenticationManagerBean(HttpSecurity http) throws Exception {
|
||||
AuthenticationManagerBuilder authenticationManagerBuilder = http
|
||||
.getSharedObject(AuthenticationManagerBuilder.class);
|
||||
authenticationManagerBuilder.userDetailsService(userService);
|
||||
return authenticationManagerBuilder.build();
|
||||
}
|
||||
@Bean
|
||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||
return (web) -> web.ignoring().requestMatchers("public/styles/**", "/js/**","/templates/**","/webjars/**");
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
package ru.ulsru.is.lab1;
|
||||
package com.example.maxim.Configuration;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -17,7 +18,20 @@ public class WebConfiguration implements WebMvcConfigurer {
|
||||
}
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
WebMvcConfigurer.super.addViewControllers(registry);
|
||||
registry.addViewController("rest-test");
|
||||
ViewControllerRegistration registration = registry.addViewController("/notFound");
|
||||
registration.setViewName("forward:/index.html");
|
||||
registration.setStatusCode(HttpStatus.OK);
|
||||
registry.addViewController("login");
|
||||
}
|
||||
//@Override
|
||||
//public void addViewControllers(ViewControllerRegistry registry) {
|
||||
// WebMvcConfigurer.super.addViewControllers(registry);
|
||||
// registry.addViewController("rest-test");
|
||||
//}
|
||||
// @Bean
|
||||
// public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
|
||||
// return container -> {
|
||||
// container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound"));
|
||||
// };
|
||||
// }
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
package ru.ulsru.is.lab1;
|
||||
package com.example.maxim;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Lab1Application {
|
||||
public class MaximApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Lab1Application.class, args);
|
||||
SpringApplication.run(MaximApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package ru.ulsru.is.lab1.lab3.Respository;
|
||||
package com.example.maxim.lab3.Respository;
|
||||
|
||||
import com.example.maxim.lab3.model.Buyer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IBuyerRespository extends JpaRepository<Buyer, Long> {
|
||||
|
||||
@Query("SELECT w.buyers FROM Car w WHERE :buyer MEMBER OF w.buyers")
|
||||
List<Buyer> findBuyersOnCar(@Param("buyer") Buyer buyer);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package ru.ulsru.is.lab1.lab3.Respository;
|
||||
package com.example.maxim.lab3.Respository;
|
||||
|
||||
import com.example.maxim.lab3.model.Car;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulsru.is.lab1.lab3.model.Car;
|
||||
|
||||
public interface ICarRespository extends JpaRepository<Car, Long> {
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.Respository;
|
||||
package com.example.maxim.lab3.Respository;
|
||||
|
||||
import com.example.maxim.lab3.model.Buyer;
|
||||
import com.example.maxim.lab3.model.Store;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulsru.is.lab1.lab3.model.Store;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStoreRespository extends JpaRepository<Store, Long> {
|
||||
@Query("SELECT DISTINCT с.buyers FROM Car с where :store MEMBER OF с.stores")
|
||||
@Query("SELECT DISTINCT p.buyers FROM Car p where :store MEMBER OF p.stores")
|
||||
List<Buyer> getBuyers(@Param("store") Store store);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.example.maxim.lab3.Respository;
|
||||
|
||||
import com.example.maxim.lab3.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface IUserRespository extends JpaRepository<User, Long> {
|
||||
User findOneByLoginIgnoreCase(String login);
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.Configuration.WebConfiguration;
|
||||
import com.example.maxim.lab3.service.BuyerService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.BuyerService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("(WebConfiguration.REST_API + /buyer")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/buyer")
|
||||
public class BuyerController {
|
||||
private final BuyerService buyerService;
|
||||
public BuyerController(BuyerService buyerService){
|
||||
@ -37,8 +38,12 @@ public class BuyerController {
|
||||
public BuyerDTO findBuyer(@PathVariable Long id) {
|
||||
return new BuyerDTO(buyerService.findBuyer(id));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/car/{id}")
|
||||
public List<BuyerDTO> findBuyersOnCar(@PathVariable Long id){
|
||||
return buyerService.findBuyersOnCar(id).stream()
|
||||
.map(BuyerDTO::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping
|
||||
public List<BuyerDTO> findAllBuyer() {
|
||||
return buyerService.findAllBuyers()
|
@ -1,18 +1,17 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.Buyer;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public class BuyerDTO {
|
||||
private long id;
|
||||
@NotBlank(message = "buyerFirstName can't be null or empty")
|
||||
@NotBlank(message = "FirstName can't be null or empty")
|
||||
private String buyerFirstName;
|
||||
@NotBlank(message = "buyerSecondName can't be null or empty")
|
||||
@NotBlank(message = "SecondName can't be null or empty")
|
||||
private String buyerSecondName;
|
||||
public BuyerDTO(Buyer buyer){
|
||||
this.id =buyer.getId();
|
||||
this.id = buyer.getId();
|
||||
this.buyerFirstName = buyer.getBuyerFirstName();
|
||||
this.buyerSecondName = buyer.getBuyerSecondName();
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.service.BuyerService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.BuyerService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/buyer")
|
||||
@ -23,10 +22,18 @@ public class BuyerMVCController {
|
||||
.toList());
|
||||
return "buyer";
|
||||
}
|
||||
|
||||
@GetMapping("/info/{id}")
|
||||
public String findBuyersOnCar(@PathVariable(required = false) Long id, Model model){
|
||||
model.addAttribute("cathegory", "Кто работает с " + buyerService.findBuyer(id).getBuyerFirstName() + " " + buyerService.findBuyer(id).getBuyerSecondName());
|
||||
model.addAttribute("buyers", buyerService.findBuyersOnCar(id).stream()
|
||||
.map(BuyerDTO::new)
|
||||
.toList());
|
||||
model.addAttribute("page", "buyer");
|
||||
return "buyer-info";
|
||||
}
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editBuyer(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("BuyerDTO", new BuyerDTO());
|
||||
} else {
|
||||
@ -37,9 +44,9 @@ public class BuyerMVCController {
|
||||
}
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
public String saveBuyer(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid BuyerDTO buyerDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
@ModelAttribute @Valid BuyerDTO buyerDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "buyer-edit";
|
@ -1,13 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.Configuration.WebConfiguration;
|
||||
import com.example.maxim.lab3.service.CarService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.CarService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("WebConfiguration.REST_API + /car")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/car")
|
||||
public class CarController {
|
||||
private final CarService carService;
|
||||
public CarController(CarService carService){
|
@ -1,14 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.Car;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import ru.ulsru.is.lab1.lab3.model.Car;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
public class CarDTO {
|
||||
private long id;
|
||||
@NotBlank(message = "carName can't be null or empty")
|
||||
@NotBlank(message = "CarName can't be null or empty")
|
||||
private String carName;
|
||||
private List<BuyerDTO> buyerDTOList;
|
||||
private List<StoreDTO> storeDTOList;
|
||||
@ -33,23 +33,19 @@ public class CarDTO {
|
||||
public String getCarName(){
|
||||
return carName;
|
||||
}
|
||||
public void setCarName(String carName){
|
||||
this.carName = carName;
|
||||
}
|
||||
public List<BuyerDTO> getBuyerDTOList(){
|
||||
return buyerDTOList;
|
||||
}
|
||||
|
||||
public void setCarName(String carName) {
|
||||
this.carName = carName;
|
||||
public void setBuyerDTOList(List<BuyerDTO> buyers){
|
||||
this.buyerDTOList = buyers;
|
||||
}
|
||||
|
||||
public void setBuyerDTOList(List<BuyerDTO> buyerDTOList) {
|
||||
this.buyerDTOList = buyerDTOList;
|
||||
}
|
||||
|
||||
public void setStoreDTOList(List<StoreDTO> storeDTOList) {
|
||||
this.storeDTOList = storeDTOList;
|
||||
}
|
||||
|
||||
public List<StoreDTO> getStoreDTOList(){
|
||||
return storeDTOList;
|
||||
}
|
||||
public void setStoreDTOList(List<StoreDTO> stores){
|
||||
this.storeDTOList = stores;
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.service.StoreService;
|
||||
import com.example.maxim.lab3.service.BuyerService;
|
||||
import com.example.maxim.lab3.service.CarService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.StoreService;
|
||||
import ru.ulsru.is.lab1.lab3.service.BuyerService;
|
||||
import ru.ulsru.is.lab1.lab3.service.CarService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ -32,6 +32,7 @@ public class CarMVCController {
|
||||
}
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editCar(@PathVariable(required = false) Long id,
|
||||
@RequestParam(value ="PW", required = false) String PW,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
List<BuyerDTO> buyers = buyerService.findAllBuyers().stream()
|
||||
@ -43,34 +44,35 @@ public class CarMVCController {
|
||||
model.addAttribute("stores", stores);
|
||||
return "car-create";
|
||||
} else {
|
||||
String name = carService.findCar(id).getCarName();
|
||||
if(PW.equals("N")) {
|
||||
model.addAttribute("carId", id);
|
||||
model.addAttribute("CarDTO", new CarDTO(carService.findCar(id)));
|
||||
return "car-create";
|
||||
}
|
||||
if(PW.equals("W")) {
|
||||
List<BuyerDTO> buyers = buyerService.findAllBuyers().stream()
|
||||
.map(BuyerDTO::new).toList();
|
||||
List<BuyerDTO> carBuyers = carService
|
||||
.findCar(id)
|
||||
.getBuyers()
|
||||
.stream()
|
||||
.map(BuyerDTO::new)
|
||||
.toList();
|
||||
List<StoreDTO> stores = storeService.findAllStores().stream()
|
||||
.map(StoreDTO::new).toList();
|
||||
List<StoreDTO> carStores = carService
|
||||
.findCar(id)
|
||||
.getStores()
|
||||
.stream()
|
||||
.map(StoreDTO::new)
|
||||
.toList();
|
||||
model.addAttribute("name", name);
|
||||
.findCar(id).getBuyers().stream().map(BuyerDTO::new).toList();
|
||||
model.addAttribute("carId", id);
|
||||
model.addAttribute("carBuyers", carBuyers);
|
||||
model.addAttribute("buyers", buyers);
|
||||
return "car-buyer";
|
||||
}
|
||||
if(PW.equals("P")) {
|
||||
List<StoreDTO> stores = storeService.findAllStores().stream()
|
||||
.map(StoreDTO::new).toList();
|
||||
List<StoreDTO> carStores = carService
|
||||
.findCar(id).getStores().stream().map(StoreDTO::new).toList();
|
||||
model.addAttribute("carId", id);
|
||||
model.addAttribute("carStores", carStores);
|
||||
model.addAttribute("stores", stores);
|
||||
model.addAttribute("CarDTO", new CarDTO(carService.findCar(id)));
|
||||
return "car-store";
|
||||
}
|
||||
}
|
||||
return "car-set";
|
||||
return "car";
|
||||
}
|
||||
@PostMapping(value = {"/"})
|
||||
@PostMapping(value = {"/0"})
|
||||
public String saveCar(@ModelAttribute @Valid CarDTO carDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
@ -78,38 +80,39 @@ public class CarMVCController {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "car-create";
|
||||
}
|
||||
carService.addCar(carDTO);
|
||||
// } else {
|
||||
// carService.updateCar(id, carDTO);
|
||||
// }
|
||||
carService.addCar(carDTO);
|
||||
return "redirect:/car";
|
||||
}
|
||||
@PostMapping(value = {"/{id}"})
|
||||
public String editCar(@PathVariable Long id,
|
||||
@RequestParam("PW") String PW,
|
||||
@RequestParam("wpName") String name,
|
||||
@RequestParam(value="idPW", required = false) Long idPW,
|
||||
@RequestParam(value = "delete", required = false) boolean del,
|
||||
Model model) {
|
||||
if(PW.equals("N")){
|
||||
carService.findCar(id).setCarName(name);
|
||||
carService.updateCar(id, new CarDTO(carService.findCar(id)));
|
||||
public String editCarName(@PathVariable Long id,
|
||||
@RequestParam("carName") String name){
|
||||
carService.findCar(id).setCarName(name);
|
||||
carService.updateCar(id, new CarDTO(carService.findCar(id)));
|
||||
return "redirect:/car/";
|
||||
}
|
||||
@PostMapping(value = {"/{id}/buyer"})
|
||||
public String editBuyerCar(@PathVariable Long id,
|
||||
@RequestParam("buyer") Long buyerId,
|
||||
@RequestParam(value = "delete", required = false) boolean del,
|
||||
Model model) {
|
||||
if (del) {
|
||||
carService.deleteBuyer(id, buyerId);
|
||||
} else {
|
||||
carService.addBuyer(id, buyerId);
|
||||
}
|
||||
return "redirect:/car/edit/" + id + "?PW=W";
|
||||
}
|
||||
@PostMapping(value = {"/{id}/store"})
|
||||
public String editStoreCar(@PathVariable Long id,
|
||||
@RequestParam("store") Long storeId,
|
||||
@RequestParam(value = "delete", required = false) boolean del,
|
||||
Model model) {
|
||||
if (del) {
|
||||
carService.deleteStore(id, storeId);
|
||||
} else {
|
||||
carService.addStore(id, storeId);
|
||||
}
|
||||
if (PW.equals("W")){
|
||||
if (del == true) {
|
||||
carService.deleteBuyer(id, idPW);
|
||||
} else {
|
||||
carService.addBuyer(id, idPW);
|
||||
}
|
||||
}
|
||||
else if(PW.equals("P")){
|
||||
if (del == true) {
|
||||
carService.deleteStore(id, idPW);
|
||||
} else {
|
||||
carService.addStore(id, idPW);
|
||||
}
|
||||
}
|
||||
return "redirect:/car/edit/" + id;
|
||||
return "redirect:/car/edit/" + id + "?PW=P";
|
||||
}
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteCar(@PathVariable Long id) {
|
@ -1,13 +1,14 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.Configuration.WebConfiguration;
|
||||
import com.example.maxim.lab3.service.StoreService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.StoreService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("WebConfiguration.REST_API + /store")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/store")
|
||||
public class StoreController {
|
||||
private final StoreService storeService;
|
||||
public StoreController(StoreService storeService){
|
||||
@ -39,10 +40,16 @@ public class StoreController {
|
||||
}
|
||||
@GetMapping("/buyer/{id}")
|
||||
public List<BuyerDTO> findBuyersOnCar(@PathVariable Long id){
|
||||
return storeService.findAllBuyersProducedStore(id).stream().map(BuyerDTO::new).toList();
|
||||
return storeService.findAllBuyersProducedStore(id)
|
||||
.stream()
|
||||
.map(BuyerDTO::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping
|
||||
public List<StoreDTO> findAllStore() {
|
||||
return storeService.findAllStores().stream().map(StoreDTO::new).toList();
|
||||
return storeService.findAllStores()
|
||||
.stream()
|
||||
.map(StoreDTO::new)
|
||||
.toList();
|
||||
}
|
||||
}
|
@ -1,23 +1,27 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.Store;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import ru.ulsru.is.lab1.lab3.model.Store;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
public class StoreDTO {
|
||||
private long id;
|
||||
@NotBlank(message = "storeName can't be null or empty")
|
||||
@NotBlank(message = "StoreName can't be null or empty")
|
||||
private String storeName;
|
||||
@NotNull
|
||||
private int price;
|
||||
private List<CarDTO> carDTOList;
|
||||
public StoreDTO(Store store){
|
||||
this.id = store.getId();
|
||||
this.storeName = store.getStoreName();
|
||||
this.price = store.getPrice();
|
||||
this.carDTOList = store.getCar() == null ? null : store.getCar()
|
||||
.stream()
|
||||
.filter(x -> x.getStores().contains(store.getId()))
|
||||
.map(y -> new CarDTO(y))
|
||||
.map(y -> new CarDTO())
|
||||
.toList();
|
||||
}
|
||||
public StoreDTO() {
|
||||
@ -33,6 +37,12 @@ public class StoreDTO {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
public void setPrice(int price){
|
||||
this.price = price;
|
||||
}
|
||||
public List<CarDTO> getCarDTOList(){
|
||||
return carDTOList;
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package ru.ulsru.is.lab1.lab3.controller;
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.service.StoreService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulsru.is.lab1.lab3.service.StoreService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/store")
|
||||
@ -24,7 +23,7 @@ public class StoreMVCController {
|
||||
return "store";
|
||||
}
|
||||
@GetMapping("/info/{id}")
|
||||
public String findBuyersOnWorkplace(@PathVariable(required = false) Long id, Model model){
|
||||
public String findBuyersOnCar(@PathVariable(required = false) Long id, Model model){
|
||||
model.addAttribute("cathegory", "Кто производит " + storeService.findStore(id).getStoreName());
|
||||
model.addAttribute("buyers", storeService.findAllBuyersProducedStore(id)
|
||||
.stream()
|
||||
@ -44,7 +43,7 @@ public class StoreMVCController {
|
||||
}
|
||||
return "store-edit";
|
||||
}
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveStore(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid StoreDTO storeDTO,
|
||||
BindingResult bindingResult,
|
28
src/main/java/com/example/maxim/lab3/controller/UserDTO.java
Normal file
28
src/main/java/com/example/maxim/lab3/controller/UserDTO.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.User;
|
||||
import com.example.maxim.lab3.model.UserRole;
|
||||
|
||||
public class UserDTO {
|
||||
private final long id;
|
||||
private final String login;
|
||||
private final UserRole role;
|
||||
|
||||
public UserDTO(User user) {
|
||||
this.id = user.getId();
|
||||
this.login = user.getLogin();
|
||||
this.role = user.getRole();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.UserRole;
|
||||
import com.example.maxim.lab3.service.UserService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/users")
|
||||
public class UserMVCController {
|
||||
private final UserService userService;
|
||||
|
||||
public UserMVCController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public String getUsers(@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "5") int size,
|
||||
Model model) {
|
||||
final Page<UserDTO> users = userService.findAllPages(page, size)
|
||||
.map(UserDTO::new);
|
||||
model.addAttribute("users", users);
|
||||
final int totalPages = users.getTotalPages();
|
||||
final List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
||||
.boxed()
|
||||
.toList();
|
||||
model.addAttribute("pages", pageNumbers);
|
||||
model.addAttribute("totalPages", totalPages);
|
||||
return "users";
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class UserSignUpDTO {
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String login;
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String password;
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String passwordConfirm;
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPasswordConfirm() {
|
||||
return passwordConfirm;
|
||||
}
|
||||
|
||||
public void setPasswordConfirm(String passwordConfirm) {
|
||||
this.passwordConfirm = passwordConfirm;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.example.maxim.lab3.controller;
|
||||
|
||||
import com.example.maxim.lab3.model.User;
|
||||
import com.example.maxim.lab3.service.UserService;
|
||||
import com.example.maxim.util.validation.ValidationException;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(UserSignUpMVCController.SIGNUP_URL)
|
||||
public class UserSignUpMVCController {
|
||||
public static final String SIGNUP_URL = "/signup";
|
||||
private final UserService userService;
|
||||
|
||||
public UserSignUpMVCController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String showSignupForm(Model model) {
|
||||
model.addAttribute("UserDTO", new UserSignUpDTO());
|
||||
return "signup";
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public String signup(@ModelAttribute("UserDTO") @Valid UserSignUpDTO userSignupDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "signup";
|
||||
}
|
||||
try {
|
||||
final User user = userService.createUser(
|
||||
userSignupDto.getLogin(), userSignupDto.getPassword(), userSignupDto.getPasswordConfirm());
|
||||
return "redirect:/login?created=" + user.getLogin();
|
||||
} catch (ValidationException e) {
|
||||
model.addAttribute("errors", e.getMessage());
|
||||
return "signup";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package ru.ulsru.is.lab1.lab3.model;
|
||||
package com.example.maxim.lab3.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@ -16,6 +17,9 @@ public class Buyer {
|
||||
@NotNull(message = "Second name can't be empty")
|
||||
@Column(name = "second_name")
|
||||
private String buyerSecondName;
|
||||
@ManyToOne
|
||||
@JoinColumn(name= "user_id", nullable = false)
|
||||
private User user;
|
||||
public Buyer(){
|
||||
}
|
||||
public Buyer(String buyerFirstName, String buyerSecondName){
|
||||
@ -37,6 +41,12 @@ public class Buyer {
|
||||
public void setBuyerSecondName(String buyerSecondName) {
|
||||
this.buyerSecondName = buyerSecondName;
|
||||
}
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@ -54,6 +64,7 @@ public class Buyer {
|
||||
"id=" + id +
|
||||
", buyerFirstName='" + buyerFirstName + '\'' +
|
||||
", buyerSecondName='" + buyerSecondName + '\'' +
|
||||
", user='" + user + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package ru.ulsru.is.lab1.lab3.model;
|
||||
package com.example.maxim.lab3.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -23,6 +24,9 @@ public class Car {
|
||||
joinColumns = @JoinColumn(name = "car_fk"),
|
||||
inverseJoinColumns = @JoinColumn(name = "store_fk"))
|
||||
private List<Store> stores;
|
||||
@ManyToOne
|
||||
@JoinColumn(name= "user_id", nullable = false)
|
||||
private User user;
|
||||
public Car(){
|
||||
}
|
||||
public Car(String carName, List<Store> stores, List<Buyer> buyers){
|
||||
@ -82,6 +86,12 @@ public class Car {
|
||||
this.buyers.remove(buyer);
|
||||
}
|
||||
}
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -100,6 +110,7 @@ public class Car {
|
||||
return "Car{" +
|
||||
"id=" + id +
|
||||
", carName='" + carName + '\'' +
|
||||
", user='" + user + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package ru.ulsru.is.lab1.lab3.model;
|
||||
package com.example.maxim.lab3.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -14,13 +15,20 @@ public class Store {
|
||||
@NotNull(message = "Name can't be empty")
|
||||
@Column(name = "storeName")
|
||||
private String storeName;
|
||||
@NotNull(message = "Price can't be null or empty")
|
||||
@Column(name = "price")
|
||||
private Integer price;
|
||||
@ManyToMany(mappedBy = "stores",cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
|
||||
private List<Car> car;
|
||||
@ManyToOne
|
||||
@JoinColumn(name= "user_id", nullable = false)
|
||||
private User user;
|
||||
public Store() {
|
||||
}
|
||||
|
||||
public Store(String storeName) {
|
||||
public Store(String storeName, Integer price) {
|
||||
this.storeName = storeName;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@ -35,6 +43,14 @@ public class Store {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Integer price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public List<Car> getCar() {
|
||||
return car;
|
||||
}
|
||||
@ -55,7 +71,12 @@ public class Store {
|
||||
if (this.car.contains(car))
|
||||
this.car.remove(car);
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -74,6 +95,8 @@ public class Store {
|
||||
return "Store{" +
|
||||
"id=" + id +
|
||||
", storeName='" + storeName + '\'' +
|
||||
", price='" + price + '\'' +
|
||||
", user='" + user + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
83
src/main/java/com/example/maxim/lab3/model/User.java
Normal file
83
src/main/java/com/example/maxim/lab3/model/User.java
Normal file
@ -0,0 +1,83 @@
|
||||
package com.example.maxim.lab3.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(nullable = false, unique = true, length = 64)
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String login;
|
||||
@Column(nullable = false, length = 64)
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 64)
|
||||
private String password;
|
||||
private UserRole role;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String login, String password) {
|
||||
this(login, password, UserRole.USER);
|
||||
}
|
||||
|
||||
public User(String login, String password, UserRole role) {
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
User user = (User) o;
|
||||
return Objects.equals(id, user.id) && Objects.equals(login, user.login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, login);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", login='" + login + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", role='" + role + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
20
src/main/java/com/example/maxim/lab3/model/UserRole.java
Normal file
20
src/main/java/com/example/maxim/lab3/model/UserRole.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.example.maxim.lab3.model;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
public enum UserRole implements GrantedAuthority {
|
||||
ADMIN,
|
||||
USER;
|
||||
|
||||
private static final String PREFIX = "ROLE_";
|
||||
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return PREFIX + this.name();
|
||||
}
|
||||
|
||||
public static final class AsString {
|
||||
public static final String ADMIN = PREFIX + "ADMIN";
|
||||
public static final String USER = PREFIX + "USER";
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
public class BuyerNotFoundException extends RuntimeException {
|
||||
public BuyerNotFoundException(Long id){
|
@ -1,12 +1,16 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
import com.example.maxim.lab3.Respository.IBuyerRespository;
|
||||
import com.example.maxim.lab3.controller.BuyerDTO;
|
||||
import com.example.maxim.lab3.controller.CarDTO;
|
||||
import com.example.maxim.lab3.model.Buyer;
|
||||
import com.example.maxim.lab3.model.User;
|
||||
import com.example.maxim.lab3.model.UserRole;
|
||||
import com.example.maxim.util.validation.ValidatorUtil;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulsru.is.lab1.lab3.Respository.IBuyerRespository;
|
||||
import ru.ulsru.is.lab1.lab3.controller.BuyerDTO;
|
||||
import ru.ulsru.is.lab1.lab3.controller.CarDTO;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
import ru.ulsru.is.lab1.util.validation.ValidatorUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -15,13 +19,25 @@ import java.util.Optional;
|
||||
public class BuyerService {
|
||||
private final IBuyerRespository buyerRespository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
public BuyerService(IBuyerRespository buyerRespositroy, ValidatorUtil validatorUtil){
|
||||
this.buyerRespository = buyerRespositroy;
|
||||
private final UserService userService;
|
||||
|
||||
public BuyerService(IBuyerRespository buyerRespository, ValidatorUtil validatorUtil, UserService userService) {
|
||||
this.buyerRespository = buyerRespository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Buyer addBuyer(BuyerDTO buyerDTO) {
|
||||
final Buyer buyer = new Buyer(buyerDTO.getBuyerFirstName(), buyerDTO.getBuyerSecondName());
|
||||
Object currentUser = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(currentUser instanceof UserDetails){
|
||||
String username = ((UserDetails)currentUser).getUsername();
|
||||
User user = userService.findByLogin(username);
|
||||
if(user.getRole() == UserRole.ADMIN){
|
||||
buyer.setUser(user);
|
||||
}
|
||||
}
|
||||
validatorUtil.validate(buyer);
|
||||
buyerRespository.save(buyer);
|
||||
return buyer;
|
||||
@ -67,6 +83,10 @@ public class BuyerService {
|
||||
return currentBuyer;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Buyer> findBuyersOnCar(Long id){
|
||||
return buyerRespository.findBuyersOnCar(findBuyer(id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllBuyers() {
|
@ -1,4 +1,4 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
public class CarNotFoundException extends RuntimeException{
|
||||
public CarNotFoundException(Long id){
|
@ -1,12 +1,12 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
import com.example.maxim.lab3.Respository.ICarRespository;
|
||||
import com.example.maxim.lab3.controller.CarDTO;
|
||||
import com.example.maxim.lab3.model.*;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulsru.is.lab1.lab3.Respository.ICarRespository;
|
||||
import ru.ulsru.is.lab1.lab3.controller.CarDTO;
|
||||
import ru.ulsru.is.lab1.lab3.model.Store;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
import ru.ulsru.is.lab1.lab3.model.Car;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -16,23 +16,32 @@ public class CarService {
|
||||
private final ICarRespository carRespository;
|
||||
private final StoreService storeService;
|
||||
private final BuyerService buyerService;
|
||||
private final UserService userService;
|
||||
public CarService(ICarRespository carRespository,
|
||||
StoreService storeService,
|
||||
BuyerService buyerService
|
||||
BuyerService buyerService,
|
||||
UserService userService
|
||||
){
|
||||
this.carRespository = carRespository;
|
||||
this.storeService = storeService;
|
||||
this.buyerService = buyerService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Car addCar(CarDTO carDTO) {
|
||||
|
||||
List<Store> stores = storeService.findAllStoresById(carDTO);
|
||||
List<Buyer> buyers = buyerService.findAllBuyerByid(carDTO);
|
||||
|
||||
final Car car = new Car(
|
||||
carDTO.getCarName(), stores, buyers);
|
||||
Object currentUser = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(currentUser instanceof UserDetails){
|
||||
String username = ((UserDetails)currentUser).getUsername();
|
||||
User user = userService.findByLogin(username);
|
||||
if(user.getRole() == UserRole.ADMIN){
|
||||
car.setUser(user);
|
||||
}
|
||||
}
|
||||
carRespository.save(car);
|
||||
return car;
|
||||
}
|
||||
@ -49,12 +58,11 @@ public class CarService {
|
||||
return currentCar;
|
||||
}
|
||||
@Transactional
|
||||
public Car addStore(Long id, Long idP) {
|
||||
public Car addStore(Long id, Long idP){
|
||||
final Car currentCar = findCar(id);
|
||||
currentCar.addStore(storeService.findStore(idP));
|
||||
return currentCar;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Car deleteStore(Long id, Long idP){
|
||||
final Car currentCar = findCar(id);
|
@ -1,4 +1,4 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
public class StoreNotFoundException extends RuntimeException{
|
||||
public StoreNotFoundException(Long id){
|
@ -1,13 +1,13 @@
|
||||
package ru.ulsru.is.lab1.lab3.service;
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
import com.example.maxim.lab3.Respository.IStoreRespository;
|
||||
import com.example.maxim.lab3.controller.StoreDTO;
|
||||
import com.example.maxim.lab3.controller.CarDTO;
|
||||
import com.example.maxim.lab3.model.*;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulsru.is.lab1.lab3.Respository.IStoreRespository;
|
||||
import ru.ulsru.is.lab1.lab3.controller.StoreDTO;
|
||||
import ru.ulsru.is.lab1.lab3.controller.CarDTO;
|
||||
import ru.ulsru.is.lab1.lab3.model.Store;
|
||||
import ru.ulsru.is.lab1.lab3.model.Buyer;
|
||||
import ru.ulsru.is.lab1.lab3.model.Car;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -15,12 +15,22 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class StoreService {
|
||||
private final IStoreRespository storeRespository;
|
||||
public StoreService(IStoreRespository storeRespository){
|
||||
private final UserService userService;
|
||||
public StoreService(IStoreRespository storeRespository, UserService userService){
|
||||
this.storeRespository = storeRespository;
|
||||
this.userService = userService;
|
||||
}
|
||||
@Transactional
|
||||
public Store addStore(StoreDTO storeDTO) {
|
||||
Store store =new Store(storeDTO.getStoreName());
|
||||
Store store =new Store(storeDTO.getStoreName(), storeDTO.getPrice());
|
||||
Object currentUser = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(currentUser instanceof UserDetails){
|
||||
String username = ((UserDetails)currentUser).getUsername();
|
||||
User user = userService.findByLogin(username);
|
||||
if(user.getRole() == UserRole.ADMIN){
|
||||
store.setUser(user);
|
||||
}
|
||||
}
|
||||
storeRespository.save(store);
|
||||
return store;
|
||||
}
|
||||
@ -51,6 +61,7 @@ public class StoreService {
|
||||
public Store updateStore(Long id, StoreDTO storeDTO) {
|
||||
final Store currentStore = findStore(id);
|
||||
currentStore.setStoreName(storeDTO.getStoreName());
|
||||
currentStore.setPrice(storeDTO.getPrice());
|
||||
storeRespository.save(currentStore);
|
||||
return currentStore;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.example.maxim.lab3.service;
|
||||
|
||||
import com.example.maxim.lab3.Respository.IUserRespository;
|
||||
import com.example.maxim.lab3.model.User;
|
||||
import com.example.maxim.lab3.model.UserRole;
|
||||
import com.example.maxim.util.validation.ValidationException;
|
||||
import com.example.maxim.util.validation.ValidatorUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
@Service
|
||||
public class UserService implements UserDetailsService {
|
||||
private final IUserRespository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public UserService(IUserRespository userRepository,
|
||||
PasswordEncoder passwordEncoder,
|
||||
ValidatorUtil validatorUtil) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
public Page<User> findAllPages(int page, int size) {
|
||||
return userRepository.findAll(PageRequest.of(page - 1, size, Sort.by("id").ascending()));
|
||||
}
|
||||
public User findByLogin(String login) {
|
||||
return userRepository.findOneByLoginIgnoreCase(login);
|
||||
}
|
||||
public User createUser(String login, String password, String passwordConfirm) {
|
||||
return createUser(login, password, passwordConfirm, UserRole.USER);
|
||||
}
|
||||
public User createUser(String login, String password, String passwordConfirm, UserRole role) {
|
||||
if (findByLogin(login) != null) {
|
||||
throw new ValidationException(String.format("User '%s' already exists", login));
|
||||
}
|
||||
final User user = new User(login, passwordEncoder.encode(password), role);
|
||||
validatorUtil.validate(user);
|
||||
if (!Objects.equals(password, passwordConfirm)) {
|
||||
throw new ValidationException("Passwords not equals");
|
||||
}
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
final User userEntity = findByLogin(username);
|
||||
if (userEntity == null) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
return new org.springframework.security.core.userdetails.User(
|
||||
userEntity.getLogin(), userEntity.getPassword(), Collections.singleton(userEntity.getRole()));
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.example.maxim.util.error;
|
||||
|
||||
import com.example.maxim.lab3.service.StoreNotFoundException;
|
||||
import com.example.maxim.lab3.service.BuyerNotFoundException;
|
||||
import com.example.maxim.lab3.service.CarNotFoundException;
|
||||
import com.example.maxim.util.validation.ValidationException;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ControllerAdvice(annotations = RestController.class)
|
||||
public class AdviceController {
|
||||
@ExceptionHandler({
|
||||
BuyerNotFoundException.class,
|
||||
StoreNotFoundException.class,
|
||||
CarNotFoundException.class,
|
||||
ValidationException.class
|
||||
})
|
||||
public ResponseEntity<Object> handleException(Throwable e) {
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
|
||||
final ValidationException validationException = new ValidationException(
|
||||
e.getBindingResult().getAllErrors().stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||
.collect(Collectors.toSet()));
|
||||
return handleException(validationException);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<Object> handleUnknownException(Throwable e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ru.ulsru.is.lab1.util.validation;
|
||||
package com.example.maxim.util.validation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -6,4 +6,7 @@ public class ValidationException extends RuntimeException {
|
||||
public <T> ValidationException(Set<String> errors) {
|
||||
super(String.join("\n", errors));
|
||||
}
|
||||
}
|
||||
public <T> ValidationException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package ru.ulsru.is.lab1.util.validation;
|
||||
package com.example.maxim.util.validation;
|
||||
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.Validator;
|
||||
import jakarta.validation.ValidatorFactory;
|
||||
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;
|
||||
|
||||
@ -27,4 +27,4 @@ public class ValidatorUtil {
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,5 +8,4 @@
|
||||
color: #333;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout ">
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/buyer/{id}(id=${id})}" th:object="${BuyerDTO}" method="post">
|
||||
<form action="#" th:action="@{/buyer/{id}(id=*{id})}" th:object="${BuyerDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="buyerFirstName" class="form-label">Имя</label>
|
||||
<input type="text" class="form-control" id="buyerFirstName" th:field="${BuyerDTO.buyerFirstName}"
|
||||
<input type="text" class="form-control" id="buyerFirstName" th:field="*{buyerFirstName}"
|
||||
required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="buyerSecondName" class="form-label">Фамилия</label>
|
||||
<input type="text" class="form-control" id="buyerSecondName" th:field="${BuyerDTO.buyerSecondName}"
|
||||
<input type="text" class="form-control" id="buyerSecondName" th:field="*{buyerSecondName}"
|
||||
required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
|
@ -6,6 +6,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h5 th:text="${cathegory}" class="d-flex justify-content-center mb-3"></h5>
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table" >
|
||||
|
@ -2,15 +2,16 @@
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout " xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout " xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
th:href="@{/buyer/edit/}">
|
||||
Добавить
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-success button-fixed"
|
||||
th:href="@{/buyer/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@ -31,11 +32,15 @@
|
||||
<td th:text="${buyer.buyerSecondName}" style="width: 40%"></td>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<a class="btn btn-info button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/buyer/info/{id}(id=${buyer.id})}">
|
||||
<i class="fa fa-info" aria-hidden="true"></i> Инфо
|
||||
</a>
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-success button-fixed" style="min-width: 120px;"
|
||||
th:href="@{/buyer/edit/{id}(id=${buyer.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<button sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="button" class="btn btn-danger button-fixed button-sm" style="min-width: 120px;"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${buyer.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
|
70
src/main/resources/templates/car-buyer.html
Normal file
70
src/main/resources/templates/car-buyer.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout " xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content" class="mw-100">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div>
|
||||
<a class="btn btn-secondary button-fixed mx-4 mt-2" th:href="@{/car}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
<div class="d-flex container-fluid ">
|
||||
<div style="width: 100%;" class="container-fluid">
|
||||
<form action="#" th:action="@{/car/{id}/buyer(id=*{id})}" method="post" >
|
||||
<input name="wpName" type="hidden" th:value="${name}" />
|
||||
<input name="PW" type="hidden" th:value="W" />
|
||||
<div sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="mb-3">
|
||||
<label for="idW" class="form-label">Работник</label>
|
||||
<select class="form-select" id = "idW" th:name="buyer">
|
||||
<option th:each="value: ${buyers}"
|
||||
th:value="${value.id}"
|
||||
th:text="${value.buyerFirstName} + ' ' + ${value.buyerSecondName}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="submit" class="btn btn-primary button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table" id="tbl-items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Имя</th>
|
||||
<th scope="col">Фамилия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="carBuyer, iterator: ${carBuyers}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${carBuyer.buyerFirstName}"></td>
|
||||
<td th:text="${carBuyer.buyerSecondName}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="button" class="m-1 btn btn-danger"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carBuyer.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '/buyer/?buyer='+ ${carBuyer.id} + '&delete=true'}" method="post">
|
||||
<button th:id="'remove-' + ${carBuyer.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -7,17 +7,17 @@
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" th:object="${CarDTO}" method="post">
|
||||
<form action="#" th:action="@{/car/{id}(id=${CarDTO.id})}" th:object="${CarDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="carName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="carName" th:field="${CarDTO.carName}" required="true">
|
||||
<input type="text" class="form-control" id="carName" th:field="*{carName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/car}">
|
||||
<a class="btn btn-secondary button-fixed mx-3" th:href="@{/car}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
|
@ -1,132 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout " xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content" class="mw-100">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
|
||||
<div class="d-flex justify-content-center">
|
||||
<input name="PW" type="hidden" th:value="N" />
|
||||
<label for="wpName" class="form-label mt-2">Название</label>
|
||||
<input type="text" class="d-flex justify-content-center form-control" id="wpName" style="width: 30vw; margin-left: 2vw;" th:value="${name}" name="wpName"/>
|
||||
<div style="margin-left: 2vw;">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Обновить</span>
|
||||
</button>
|
||||
</div>
|
||||
<div style="margin-left: 2vw;">
|
||||
<a class="btn btn-outline-dark text-center button-fixed" th:href="@{/car}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="d-flex container-fluid ">
|
||||
<div style="width: 45vw; margin-right: 2vw" class="container-fluid">
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" >
|
||||
<input name="wpName" type="hidden" th:value="${name}" />
|
||||
<input name="PW" type="hidden" th:value="W" />
|
||||
<div class="mb-3">
|
||||
<label for="idW" class="form-label">Покупатель</label>
|
||||
<select class="form-select" id = "idW" th:name="idPW">
|
||||
<option th:each="value: ${buyers}"
|
||||
th:value="${value.id}"
|
||||
th:text="${value.buyerFirstName} + ' ' + ${value.buyerSecondName}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table" id="tbl-items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Имя</th>
|
||||
<th scope="col">Фамилия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="carBuyer, iterator: ${carBuyers}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${carBuyer.buyerFirstName}"></td>
|
||||
<td th:text="${carBuyer.buyerSecondName}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a type="button" class="btn btn-outline-dark text-center button-fixed"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carBuyer.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '?PW=W&wpName='+ ${name} +'&idPW=' + ${carBuyer.id} + '&delete=true'}" method="post">
|
||||
<button th:id="'remove-' + ${carBuyer.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div style="width: 45vw; margin-left: 2vw" class="container-fluid">
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
|
||||
<input name="wpName" type="hidden" th:value="${name}" />
|
||||
<input type="hidden" th:value="P" name="PW"/>
|
||||
<div class="mb-3">
|
||||
<label for="idP" class="form-label">Магазин</label>
|
||||
<select class="form-select" id = "idP" th:name="idPW">
|
||||
<option th:each="store, iterator: ${stores}"
|
||||
th:value="${store.id}"
|
||||
th:text="${store.storeName}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<table class="table" id="tbl-items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Цена</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="carStore, iterator: ${carStores}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${carStore.storeName}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a type="button" class="btn btn-outline-dark text-center button-fixed"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carStore.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '?PW=P&wpName='+ ${name} + '&idPW=' + ${carStore.id} + '&delete=true'}" method="post">
|
||||
<button class = "btn btn-outline-dark text-center button-fixed" th:id="'remove-' + ${carStore.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
67
src/main/resources/templates/car-store.html
Normal file
67
src/main/resources/templates/car-store.html
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.ultraq.net.nz/thymeleaf/layout " xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content" class="mw-100">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div>
|
||||
<a class="btn btn-secondary button-fixed mx-3 mt-2" th:href="@{/car}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
<div style="width: 100%;" class="container-fluid">
|
||||
<form action="#" th:action="@{/car/{id}/store(id=*{id})}" method="post" class="mb-3">
|
||||
<div sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="mb-3">
|
||||
<label for="idP" class="form-label">Продукт</label>
|
||||
<select class="form-select" id = "idP" th:name="store">
|
||||
<option th:each="store, iterator: ${stores}"
|
||||
th:value="${store.id}"
|
||||
th:text="${store.storeName} + ' ' + ${store.price}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="submit" class="btn btn-primary button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table" id="tbl-items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Цена</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="carStore, iterator: ${carStores}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${carStore.storeName}"></td>
|
||||
<td th:text="${carStore.price}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="button" class="m-1 btn btn-danger"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carStore.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '/store/?store='+ ${carStore.id} + '&delete=true'}" method="post">
|
||||
<button th:id="'remove-' + ${carStore.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,15 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
th:href="@{/car/edit/}">
|
||||
Добавить
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-success button-fixed"
|
||||
th:href="@{/car/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@ -29,11 +29,19 @@
|
||||
<td th:text="${car.carName}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
th:href="@{/car/edit/{id}(id=${car.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
<a class="btn btn-info button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/car/edit/{id}?PW=W(id=${car.id})}">
|
||||
<i class="fa fa-user-secret" aria-hidden="true"></i> Рабочие
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<a class="btn btn-success button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/car/edit/{id}?PW=P(id=${car.id})}">
|
||||
<i class="fa fa-tag" aria-hidden="true"></i> Продукты
|
||||
</a>
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-warning button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/car/edit/{id}?PW=N(id=${car.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изм. Имя
|
||||
</a>
|
||||
<button sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="button" class="btn btn-danger button-fixed button-sm" style="min-width: 120px;"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${car.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
|
@ -1,38 +1,60 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>Кашин Максим ПИбд-22</title>
|
||||
<title>Работаем с кайфом</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
||||
<link rel="stylesheet" href="../static/css/style.css" th:href="@{/css/style.css}"/>
|
||||
<link href="public/styles/style.css"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #708090;">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<i class="fa fa-wheelchair fa-spin fa-fw"></i>
|
||||
Работаем с кайфом
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav" th:with="activeLink=${#request.requestURI}">
|
||||
<ul class="navbar-nav" th:with="activeLink=${#requestURI}">
|
||||
<a class="nav-link" href="/"
|
||||
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная</a>
|
||||
<a class="nav-link" href="/store"
|
||||
th:classappend="${#strings.equals(activeLink, '/store')} ? 'active' : ''">Магазины</a>
|
||||
th:classappend="${#strings.equals(activeLink, '/store')} ? 'active' : ''">Магазин</a>
|
||||
<a class="nav-link" href="/buyer"
|
||||
th:classappend="${#strings.equals(activeLink, '/buyer')} ? 'active' : ''">Покупатели</a>
|
||||
<a class="nav-link" href="/car"
|
||||
th:classappend="${#strings.equals(activeLink, '/car')} ? 'active' : ''">Машины</a>
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="nav-link" href="/users"
|
||||
th:classappend="${#strings.equals(activeLink, '/users')} ? 'active' : ''">Пользователи</a>
|
||||
<a sec:authorize="isAuthenticated()" class="nav-link" href="/logout">
|
||||
Выход (<span th:text="${#authentication.name}"></span>)
|
||||
</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
<div class="container p-3" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
<footer class = "footer">
|
||||
Кашин Максим ПИбд-22
|
||||
<footer class="ft d-flex justify-content-center"
|
||||
style="background-color: #708090;
|
||||
color: black;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100vw;">
|
||||
ООО "Работаем" © 2022
|
||||
</footer>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
@ -1,9 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div class = "d-flex justify-content-center"><span text="error"></span></div>
|
||||
<a href="/">
|
||||
<img class = "container-fluid" src="2.png">
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -5,5 +5,10 @@
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<a href="123">
|
||||
<img class = "container-fluid" src="3.png">
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
34
src/main/resources/templates/login.html
Normal file
34
src/main/resources/templates/login.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:if="${param.error}" class="alert alert-danger margin-bottom">
|
||||
Пользователь не найден или пароль указан не верно
|
||||
</div>
|
||||
<div th:if="${param.logout}" class="alert alert-success margin-bottom">
|
||||
Выход успешно произведен
|
||||
</div>
|
||||
<div th:if="${param.created}" class="alert alert-success margin-bottom">
|
||||
Пользователь '<span th:text="${param.created}"></span>' успешно создан
|
||||
</div>
|
||||
<form th:action="@{/login}" method="post" class="w-50 ms-2">
|
||||
<h2 class="py-3">Вход</h2>
|
||||
<h4>Логин</h4>
|
||||
<input class="form-control my-2" name="username" id="username" type="text" placeholder="Логин" required="true" autofocus="true"/>
|
||||
<h4>Пароль</h4>
|
||||
<input class="form-control my-2" name="password" id="password" type="password" placeholder="Пароль" required="true" />
|
||||
<div>
|
||||
<button class="btn btn-primary m-2" type="submit">Войти</button>
|
||||
<a href="/signup" style="margin-top: 1em; margin-left: 1em"
|
||||
>Зарегистрируйтесь, если нет аккаунта, здесь</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
29
src/main/resources/templates/signup.html
Normal file
29
src/main/resources/templates/signup.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<body>
|
||||
<div class="container container-padding mt-3" layout:fragment="content">
|
||||
<div th:if="${errors}" th:text="${errors}" class="margin-bottom alert alert-danger"></div>
|
||||
<form action="#" th:action="@{/signup}" th:object="${UserDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" th:field="${UserDTO.login}"
|
||||
placeholder="Логин" required="true" autofocus="true" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" th:field="${UserDTO.password}"
|
||||
placeholder="Пароль" required="true" minlength="6" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" th:field="${UserDTO.passwordConfirm}"
|
||||
placeholder="Пароль (подтверждение)" required="true" minlength="6" maxlength="64"/>
|
||||
</div>
|
||||
<div class="mx-4">
|
||||
<button type="submit" class="btn btn-success button-fixed">Создать</button>
|
||||
<a class="btn btn-primary button-fixed" href="/login">Назад</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -7,14 +7,18 @@
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/store/{id}(id=${id})}" th:object="${StoreDTO}" method="post">
|
||||
<form action="#" th:action="@{/store/{id}(id=*{id})}" th:object="${StoreDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="storeName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="storeName" th:field="${StoreDTO.storeName}" required="true">
|
||||
<input type="text" class="form-control" id="storeName" th:field="*{storeName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<label for="price" class="form-label">цена</label>
|
||||
<input type="number" class="form-control" id="price" th:field="*{price}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/store}">
|
||||
|
@ -1,15 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
th:href="@{/store/edit/}">
|
||||
Добавить
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-success button-fixed"
|
||||
th:href="@{/store/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@ -27,17 +27,18 @@
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${store.id}"/>
|
||||
<td th:text="${store.storeName}" style="width: 40%"></td>
|
||||
<td th:text="${store.price}" style="width: 40%"></td>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<a class="btn btn-info button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/store/info/{id}(id=${store.id})}">
|
||||
<i class="fa fa-info" aria-hidden="true"></i> Инфо
|
||||
</a>
|
||||
<a class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<a sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" class="btn btn-warning button-fixed button-sm" style="min-width: 120px;"
|
||||
th:href="@{/store/edit/{id}(id=${store.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-dark text-center d-flex justify-content-md-center mx-5"
|
||||
<button sec:authorize="isAuthenticated() and hasRole('ROLE_ADMIN')" type="button" class="btn btn-danger button-fixed button-sm" style="min-width: 120px;"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${store.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
|
38
src/main/resources/templates/users.html
Normal file
38
src/main/resources/templates/users.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<body>
|
||||
<div class="container" layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Логин</th>
|
||||
<th scope="col">Роль</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="user, iterator: ${users}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"></th>
|
||||
<td th:text="${user.id}"></td>
|
||||
<td th:text="${user.login}" style="width: 60%"></td>
|
||||
<td th:text="${user.role}" style="width: 20%"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div th:if="${totalPages > 0}" class="pagination">
|
||||
<span style="float: left; padding: 5px 5px;">Страницы:</span>
|
||||
<a th:each="page : ${pages}"
|
||||
th:href="@{/users(page=${page}, size=${users.size})}"
|
||||
th:text="${page}"
|
||||
th:class="${page == users.number + 1} ? active">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
13
src/test/java/com/example/maxim/MaximApplicationTests.java
Normal file
13
src/test/java/com/example/maxim/MaximApplicationTests.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.example.maxim;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class MaximApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user