Compare commits
14 Commits
LabWork06M
...
LabWork06R
Author | SHA1 | Date | |
---|---|---|---|
a36cf7602e | |||
6c4676d7e1 | |||
02b25cd834 | |||
03db68af7d | |||
|
7dbe6221ac | ||
|
7762a31191 | ||
1d7e424614 | |||
39fa662ca5 | |||
b43b77ac12 | |||
9e6b5cc2db | |||
6346309870 | |||
864614acea | |||
b3f98c6325 | |||
8d3470086b |
15
build.gradle
@ -16,19 +16,18 @@ jar {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(':front'))
|
implementation(project(':front'))
|
||||||
|
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
implementation 'com.h2database:h2:2.1.210'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
implementation 'com.auth0:java-jwt:4.4.0'
|
||||||
|
implementation 'org.hibernate.validator:hibernate-validator'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
||||||
implementation 'org.webjars:bootstrap:5.1.3'
|
implementation 'org.webjars:bootstrap:5.1.3'
|
||||||
implementation 'org.webjars:jquery:3.6.0'
|
implementation 'org.webjars:jquery:3.6.0'
|
||||||
implementation 'org.webjars:font-awesome:6.1.0'
|
implementation 'org.webjars:font-awesome:6.1.0'
|
||||||
|
|
||||||
implementation 'com.h2database:h2:2.1.210'
|
|
||||||
implementation 'org.hibernate.validator:hibernate-validator'
|
|
||||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
//implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
//implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||||
|
|
||||||
|
BIN
data.mv.db
1070
data.trace.db
Before Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 48 KiB |
@ -1,43 +1,49 @@
|
|||||||
import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom';
|
import { Routes, BrowserRouter, Route } from 'react-router-dom';
|
||||||
import Creator from './MainS/Creator';
|
|
||||||
import Reader from './MainS/Reader';
|
|
||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
import CreatorAction from './Main/CreatorAction';
|
import CreatorAction from './Main/CreatorAction';
|
||||||
import ReaderAction from './Main/ReaderAction';
|
import ReaderAction from './Main/ReaderAction';
|
||||||
import MangaPage from './Main/MangaPage';
|
import UsersPage from './Main/UsersPage';
|
||||||
import Catalog from './Main/Catalog';
|
import Catalog from './Main/Catalog';
|
||||||
|
import LoginPage from './Main/LoginPage';
|
||||||
|
import SingupPage from './Main/SingupPage';
|
||||||
|
import PrivateRoutes from "./components/PrivateRoutes";
|
||||||
|
import MangaPage from "./Main/MangaPage";
|
||||||
|
|
||||||
function Router(props) {
|
function Router(props) {
|
||||||
return useRoutes(props.rootRoute);
|
return useRoutes(props.rootRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const routes = [
|
|
||||||
{ index: true, element: <Reader /> },
|
|
||||||
{ path: 'creator', element: <Creator />, label: 'Creator' },
|
|
||||||
{ path: 'reader', element: <Reader />, label: 'Reader' },
|
|
||||||
{ path: 'creatorAction', element: <CreatorAction />, label: 'CreatorAction' },
|
|
||||||
{ path: 'readerAction', element: <ReaderAction />, label: 'ReaderAction' },
|
|
||||||
{ path: 'catalog', element: <Catalog />, label: 'Catalog' },
|
|
||||||
{ path: 'mangapage', element: <MangaPage /> },
|
|
||||||
];
|
|
||||||
const links = routes.filter(route => route.hasOwnProperty('label'));
|
|
||||||
const rootRoute = [
|
|
||||||
{ path: '/', element: render(links), children: routes }
|
|
||||||
];
|
|
||||||
|
|
||||||
function render(links) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Header links={links} />
|
|
||||||
<Outlet />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const links = [
|
||||||
|
{ path: 'catalog', label: "Catalog", userGroup: "AUTH" },
|
||||||
|
{ path: 'readerAction', label: "ReaderAction", userGroup: "USER" },
|
||||||
|
{ path: 'creatorAction', label: "CreatorAction", userGroup: "ADMIN" },
|
||||||
|
{ path: 'users', label: "Users", userGroup: "ADMIN" }
|
||||||
|
];
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<>
|
||||||
<Router rootRoute={ rootRoute } />
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<Header links={links}></Header>
|
||||||
|
<div className="content-div">
|
||||||
|
<Routes>
|
||||||
|
<Route element={<LoginPage />} path="/login" />
|
||||||
|
<Route element={<SingupPage />} path="/singup" />
|
||||||
|
<Route element={<PrivateRoutes userGroup="AUTH" />}>
|
||||||
|
<Route element={<MangaPage />} path="/mangapage" />
|
||||||
|
<Route element={<Catalog />} path="/catalog" />
|
||||||
|
<Route element={<Catalog />} path="*" />
|
||||||
|
</Route>
|
||||||
|
<Route element={<PrivateRoutes userGroup="USER" />}>
|
||||||
|
<Route element={<ReaderAction />} path="/readerAction" />
|
||||||
|
</Route>
|
||||||
|
<Route element={<PrivateRoutes userGroup="ADMIN" />}>
|
||||||
|
<Route element={<UsersPage />} path="/users" />
|
||||||
|
<Route element={<CreatorAction />} path="/creatorAction" />
|
||||||
|
</Route>
|
||||||
|
</Routes>
|
||||||
|
</div>
|
||||||
|
</BrowserRouter>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
8
front/src/Dto/user-singup-dto.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default class UserSignupDto {
|
||||||
|
constructor(args) {
|
||||||
|
this.login = args.login;
|
||||||
|
this.email = args.email;
|
||||||
|
this.password = args.password;
|
||||||
|
this.passwordConfirm = args.passwordConfirm;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,9 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import '../components/Banner/banner.css'
|
import { NavLink } from 'react-router-dom';
|
||||||
import Banner from '../components/Banner/Banner.jsx'
|
|
||||||
import { Link, NavLink } from 'react-router-dom';
|
|
||||||
import MangaDto from "../Dto/Manga-Dto";
|
|
||||||
|
|
||||||
export default function Catalog() {
|
export default function Catalog() {
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
const [mangs, setMangs] = useState([]);
|
const [mangs, setMangs] = useState([]);
|
||||||
|
|
||||||
@ -17,8 +14,18 @@ export default function Catalog() {
|
|||||||
console.log(mangs);
|
console.log(mangs);
|
||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
const getMangs = async function () {
|
const getMangs = async function () {
|
||||||
const response = await fetch(host + "/manga");
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response = await fetch(host + "/manga", requestParams);
|
||||||
const _data = await response.json()
|
const _data = await response.json()
|
||||||
console.log(_data);
|
console.log(_data);
|
||||||
return _data;
|
return _data;
|
||||||
@ -26,7 +33,6 @@ export default function Catalog() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<article className="p-2 catalog_article">
|
<article className="p-2 catalog_article">
|
||||||
<Banner />
|
|
||||||
<div className = "catalog_wrapper">
|
<div className = "catalog_wrapper">
|
||||||
<h1>Каталог</h1>
|
<h1>Каталог</h1>
|
||||||
<div className="p-2 d-flex flex-wrap">
|
<div className="p-2 d-flex flex-wrap">
|
||||||
|
@ -8,12 +8,10 @@ import EditMangaModal from "../components/Modal/EditMangaModal";
|
|||||||
|
|
||||||
export default function CreatorAction() {
|
export default function CreatorAction() {
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
const [creatorData, setCreatorData] = useState([]);
|
const [creatorData, setCreatorData] = useState([]);
|
||||||
|
|
||||||
const [creatorId, setCreatorId] = useState(0);
|
|
||||||
|
|
||||||
const [creator, setCreator] = useState([]);
|
const [creator, setCreator] = useState([]);
|
||||||
|
|
||||||
const [mangaId, setMangaId] = useState(0);
|
const [mangaId, setMangaId] = useState(0);
|
||||||
@ -24,39 +22,62 @@ export default function CreatorAction() {
|
|||||||
|
|
||||||
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
|
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* useEffect(() => {
|
||||||
getCreatorData()
|
getCreatorData()
|
||||||
.then(_data =>setCreatorData(_data));
|
.then(_data =>setCreatorData(_data));
|
||||||
},[]);
|
},[]);*/
|
||||||
|
|
||||||
|
|
||||||
const getCreatorData = async function () {
|
|
||||||
const response = await fetch(host + "/creator");
|
|
||||||
const _data = await response.json()
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCreator(creatorId)
|
getCreator().then(_data => {
|
||||||
.then(_data =>setCreator(_data));
|
setCreator(_data)
|
||||||
},[creatorId]);
|
console.log(_data);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const getCreator = async function (id) {
|
const getCreator = async function () {
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/creator/` + id, requestParams);
|
let login = localStorage.getItem("user");
|
||||||
|
console.log(host + `/creator/` + login);
|
||||||
|
const response = await fetch(host + `/creator/` + login, requestParams);
|
||||||
|
const _data = await response.json()
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCreatorData = async function () {
|
||||||
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response = await fetch(host + "/creator", requestParams);
|
||||||
|
console.log(response);
|
||||||
const _data = await response.json()
|
const _data = await response.json()
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const updateButton = (e) =>{
|
const updateButton = (e) =>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
update().then((result) => {
|
update().then((result) => {
|
||||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||||
getCreator(creatorId)
|
getCreator(creator.id)
|
||||||
.then(_data =>setCreator(_data));
|
.then(_data =>setCreator(_data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -68,13 +89,14 @@ export default function CreatorAction() {
|
|||||||
}
|
}
|
||||||
mangaModel.id = mangaId;
|
mangaModel.id = mangaId;
|
||||||
mangaModel.chapterCount = chapterCount;
|
mangaModel.chapterCount = chapterCount;
|
||||||
mangaModel.creatorId = creatorId;
|
mangaModel.creatorId = creator.id;
|
||||||
mangaModel.image = imageURL;
|
mangaModel.image = imageURL;
|
||||||
mangaModel.mangaName = mangaName;
|
mangaModel.mangaName = mangaName;
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify(mangaModel),
|
body: JSON.stringify(mangaModel),
|
||||||
};
|
};
|
||||||
@ -88,7 +110,7 @@ export default function CreatorAction() {
|
|||||||
|
|
||||||
const removeButton = (id) =>{
|
const removeButton = (id) =>{
|
||||||
remove(id).then(() => {
|
remove(id).then(() => {
|
||||||
getCreator(creatorId)
|
getCreator(creator.id)
|
||||||
.then(_data =>setCreator(_data));
|
.then(_data =>setCreator(_data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -104,6 +126,7 @@ export default function CreatorAction() {
|
|||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/manga/` + id, requestParams);
|
const response = await fetch(host + `/manga/` + id, requestParams);
|
||||||
@ -113,20 +136,22 @@ export default function CreatorAction() {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
create().then((result) => {
|
create().then((result) => {
|
||||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||||
getCreator(creatorId)
|
getCreator(creator.id)
|
||||||
.then(_data =>setCreator(_data));
|
.then(_data =>setCreator(_data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = async function (){
|
const create = async function (){
|
||||||
mangaModel.chapterCount = chapterCount;
|
mangaModel.chapterCount = chapterCount;
|
||||||
mangaModel.creatorId = creatorId;
|
mangaModel.creatorId = creator.id;
|
||||||
mangaModel.image = imageURL;
|
mangaModel.image = imageURL;
|
||||||
mangaModel.mangaName = mangaName;
|
mangaModel.mangaName = mangaName;
|
||||||
|
console.log(mangaModel);
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify(mangaModel),
|
body: JSON.stringify(mangaModel),
|
||||||
};
|
};
|
||||||
@ -156,16 +181,6 @@ export default function CreatorAction() {
|
|||||||
<h1>Creator</h1>
|
<h1>Creator</h1>
|
||||||
<form id="form">
|
<form id="form">
|
||||||
<div className="d-flex mt-3">
|
<div className="d-flex mt-3">
|
||||||
<div className="col-sm-2 me-3">
|
|
||||||
<select className="form-select" value={creatorId} onChange={event => setCreatorId(event.target.value)} aria-label="Default select example">
|
|
||||||
<option value={0}>Creator</option>
|
|
||||||
{
|
|
||||||
creatorData?.map((creatorD) =>
|
|
||||||
<option key={creatorD.id} value={creatorD.id}>{creatorD.creatorName}</option>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div className="d-grid col-sm-2">
|
<div className="d-grid col-sm-2">
|
||||||
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
||||||
</div>
|
</div>
|
||||||
|
90
front/src/Main/LoginPage.jsx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
|
const hostURL = "http://localhost:8080";
|
||||||
|
|
||||||
|
const LoginPage = function () {
|
||||||
|
|
||||||
|
const loginInput = useRef();
|
||||||
|
const passwordInput = useRef();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const login = async function (login, password) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({login: login, password: password}),
|
||||||
|
};
|
||||||
|
const response = await fetch(hostURL + "/jwt/login", requestParams);
|
||||||
|
const result = await response.text();
|
||||||
|
if (response.status === 200) {
|
||||||
|
localStorage.setItem("token", result);
|
||||||
|
localStorage.setItem("user", login);
|
||||||
|
getRole(result);
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
localStorage.removeItem("role");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getRole = async function (token) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = hostURL + `/who_am_i?token=${token}`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
|
const result = await response.text();
|
||||||
|
localStorage.setItem("role", result);
|
||||||
|
window.dispatchEvent(new Event("storage"));
|
||||||
|
navigate("/reader");
|
||||||
|
}
|
||||||
|
|
||||||
|
const loginFormOnSubmit = function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
login(loginInput.current.value, passwordInput.current.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<form onSubmit={(event) => loginFormOnSubmit(event)}>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Login</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="text" required autoFocus
|
||||||
|
ref={loginInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Password</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="password" required
|
||||||
|
ref={passwordInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<button type="submit" className="btn btn-success">
|
||||||
|
Sing in
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<span>Not a member yet? </span>
|
||||||
|
<Link to="/singup">Sing Up here</Link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginPage;
|
@ -8,7 +8,11 @@ export default function MangaPage() {
|
|||||||
|
|
||||||
const [readerData, setReaderData] = useState([]);
|
const [readerData, setReaderData] = useState([]);
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const quryString = window.location.search;
|
const quryString = window.location.search;
|
||||||
@ -29,6 +33,7 @@ export default function MangaPage() {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/manga/` + id + `/readers`, requestParams);
|
const response = await fetch(host + `/manga/` + id + `/readers`, requestParams);
|
||||||
@ -52,6 +57,7 @@ export default function MangaPage() {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/manga/` + id, requestParams);
|
const response = await fetch(host + `/manga/` + id, requestParams);
|
||||||
@ -72,7 +78,6 @@ export default function MangaPage() {
|
|||||||
<div className="container d-flex" >
|
<div className="container d-flex" >
|
||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
<img className="img_style01" style={{borderRadius: "3%"}}src={mangaModel.image} alt={mangaModel.mangaName}/>
|
<img className="img_style01" style={{borderRadius: "3%"}}src={mangaModel.image} alt={mangaModel.mangaName}/>
|
||||||
<button type="button" onClick={addMangaButton} className="btn btn-primary mt-3">Добавить в избранное</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="container table text-white fs-4 ms-4">
|
<div className="container table text-white fs-4 ms-4">
|
||||||
<div className="row text-white fw-bold fs-3">О манге</div>
|
<div className="row text-white fw-bold fs-3">О манге</div>
|
||||||
|
@ -6,14 +6,12 @@ import AddMangaReaderModal from "../components/Modal/AddMangaReaderModal";
|
|||||||
|
|
||||||
export default function ReaderAction() {
|
export default function ReaderAction() {
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
const [mangaData, setMangaData] = useState([]);
|
const [mangaData, setMangaData] = useState([]);
|
||||||
|
|
||||||
const [readerData, setReaderData] = useState([]);
|
const [readerData, setReaderData] = useState([]);
|
||||||
|
|
||||||
const [readerId, setReaderId] = useState(0);
|
|
||||||
|
|
||||||
const [reader, setReader] = useState([]);
|
const [reader, setReader] = useState([]);
|
||||||
|
|
||||||
const [mangaId, setMangaId] = useState(0);
|
const [mangaId, setMangaId] = useState(0);
|
||||||
@ -22,11 +20,16 @@ export default function ReaderAction() {
|
|||||||
|
|
||||||
const [mangaName, setMangaName] = useState("");
|
const [mangaName, setMangaName] = useState("");
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const quryString = window.location.search;
|
const quryString = window.location.search;
|
||||||
const urlParams = new URLSearchParams(quryString);
|
const urlParams = new URLSearchParams(quryString);
|
||||||
const id = urlParams.get('id');
|
const id = urlParams.get('id');
|
||||||
setReaderId(id);
|
console.log(id);
|
||||||
|
if (id !== null) setReaderId(id);
|
||||||
getReaderData()
|
getReaderData()
|
||||||
.then(_data =>setReaderData(_data));
|
.then(_data =>setReaderData(_data));
|
||||||
getMangaData()
|
getMangaData()
|
||||||
@ -36,48 +39,61 @@ export default function ReaderAction() {
|
|||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
const getReaderData = async function () {
|
const getReaderData = async function () {
|
||||||
const response = await fetch(host + "/reader");
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response = await fetch(host + "/reader", requestParams);
|
||||||
const _data = await response.json()
|
const _data = await response.json()
|
||||||
console.log(_data);
|
console.log(_data);
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getMangaData = async function () {
|
const getMangaData = async function () {
|
||||||
const response = await fetch(host + "/manga");
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response = await fetch(host + "/manga", requestParams);
|
||||||
const _data = await response.json()
|
const _data = await response.json()
|
||||||
console.log(_data);
|
console.log(_data);
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log(readerId);
|
|
||||||
getReader(readerId)
|
|
||||||
.then(_data =>setReader(_data));
|
|
||||||
console.log(readerId);
|
|
||||||
},[readerId]);
|
|
||||||
|
|
||||||
const getReader = async function (id) {
|
|
||||||
|
useEffect(() => {
|
||||||
|
getReader().then(_data => {
|
||||||
|
setReader(_data);
|
||||||
|
console.log(_data);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getReader = async function () {
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/reader/` + id, requestParams);
|
let login = localStorage.getItem("user");
|
||||||
|
console.log(host + `/reader/` + login);
|
||||||
|
const response = await fetch(host + `/reader/` + login, requestParams);
|
||||||
const _data = await response.json()
|
const _data = await response.json()
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateButton = (e) =>{
|
const updateButton = (e) =>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
update().then((result) => {
|
update().then((result) => {
|
||||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||||
getReader(readerId)
|
getReader()
|
||||||
.then(_data =>setReader(_data));
|
.then(_data =>setReader(_data));
|
||||||
});
|
});
|
||||||
console.log(readerId);
|
|
||||||
|
|
||||||
console.log(readerId);
|
|
||||||
console.log(reader);
|
console.log(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +106,7 @@ export default function ReaderAction() {
|
|||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/manga/${mangaId}?chapterCount=${chapterCount}`, requestParams);
|
const response = await fetch(host + `/manga/${mangaId}?chapterCount=${chapterCount}`, requestParams);
|
||||||
@ -102,7 +119,7 @@ export default function ReaderAction() {
|
|||||||
|
|
||||||
const removeButton = (id) =>{
|
const removeButton = (id) =>{
|
||||||
remove(id).then((result) => {
|
remove(id).then((result) => {
|
||||||
getReader(readerId)
|
getReader()
|
||||||
.then(_data =>setReader(_data));
|
.then(_data =>setReader(_data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -117,10 +134,11 @@ export default function ReaderAction() {
|
|||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
|
console.log(host + `/reader/${reader.id}/removeManga?mangaId=${id}`, requestParams);
|
||||||
const response = await fetch(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
|
const response = await fetch(host + `/reader/${reader.id}/removeManga?mangaId=${id}`, requestParams);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +148,7 @@ export default function ReaderAction() {
|
|||||||
addManga().then((result) => {
|
addManga().then((result) => {
|
||||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||||
console.log(result);
|
console.log(result);
|
||||||
getReader(readerId)
|
getReader()
|
||||||
.then(_data =>setReader(_data));
|
.then(_data =>setReader(_data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -140,10 +158,11 @@ export default function ReaderAction() {
|
|||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
|
console.log(host + `/reader/${reader.id}/addManga?mangaId=${mangaId}`, requestParams);
|
||||||
const response = await fetch(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
|
const response = await fetch(host + `/reader/${reader.id}/addManga?mangaId=${mangaId}`, requestParams);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,16 +173,6 @@ export default function ReaderAction() {
|
|||||||
<h1>Reader</h1>
|
<h1>Reader</h1>
|
||||||
<form id="form">
|
<form id="form">
|
||||||
<div className="d-flex mt-3">
|
<div className="d-flex mt-3">
|
||||||
<div className="col-sm-2 me-3">
|
|
||||||
<select className="form-select" value={readerId} onChange={event => setReaderId(event.target.value)} aria-label="Default select example">
|
|
||||||
<option value={0}>Reader</option>
|
|
||||||
{
|
|
||||||
readerData.map((readerD) =>
|
|
||||||
<option key={readerD.id} value={readerD.id}>{readerD.readerName}</option>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div className="d-grid col-sm-2">
|
<div className="d-grid col-sm-2">
|
||||||
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
||||||
</div>
|
</div>
|
||||||
|
88
front/src/Main/SingupPage.jsx
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
|
const hostURL = "http://localhost:8080";
|
||||||
|
|
||||||
|
const SingupPage = function () {
|
||||||
|
|
||||||
|
const loginInput = useRef();
|
||||||
|
const emailInput = useRef();
|
||||||
|
const passwordInput = useRef();
|
||||||
|
const passwordConfirmInput = useRef();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const singup = async function (userSinginDto) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(userSinginDto),
|
||||||
|
};
|
||||||
|
console.log(hostURL + "/sing_up");
|
||||||
|
console.log(userSinginDto);
|
||||||
|
const response = await fetch(hostURL + "/sing_up", requestParams);
|
||||||
|
const result = await response.text();
|
||||||
|
alert(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
const singupFormOnSubmit = function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const userSinginDto = {
|
||||||
|
login: loginInput.current.value,
|
||||||
|
email: emailInput.current.value,
|
||||||
|
password: passwordInput.current.value,
|
||||||
|
passwordConfirm: passwordConfirmInput.current.value
|
||||||
|
}
|
||||||
|
singup(userSinginDto);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<form onSubmit={(event) => singupFormOnSubmit(event)}>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Login</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="text" required maxLength="64"
|
||||||
|
ref={loginInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Email</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="text" required
|
||||||
|
ref={emailInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Password</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="password" required minLength="3" maxLength="64"
|
||||||
|
ref={passwordInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<p className="mb-1">Confirm Password</p>
|
||||||
|
<input className="form-control"
|
||||||
|
type="password" required minLength="3" maxLength="64"
|
||||||
|
ref={passwordConfirmInput} />
|
||||||
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<button type="submit" className="btn btn-success">
|
||||||
|
Create account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<span>Already have an account? </span>
|
||||||
|
<Link to="/login">Sing In here</Link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SingupPage;
|
112
front/src/Main/UsersPage.jsx
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
const hostURL = "http://localhost:8080";
|
||||||
|
const host = hostURL + "/api/1.0";
|
||||||
|
|
||||||
|
const UsersPage = function () {
|
||||||
|
|
||||||
|
const [users, setUsers] = useState([]);
|
||||||
|
const [pageNumbers, setPageNumbers] = useState([]);
|
||||||
|
const [pageNumber, setPageNumber] = useState();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUsers(1);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUsers = async function (page) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = host + `/users?page=${page}`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
|
const data = await response.json();
|
||||||
|
setUsers(data.first.content);
|
||||||
|
setPageNumber(data.first.number);
|
||||||
|
setPageNumbers(data.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeUser = async function (id) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = host + `/user/${id}`;
|
||||||
|
await fetch(requestUrl, requestParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageButtonOnClick = function (page) {
|
||||||
|
getUsers(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeButtonOnClick = function (id) {
|
||||||
|
const confirmResult = confirm("Are you sure you want to remove " +
|
||||||
|
"the selected user?");
|
||||||
|
if (confirmResult === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeUser(id).then(() => getUsers(pageNumber + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="table-shell mb-3">
|
||||||
|
<table className="table text-white">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style={{ width: "10%" }} scope="col">#</th>
|
||||||
|
<th style={{ width: "15%" }} scope="col">ID</th>
|
||||||
|
<th style={{ width: "30%" }} scope="col">Login</th>
|
||||||
|
<th style={{ width: "30%" }} scope="col">Email</th>
|
||||||
|
<th style={{ width: "15%" }} scope="col">Role</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{users.map((user, index) => (
|
||||||
|
<tr>
|
||||||
|
<th style={{ width: "10%" }} scope="row">{index}</th>
|
||||||
|
<td style={{ width: "15%" }}>{user.id}</td>
|
||||||
|
<td style={{ width: "30%" }}>{user.login}</td>
|
||||||
|
<td style={{ width: "30%" }}>{user.email}</td>
|
||||||
|
<td style={{ width: "15%" }}>{user.role}</td>
|
||||||
|
{user.login !== localStorage.getItem("user") ?
|
||||||
|
<td style={{ width: "1%" }}>
|
||||||
|
<button className="btn btn-secondary btn-sm"
|
||||||
|
onClick={() => removeButtonOnClick(user.id)}>
|
||||||
|
del
|
||||||
|
</button>
|
||||||
|
</td> : null}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Pages:
|
||||||
|
</p>
|
||||||
|
<nav>
|
||||||
|
<ul className="pagination">
|
||||||
|
{pageNumbers.map((number) => (
|
||||||
|
<li className={`page-item ${number === pageNumber + 1 ? "active" : ""}`}
|
||||||
|
onClick={() => pageButtonOnClick(number)}>
|
||||||
|
<a className="page-link" href="#">{number}</a>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UsersPage;
|
@ -4,7 +4,7 @@ import MangaDto from '../Dto/Manga-Dto';
|
|||||||
|
|
||||||
export default function Creator() {
|
export default function Creator() {
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
const [creatorId, setCreatorId] = useState(0);
|
const [creatorId, setCreatorId] = useState(0);
|
||||||
|
|
||||||
@ -16,6 +16,9 @@ export default function Creator() {
|
|||||||
|
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
const table = document.getElementById("tbody");
|
const table = document.getElementById("tbody");
|
||||||
|
|
||||||
@ -24,15 +27,23 @@ export default function Creator() {
|
|||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
const getData = async function () {
|
const getData = async function () {
|
||||||
const response = await fetch(host + "/creator");
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = host + `/creator`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
setData(await response.json())
|
setData(await response.json())
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = async function (){
|
const create = async function (){
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -52,6 +63,7 @@ export default function Creator() {
|
|||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -69,6 +81,9 @@ export default function Creator() {
|
|||||||
}
|
}
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
await fetch(host + `/creator/`, requestParams);
|
await fetch(host + `/creator/`, requestParams);
|
||||||
}
|
}
|
||||||
@ -81,6 +96,7 @@ export default function Creator() {
|
|||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ import TableReader from '../components/Table/TableReader';
|
|||||||
|
|
||||||
export default function ReaderS() {
|
export default function ReaderS() {
|
||||||
|
|
||||||
const host = "http://localhost:8080/api";
|
const host = "http://localhost:8080/api/1.0";
|
||||||
|
|
||||||
const [readerId, setReaderId] = useState(0);
|
const [readerId, setReaderId] = useState(0);
|
||||||
|
|
||||||
@ -15,8 +15,9 @@ export default function ReaderS() {
|
|||||||
|
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
const table = document.getElementById("tbody");
|
const table = document.getElementById("tbody");
|
||||||
|
|
||||||
@ -25,21 +26,30 @@ export default function ReaderS() {
|
|||||||
console.log(2);
|
console.log(2);
|
||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
|
|
||||||
const getData = async function () {
|
const getData = async function () {
|
||||||
const response = await fetch(host + "/reader");
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = host + `/reader`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
setData(await response.json())
|
setData(await response.json())
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = async function (){
|
const create = async function (){
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/reader?readerName=${readerName}&password=${password}`, requestParams);
|
const response = await fetch(host + `/reader?readerName=${readerName}&password=${password}`, requestParams);
|
||||||
|
alert(response);
|
||||||
|
console.log(response);
|
||||||
getData();
|
getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +65,7 @@ export default function ReaderS() {
|
|||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(host + `/reader/` + id, requestParams);
|
const response = await fetch(host + `/reader/` + id, requestParams);
|
||||||
@ -70,6 +81,9 @@ export default function ReaderS() {
|
|||||||
}
|
}
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
await fetch(host + `/reader/`, requestParams);
|
await fetch(host + `/reader/`, requestParams);
|
||||||
getData();
|
getData();
|
||||||
@ -83,6 +97,7 @@ export default function ReaderS() {
|
|||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -100,6 +115,7 @@ export default function ReaderS() {
|
|||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -112,6 +128,7 @@ export default function ReaderS() {
|
|||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import React from 'react'
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import banner1 from "../../../img/popular_1.jpg";
|
|
||||||
import banner2 from "../../../img/popular_2.jpg";
|
|
||||||
import banner3 from "../../../img/popular_3.jpg"
|
|
||||||
|
|
||||||
export default function Banner() {
|
|
||||||
const length = 3;
|
|
||||||
var old = length - 1;
|
|
||||||
var current = 0;
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [bannerState, setBannerState] = useState(["show", "hide", "hide"]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const timer = window.setInterval(() => {
|
|
||||||
setBannerState([
|
|
||||||
...bannerState,
|
|
||||||
(bannerState[current] = "show"),
|
|
||||||
(bannerState[old] = "hide"),
|
|
||||||
]);
|
|
||||||
//setBannerState([...bannerState, ]);
|
|
||||||
|
|
||||||
console.info("Banner changed");
|
|
||||||
|
|
||||||
old = current;
|
|
||||||
current++;
|
|
||||||
|
|
||||||
if (current === length) {
|
|
||||||
current = 0;
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.clearInterval(timer);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="d-flex align-items-center flex-column" id="banner">
|
|
||||||
<a className={bannerState[0]} style={{ cursor: "pointer" }}><img src={banner1}/></a>
|
|
||||||
<a className={bannerState[1]} style={{ cursor: "pointer" }}><img src={banner2}/></a>
|
|
||||||
<a className={bannerState[2]} style={{ cursor: "pointer" }}><img src={banner3}/></a>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#banner {
|
|
||||||
margin: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes newAnim {
|
|
||||||
from { opacity: 0; }
|
|
||||||
to { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#banner img {
|
|
||||||
max-width: 90%;
|
|
||||||
border-radius: 5px;
|
|
||||||
animation: newAnim 1s forwards;
|
|
||||||
}
|
|
||||||
|
|
||||||
#banner a.show {
|
|
||||||
text-align: center;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#banner a.hide {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
img.show {
|
|
||||||
max-height: 200px;
|
|
||||||
width: auto;
|
|
||||||
opacity: 1;
|
|
||||||
transition: opacity 1s, visibility 0s;
|
|
||||||
}
|
|
||||||
|
|
||||||
img.hide {
|
|
||||||
max-height: 0;
|
|
||||||
width: 0;
|
|
||||||
opacity: 0;
|
|
||||||
visibility: hidden;
|
|
||||||
transition: opacity 1s, visibility 0s 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 700px){
|
|
||||||
#banner{width: 0px;}
|
|
||||||
#banner_2{width: 0px;}
|
|
||||||
#banner img.show {
|
|
||||||
height: 0;
|
|
||||||
width: 0;
|
|
||||||
opacity: 0;
|
|
||||||
visibility: hidden;
|
|
||||||
transition: opacity 1s, visibility 0s 1s;
|
|
||||||
}
|
|
||||||
#banner h3{
|
|
||||||
font-size: 0em;
|
|
||||||
}
|
|
||||||
#banner_2 h3{
|
|
||||||
font-size: 0em;
|
|
||||||
}
|
|
||||||
#banner_2 img.show {
|
|
||||||
height: 0;
|
|
||||||
width: 0;
|
|
||||||
opacity: 0;
|
|
||||||
visibility: hidden;
|
|
||||||
transition: opacity 1s, visibility 0s 1s;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,65 @@
|
|||||||
import { NavLink } from 'react-router-dom';
|
import {NavLink, useNavigate} from 'react-router-dom';
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
export default function Header(props) {
|
export default function Header(props) {
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener("storage", () => {
|
||||||
|
let token = localStorage.getItem("token");
|
||||||
|
if (token) {
|
||||||
|
getRole(token).then((role) => {
|
||||||
|
if (localStorage.getItem("role") != role) {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
localStorage.removeItem("role");
|
||||||
|
window.dispatchEvent(new Event("storage"));
|
||||||
|
navigate("/catalog");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const getRole = async function (token) {
|
||||||
|
const requestParams = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = `http://localhost:8080/who_am_i?token=${token}`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
|
return await response.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
const logoutButtonOnClick = function () {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
localStorage.removeItem("role");
|
||||||
|
window.dispatchEvent(new Event("storage"));
|
||||||
|
navigate("/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
const [userRole, setUserRole] = useState("NONE");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener("storage", () => {
|
||||||
|
getUserRole();
|
||||||
|
});
|
||||||
|
getUserRole();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const getUserRole = function () {
|
||||||
|
const role = localStorage.getItem("role") || "NONE";
|
||||||
|
setUserRole(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
const validate = function (userGroup) {
|
||||||
|
return (userGroup === "AUTH" && userRole !== "NONE") || (userGroup === userRole);
|
||||||
|
}
|
||||||
|
console.log(userRole);
|
||||||
return (
|
return (
|
||||||
<nav className="navbar navbar-expand-lg navbar-dark">
|
<nav className="navbar navbar-expand-lg navbar-dark">
|
||||||
<div className="container-fluid">
|
<div className="container-fluid">
|
||||||
@ -11,14 +70,27 @@ export default function Header(props) {
|
|||||||
</button>
|
</button>
|
||||||
<div className="collapse navbar-collapse" id="navbarNav">
|
<div className="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul className="navbar-nav">
|
<ul className="navbar-nav">
|
||||||
{props.links.map(route =>
|
{props.links.map(route =>{
|
||||||
|
if (validate(route.userGroup)) {
|
||||||
|
return (
|
||||||
<li key={route.path}
|
<li key={route.path}
|
||||||
className="nav-item">
|
className="nav-item">
|
||||||
<NavLink className="nav-link" to={route.path}>
|
<NavLink className="nav-link" to={route.path}>
|
||||||
{route.label}
|
{route.label}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</li>
|
</li>
|
||||||
|
);}}
|
||||||
)}
|
)}
|
||||||
|
{userRole === "NONE"?
|
||||||
|
null
|
||||||
|
:
|
||||||
|
<div className="border-bottom pb-3 mb-3">
|
||||||
|
<button className="btn btn-primary"
|
||||||
|
onClick={logoutButtonOnClick}>
|
||||||
|
Log Out
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,10 +10,8 @@ export default function ReaderList(props) {
|
|||||||
props.readers?.map((reader) =>
|
props.readers?.map((reader) =>
|
||||||
<div key={reader.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
<div key={reader.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
||||||
<div>
|
<div>
|
||||||
<div className="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
<div className="text-white pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
||||||
<NavLink className="text-white fs-5 fw-bold pt-3 mb-3"
|
Имя пользователя: {reader.readerName}
|
||||||
to={`/readeraction?id=${reader.id}`}>Имя пользователя: {reader.readerName}
|
|
||||||
</NavLink>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
17
front/src/components/PrivateRoutes.jsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {Navigate, Outlet, useNavigate} from 'react-router-dom';
|
||||||
|
import {useEffect} from "react";
|
||||||
|
|
||||||
|
const PrivateRoutes = (props) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let isAllowed = false;
|
||||||
|
let userRole = localStorage.getItem("role");
|
||||||
|
if ((props.userGroup === "AUTH" && userRole) || (props.userGroup === userRole)) {
|
||||||
|
isAllowed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAllowed ? <Outlet /> : <Navigate to="/login" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PrivateRoutes;
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.configuration.jwt.JwtFilter;
|
||||||
|
import io.swagger.v3.oas.models.Components;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class OpenAPI30Configuration {
|
||||||
|
public static final String API_PREFIX = "/api/1.0";
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI customizeOpenAPI() {
|
||||||
|
final String securitySchemeName = JwtFilter.TOKEN_BEGIN_STR;
|
||||||
|
return new OpenAPI()
|
||||||
|
.addSecurityItem(new SecurityRequirement()
|
||||||
|
.addList(securitySchemeName))
|
||||||
|
.components(new Components()
|
||||||
|
.addSecuritySchemes(securitySchemeName, new SecurityScheme()
|
||||||
|
.name(securitySchemeName)
|
||||||
|
.type(SecurityScheme.Type.HTTP)
|
||||||
|
.scheme("bearer")
|
||||||
|
.bearerFormat("JWT")));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.LabWork.app.MangaStore.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 passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.configuration.jwt.JwtFilter;
|
||||||
|
import com.LabWork.app.MangaStore.controller.UserController;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
|
import com.LabWork.app.MangaStore.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.method.configuration.EnableMethodSecurity;
|
||||||
|
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.config.http.SessionCreationPolicy;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
@EnableMethodSecurity(
|
||||||
|
securedEnabled = true
|
||||||
|
)
|
||||||
|
public class SecurityConfiguration {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
||||||
|
public static final String SPA_URL_MASK = "/{path:[^\\.]*}";
|
||||||
|
private final UserService userService;
|
||||||
|
private final JwtFilter jwtFilter;
|
||||||
|
|
||||||
|
public SecurityConfiguration(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
this.jwtFilter = new JwtFilter(userService);
|
||||||
|
createAdminOnStartup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAdminOnStartup() {
|
||||||
|
final String admin = "admin";
|
||||||
|
if (userService.findByLogin(admin) == null) {
|
||||||
|
log.info("Admin user successfully created");
|
||||||
|
userService.addUser(admin, "admin@gmail.com", admin, admin, UserRole.ADMIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
|
http.cors()
|
||||||
|
.and()
|
||||||
|
.csrf().disable()
|
||||||
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
|
.and()
|
||||||
|
.authorizeHttpRequests()
|
||||||
|
.requestMatchers("/", SPA_URL_MASK).permitAll()
|
||||||
|
.requestMatchers(HttpMethod.POST, UserController.URL_LOGIN).permitAll()
|
||||||
|
.requestMatchers(HttpMethod.POST, UserController.URL_SING_UP).permitAll()
|
||||||
|
.requestMatchers(HttpMethod.POST, UserController.URL_WHO_AM_I).permitAll()
|
||||||
|
.anyRequest()
|
||||||
|
.authenticated()
|
||||||
|
.and()
|
||||||
|
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
|
||||||
|
.anonymous();
|
||||||
|
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(HttpMethod.OPTIONS, "/**")
|
||||||
|
.requestMatchers("/*.js")
|
||||||
|
.requestMatchers("/*.html")
|
||||||
|
.requestMatchers("/*.css")
|
||||||
|
.requestMatchers("/assets/**")
|
||||||
|
.requestMatchers("/favicon.ico")
|
||||||
|
.requestMatchers("/.js", "/.css")
|
||||||
|
.requestMatchers("/swagger-ui/index.html")
|
||||||
|
.requestMatchers("/webjars/**")
|
||||||
|
.requestMatchers("/swagger-resources/**")
|
||||||
|
.requestMatchers("/v3/api-docs/**")
|
||||||
|
.requestMatchers("/h2-console");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration;
|
||||||
|
|
||||||
|
import org.springframework.boot.web.server.ErrorPage;
|
||||||
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
|
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebConfiguration implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
|
registry.addViewController(SecurityConfiguration.SPA_URL_MASK).setViewName("forward:/");
|
||||||
|
registry.addViewController("/notFound").setViewName("forward:/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
|
||||||
|
return container -> container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**").allowedMethods("*");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration.jwt;
|
||||||
|
|
||||||
|
public class JwtException extends RuntimeException {
|
||||||
|
public JwtException(Throwable throwable) {
|
||||||
|
super(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JwtException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration.jwt;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.ServletRequest;
|
||||||
|
import jakarta.servlet.ServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.filter.GenericFilterBean;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class JwtFilter extends GenericFilterBean {
|
||||||
|
private static final String AUTHORIZATION = "Authorization";
|
||||||
|
public static final String TOKEN_BEGIN_STR = "Bearer ";
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public JwtFilter(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTokenFromRequest(HttpServletRequest request) {
|
||||||
|
String bearer = request.getHeader(AUTHORIZATION);
|
||||||
|
if (StringUtils.hasText(bearer) && bearer.startsWith(TOKEN_BEGIN_STR)) {
|
||||||
|
return bearer.substring(TOKEN_BEGIN_STR.length());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void raiseException(ServletResponse response, int status, String message) throws IOException {
|
||||||
|
if (response instanceof final HttpServletResponse httpResponse) {
|
||||||
|
httpResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
httpResponse.setStatus(status);
|
||||||
|
final byte[] body = new ObjectMapper().writeValueAsBytes(message);
|
||||||
|
response.getOutputStream().write(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request,
|
||||||
|
ServletResponse response,
|
||||||
|
FilterChain chain) throws IOException, ServletException {
|
||||||
|
if (request instanceof final HttpServletRequest httpRequest) {
|
||||||
|
final String token = getTokenFromRequest(httpRequest);
|
||||||
|
if (StringUtils.hasText(token)) {
|
||||||
|
try {
|
||||||
|
final UserDetails user = userService.loadUserByToken(token);
|
||||||
|
final UsernamePasswordAuthenticationToken auth =
|
||||||
|
new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||||
|
} catch (JwtException e) {
|
||||||
|
raiseException(response, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
raiseException(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||||
|
String.format("Internal error: %s", e.getMessage()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration.jwt;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "jwt", ignoreInvalidFields = true)
|
||||||
|
public class JwtProperties {
|
||||||
|
private String devToken = "";
|
||||||
|
private Boolean isDev = true;
|
||||||
|
|
||||||
|
public String getDevToken() {
|
||||||
|
return devToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevToken(String devToken) {
|
||||||
|
this.devToken = devToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isDev() {
|
||||||
|
return isDev;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDev(Boolean dev) {
|
||||||
|
isDev = dev;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
package com.LabWork.app.MangaStore.configuration.jwt;
|
||||||
|
|
||||||
|
import com.auth0.jwt.JWT;
|
||||||
|
import com.auth0.jwt.algorithms.Algorithm;
|
||||||
|
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||||||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||||
|
import com.auth0.jwt.interfaces.JWTVerifier;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class JwtProvider {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(JwtProvider.class);
|
||||||
|
|
||||||
|
private final static byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
|
||||||
|
private final static String ISSUER = "auth0";
|
||||||
|
|
||||||
|
private final Algorithm algorithm;
|
||||||
|
private final JWTVerifier verifier;
|
||||||
|
|
||||||
|
public JwtProvider(JwtProperties jwtProperties) {
|
||||||
|
if (!jwtProperties.isDev()) {
|
||||||
|
LOG.info("Generate new JWT key for prod");
|
||||||
|
try {
|
||||||
|
final MessageDigest salt = MessageDigest.getInstance("SHA-256");
|
||||||
|
salt.update(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
LOG.info("Use generated JWT key for prod \n{}", bytesToHex(salt.digest()));
|
||||||
|
algorithm = Algorithm.HMAC256(bytesToHex(salt.digest()));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new JwtException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG.info("Use default JWT key for dev \n{}", jwtProperties.getDevToken());
|
||||||
|
algorithm = Algorithm.HMAC256(jwtProperties.getDevToken());
|
||||||
|
}
|
||||||
|
verifier = JWT.require(algorithm)
|
||||||
|
.withIssuer(ISSUER)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String bytesToHex(byte[] bytes) {
|
||||||
|
byte[] hexChars = new byte[bytes.length * 2];
|
||||||
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
|
int v = bytes[j] & 0xFF;
|
||||||
|
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||||
|
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||||
|
}
|
||||||
|
return new String(hexChars, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateToken(String login) {
|
||||||
|
final Date issueDate = Date.from(LocalDate.now()
|
||||||
|
.atStartOfDay(ZoneId.systemDefault())
|
||||||
|
.toInstant());
|
||||||
|
final Date expireDate = Date.from(LocalDate.now()
|
||||||
|
.plusDays(15)
|
||||||
|
.atStartOfDay(ZoneId.systemDefault())
|
||||||
|
.toInstant());
|
||||||
|
return JWT.create()
|
||||||
|
.withIssuer(ISSUER)
|
||||||
|
.withIssuedAt(issueDate)
|
||||||
|
.withExpiresAt(expireDate)
|
||||||
|
.withSubject(login)
|
||||||
|
.sign(algorithm);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DecodedJWT validateToken(String token) {
|
||||||
|
try {
|
||||||
|
return verifier.verify(token);
|
||||||
|
} catch (JWTVerificationException e) {
|
||||||
|
throw new JwtException(String.format("Token verification error: %s", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTokenValid(String token) {
|
||||||
|
if (!StringUtils.hasText(token)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
validateToken(token);
|
||||||
|
return true;
|
||||||
|
} catch (JwtException e) {
|
||||||
|
LOG.error(e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getLoginFromToken(String token) {
|
||||||
|
try {
|
||||||
|
return Optional.ofNullable(validateToken(token).getSubject());
|
||||||
|
} catch (JwtException e) {
|
||||||
|
LOG.error(e.getMessage());
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,101 +0,0 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Creator;
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
|
||||||
import com.LabWork.app.MangaStore.service.MangaService;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.validation.BindingResult;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/creatorAction")
|
|
||||||
public class CreatorActionMvcController {
|
|
||||||
private final CreatorService creatorService;
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(CreatorActionMvcController.class);
|
|
||||||
private final MangaService mangaService;
|
|
||||||
|
|
||||||
public CreatorActionMvcController(CreatorService creatorService, MangaService mangaService) {
|
|
||||||
this.creatorService = creatorService;
|
|
||||||
this.mangaService = mangaService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping()
|
|
||||||
public String getCreator(@RequestParam(value = "creatorId", required = false) Long creatorId, Model model) {
|
|
||||||
model.addAttribute("creators",
|
|
||||||
creatorService.findAllCreators().stream()
|
|
||||||
.map(CreatorMangaDto::new)
|
|
||||||
.toList());
|
|
||||||
if(creatorId != null){
|
|
||||||
model.addAttribute("currentCreator", new CreatorMangaDto(creatorService.findCreator(creatorId)));
|
|
||||||
}
|
|
||||||
model.addAttribute("creatorId", creatorId);
|
|
||||||
return "creatorAction";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/edit/{id}")
|
|
||||||
public String editManga(@PathVariable Long id, Model model) {
|
|
||||||
model.addAttribute("Id", id);
|
|
||||||
model.addAttribute("mangaDto", new MangaDto(mangaService.findManga(id)));
|
|
||||||
model.addAttribute("controller", "manga/");
|
|
||||||
return "creatorAction-edit";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/create/{id}")
|
|
||||||
public String createManga(@PathVariable Long id, Model model) {
|
|
||||||
model.addAttribute("Id", id);
|
|
||||||
model.addAttribute("mangaDto", new MangaDto());
|
|
||||||
model.addAttribute("controller", "creator/");
|
|
||||||
return "creatorAction-edit";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping( "/creator/{creatorId}")
|
|
||||||
public String saveManga(@PathVariable(value = "creatorId", required = false) Long creatorId,
|
|
||||||
@RequestParam("multipartFile") MultipartFile multipartFile,
|
|
||||||
@ModelAttribute @Valid MangaDto mangaDto,
|
|
||||||
BindingResult bindingResult,
|
|
||||||
Model model) throws IOException {
|
|
||||||
if (bindingResult.hasErrors()) {
|
|
||||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
|
||||||
return "creatorAction-edit";
|
|
||||||
}
|
|
||||||
mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes()));
|
|
||||||
mangaDto.setCreatorId(creatorId);
|
|
||||||
mangaService.addManga(mangaDto);
|
|
||||||
return "redirect:/creatorAction?creatorId=" + creatorId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping( "/manga/{mangaId}")
|
|
||||||
public String updateManga(@PathVariable(value = "mangaId", required = false) Long mangaId, @RequestParam("multipartFile") MultipartFile multipartFile,
|
|
||||||
@ModelAttribute @Valid MangaDto mangaDto,
|
|
||||||
BindingResult bindingResult,
|
|
||||||
Model model) throws IOException {
|
|
||||||
if (bindingResult.hasErrors()) {
|
|
||||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
|
||||||
return "creatorAction-edit";
|
|
||||||
}
|
|
||||||
mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes()));
|
|
||||||
mangaService.updateManga(mangaId, mangaDto.getChapterCount(), mangaDto.getImage());
|
|
||||||
return "redirect:/creatorAction?creatorId=" + mangaService.findManga(mangaId).getCreatorId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/delete/{id}")
|
|
||||||
public String deleteCreator(@PathVariable Long id) {
|
|
||||||
Long creatorId = mangaService.findManga(id).getCreatorId();
|
|
||||||
mangaService.deleteManga(id);
|
|
||||||
if (creatorId != null){
|
|
||||||
return "redirect:/creatorAction?creatorId=" + creatorId;
|
|
||||||
} else {
|
|
||||||
return "redirect:/creatorAction";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Creator;
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
|
||||||
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.*;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/creator")
|
|
||||||
public class CreatorMvcController {
|
|
||||||
private final CreatorService creatorService;
|
|
||||||
|
|
||||||
public CreatorMvcController(CreatorService creatorService) {
|
|
||||||
this.creatorService = creatorService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public String getCreators(Model model) {
|
|
||||||
model.addAttribute("creators",
|
|
||||||
creatorService.findAllCreators().stream()
|
|
||||||
.map(CreatorMangaDto::new)
|
|
||||||
.toList());
|
|
||||||
return "creator";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
|
||||||
public String editCreator(@PathVariable(required = false) Long id,
|
|
||||||
Model model) {
|
|
||||||
if (id == null || id <= 0) {
|
|
||||||
model.addAttribute("CreatorMangaDto", new CreatorMangaDto());
|
|
||||||
} else {
|
|
||||||
model.addAttribute("creatorId", id);
|
|
||||||
model.addAttribute("CreatorMangaDto", new CreatorMangaDto(creatorService.findCreator(id)));
|
|
||||||
}
|
|
||||||
return "creator-edit";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(value = {"", "/{id}"})
|
|
||||||
public String saveCreator(@PathVariable(required = false) Long id,
|
|
||||||
@ModelAttribute @Valid CreatorMangaDto creatorMangaDto,
|
|
||||||
BindingResult bindingResult,
|
|
||||||
Model model) {
|
|
||||||
if (bindingResult.hasErrors()) {
|
|
||||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
|
||||||
return "creator-edit";
|
|
||||||
}
|
|
||||||
if (id == null || id <= 0) {
|
|
||||||
creatorService.addCreator(creatorMangaDto.getCreatorName(), creatorMangaDto.getHashedPassword());
|
|
||||||
} else {
|
|
||||||
creatorService.updateCreator(id, creatorMangaDto.getCreatorName(), creatorMangaDto.getHashedPassword());
|
|
||||||
}
|
|
||||||
return "redirect:/creator";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/delete/{id}")
|
|
||||||
public String deleteCreator(@PathVariable Long id) {
|
|
||||||
creatorService.deleteCreator(id);
|
|
||||||
return "redirect:/creator";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +1,28 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Creator;
|
package com.LabWork.app.MangaStore.controller;
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto;
|
import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto;
|
||||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
import com.LabWork.app.MangaStore.service.CreatorService;
|
||||||
import com.LabWork.app.WebConfiguration;
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(WebConfiguration.REST_API + "/creator")
|
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/creator")
|
||||||
public class CreatorController {
|
public class CreatorController {
|
||||||
private final CreatorService creatorService;
|
private final CreatorService creatorService;
|
||||||
|
|
||||||
public CreatorController(CreatorService creatorService) {
|
private final UserService userService;
|
||||||
|
|
||||||
|
public CreatorController(CreatorService creatorService,
|
||||||
|
UserService userService) {
|
||||||
this.creatorService = creatorService;
|
this.creatorService = creatorService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{login}")
|
||||||
public CreatorMangaDto getCreator(@PathVariable Long id) {
|
public CreatorMangaDto getCreator(@PathVariable String login) {
|
||||||
return new CreatorMangaDto(creatorService.findCreator(id));
|
return new CreatorMangaDto(creatorService.findCreator(userService.findByLogin(login).getCreator().getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@ -28,18 +32,18 @@ public class CreatorController {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
/* @PostMapping
|
||||||
public CreatorMangaDto createCreator(@RequestParam("creatorName") String creatorName,
|
public CreatorMangaDto createCreator(@RequestParam("creatorName") String creatorName,
|
||||||
@RequestParam("password") String password) {
|
@RequestParam("password") String password) {
|
||||||
return new CreatorMangaDto(creatorService.addCreator(creatorName, password));
|
return new CreatorMangaDto(creatorService.addCreator());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
/* @PutMapping("/{id}")
|
||||||
public CreatorMangaDto updateCreator(@PathVariable Long id,
|
public CreatorMangaDto updateCreator(@PathVariable Long id,
|
||||||
@RequestParam("creatorName") String creatorName,
|
@RequestParam("creatorName") String creatorName,
|
||||||
@RequestParam("password") String password) {
|
@RequestParam("password") String password) {
|
||||||
return new CreatorMangaDto(creatorService.updateCreator(id, creatorName, password));
|
return new CreatorMangaDto(creatorService.updateCreator(id, creatorName, password));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public CreatorMangaDto deleteCreator(@PathVariable Long id) {
|
public CreatorMangaDto deleteCreator(@PathVariable Long id) {
|
@ -1,38 +0,0 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Manga;
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto;
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.service.MangaService;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/manga")
|
|
||||||
public class MangaMvcController {
|
|
||||||
private final MangaService mangaService;
|
|
||||||
|
|
||||||
public MangaMvcController(MangaService mangaService) {
|
|
||||||
this.mangaService = mangaService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping()
|
|
||||||
public String getMangaAnfReaders(Model model) {
|
|
||||||
model.addAttribute("mangaList", mangaService.findAllMangas().stream()
|
|
||||||
.map(x -> new MangaDto(x))
|
|
||||||
.toList());
|
|
||||||
return "catalog";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public String getMangaAnfReaders(@PathVariable Long id, Model model) {
|
|
||||||
model.addAttribute("manga", new MangaReaderDto(mangaService.findManga(id), mangaService.getReader(id)));
|
|
||||||
model.addAttribute("readers", mangaService.getReader(id).stream()
|
|
||||||
.map(x -> new ReaderMangaDto(x))
|
|
||||||
.toList());
|
|
||||||
return "mangaPage";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +1,36 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Manga;
|
package com.LabWork.app.MangaStore.controller;
|
||||||
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto;
|
import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.MangaUserDto;
|
||||||
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
||||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
||||||
import com.LabWork.app.MangaStore.service.MangaService;
|
import com.LabWork.app.MangaStore.service.MangaService;
|
||||||
import com.LabWork.app.WebConfiguration;
|
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||||
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(WebConfiguration.REST_API + "/manga")
|
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/manga")
|
||||||
public class MangaController {
|
public class MangaController {
|
||||||
private final MangaService mangaService;
|
private final MangaService mangaService;
|
||||||
|
|
||||||
public MangaController(MangaService mangaService) {
|
private final UserService userService;
|
||||||
|
|
||||||
|
public MangaController(MangaService mangaService,
|
||||||
|
UserService userService) {
|
||||||
this.mangaService = mangaService;
|
this.mangaService = mangaService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public MangaReaderDto getManga(@PathVariable Long id) {
|
public MangaUserDto getManga(@PathVariable Long id) {
|
||||||
return new MangaReaderDto(mangaService.findManga(id), mangaService.getReader(id));
|
return new MangaUserDto(mangaService.findManga(id), mangaService.getReader(id).stream()
|
||||||
|
.map(x -> userService.findUser(x.getId()))
|
||||||
|
.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.LabWork.app.MangaStore.controller;
|
||||||
|
|
||||||
|
public class Pair<F, S> {
|
||||||
|
private final F first;
|
||||||
|
private final S second;
|
||||||
|
|
||||||
|
public Pair(F first, S second) {
|
||||||
|
this.first = first;
|
||||||
|
this.second = second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public F getFirst() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public S getSecond() {
|
||||||
|
return second;
|
||||||
|
}
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Reader;
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.service.ReaderService;
|
|
||||||
import com.LabWork.app.MangaStore.service.MangaService;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.validation.BindingResult;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/readerAction")
|
|
||||||
public class ReaderActionMvcController {
|
|
||||||
private final ReaderService readerService;
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(ReaderActionMvcController.class);
|
|
||||||
private final MangaService mangaService;
|
|
||||||
|
|
||||||
public ReaderActionMvcController(ReaderService readerService, MangaService mangaService) {
|
|
||||||
this.readerService = readerService;
|
|
||||||
this.mangaService = mangaService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping()
|
|
||||||
public String getReader(@RequestParam(value = "readerId", required = false) Long readerId, Model model) {
|
|
||||||
model.addAttribute("readers",
|
|
||||||
readerService.findAllReaders().stream()
|
|
||||||
.map(ReaderMangaDto::new)
|
|
||||||
.toList());
|
|
||||||
if (readerId != null){
|
|
||||||
model.addAttribute("readerId", readerId);
|
|
||||||
model.addAttribute("reader", new ReaderMangaDto(readerService.findReader(readerId)));
|
|
||||||
} else {
|
|
||||||
model.addAttribute("readerId", 0);
|
|
||||||
model.addAttribute("reader", new ReaderMangaDto());
|
|
||||||
}
|
|
||||||
model.addAttribute("MangaDto", new MangaDto());
|
|
||||||
model.addAttribute("mangaList", mangaService.findAllMangas());
|
|
||||||
return "readerAction";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/manga/{readerId}")
|
|
||||||
public String saveManga(@PathVariable Long readerId,
|
|
||||||
@RequestParam("mangaId") Long mangaId,
|
|
||||||
@ModelAttribute @Valid MangaDto MangaDto,
|
|
||||||
BindingResult bindingResult,
|
|
||||||
Model model){
|
|
||||||
if (bindingResult.hasErrors()) {
|
|
||||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
|
||||||
return "readerAction";
|
|
||||||
}
|
|
||||||
readerService.addManga(mangaId, readerId);
|
|
||||||
return "redirect:/readerAction/?readerId=" + readerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/{id}/removeManga/{mangaId}")
|
|
||||||
public String removeManga(@PathVariable Long id, @PathVariable Long mangaId) {
|
|
||||||
readerService.removeManga(mangaId, id);
|
|
||||||
return "redirect:/readerAction/?readerId=" + id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Reader;
|
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
|
||||||
import com.LabWork.app.MangaStore.service.ReaderService;
|
|
||||||
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.*;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/reader")
|
|
||||||
public class ReaderMvcController {
|
|
||||||
private final ReaderService readerService;
|
|
||||||
|
|
||||||
public ReaderMvcController(ReaderService readerService) {
|
|
||||||
this.readerService = readerService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public String getReaders(Model model) {
|
|
||||||
model.addAttribute("readers",
|
|
||||||
readerService.findAllReaders().stream()
|
|
||||||
.map(ReaderMangaDto::new)
|
|
||||||
.toList());
|
|
||||||
return "reader";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
|
||||||
public String editReader(@PathVariable(required = false) Long id,
|
|
||||||
Model model) {
|
|
||||||
if (id == null || id <= 0) {
|
|
||||||
model.addAttribute("ReaderMangaDto", new ReaderMangaDto());
|
|
||||||
} else {
|
|
||||||
model.addAttribute("readerId", id);
|
|
||||||
model.addAttribute("ReaderMangaDto", new ReaderMangaDto(readerService.findReader(id)));
|
|
||||||
}
|
|
||||||
return "reader-edit";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(value = {"", "/{id}"})
|
|
||||||
public String saveReader(@PathVariable(required = false) Long id,
|
|
||||||
@ModelAttribute @Valid ReaderMangaDto readerMangaDto,
|
|
||||||
BindingResult bindingResult,
|
|
||||||
Model model) {
|
|
||||||
if (bindingResult.hasErrors()) {
|
|
||||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
|
||||||
return "reader-edit";
|
|
||||||
}
|
|
||||||
if (id == null || id <= 0) {
|
|
||||||
readerService.addReader(readerMangaDto.getReaderName(), readerMangaDto.getHashedPassword());
|
|
||||||
} else {
|
|
||||||
readerService.updateReader(id, readerMangaDto.getReaderName(), readerMangaDto.getHashedPassword());
|
|
||||||
}
|
|
||||||
return "redirect:/reader";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/delete/{id}")
|
|
||||||
public String deleteReader(@PathVariable Long id) {
|
|
||||||
readerService.deleteReader(id);
|
|
||||||
return "redirect:/reader";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +1,34 @@
|
|||||||
package com.LabWork.app.MangaStore.controller.Reader;
|
package com.LabWork.app.MangaStore.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
|
||||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
||||||
import com.LabWork.app.MangaStore.service.ReaderService;
|
import com.LabWork.app.MangaStore.service.ReaderService;
|
||||||
import com.LabWork.app.WebConfiguration;
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
|
import com.LabWork.app.MangaStore.util.validation.ValidationException;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(WebConfiguration.REST_API + "/reader")
|
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/reader")
|
||||||
public class ReaderController {
|
public class ReaderController {
|
||||||
private final ReaderService readerService;
|
private final ReaderService readerService;
|
||||||
|
|
||||||
public ReaderController(ReaderService readerService) {
|
private final UserService userService;
|
||||||
|
|
||||||
|
public ReaderController(ReaderService readerService,
|
||||||
|
UserService userService) {
|
||||||
this.readerService = readerService;
|
this.readerService = readerService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{login}")
|
||||||
public ReaderMangaDto getReader(@PathVariable Long id) {
|
public ReaderMangaDto getReader(@PathVariable String login) {
|
||||||
return new ReaderMangaDto(readerService.findReader(id));
|
return new ReaderMangaDto(readerService.findReader(userService.findByLogin(login).getReader().getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@ -30,10 +38,15 @@ public class ReaderController {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
/* @PostMapping
|
||||||
public ReaderMangaDto createReader(@RequestParam("readerName") String readerName,
|
@Secured({UserRole.AsString.ADMIN})
|
||||||
|
public String createReader(@RequestParam("readerName") String readerName,
|
||||||
@RequestParam("password") String password) {
|
@RequestParam("password") String password) {
|
||||||
return new ReaderMangaDto(readerService.addReader(readerName, password));
|
try {
|
||||||
|
return new ReaderMangaDto(readerService.addReader(readerName, password)).toString();
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@ -41,7 +54,7 @@ public class ReaderController {
|
|||||||
@RequestParam("readerName") String readerName,
|
@RequestParam("readerName") String readerName,
|
||||||
@RequestParam("password") String password) {
|
@RequestParam("password") String password) {
|
||||||
return new ReaderMangaDto(readerService.updateReader(id, readerName, password));
|
return new ReaderMangaDto(readerService.updateReader(id, readerName, password));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@PutMapping("/{id}/addManga")
|
@PutMapping("/{id}/addManga")
|
||||||
public MangaDto addManga(@PathVariable Long id,
|
public MangaDto addManga(@PathVariable Long id,
|
@ -0,0 +1,90 @@
|
|||||||
|
package com.LabWork.app.MangaStore.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.UserDto;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.UserSignupDto;
|
||||||
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
|
import com.LabWork.app.MangaStore.util.validation.ValidationException;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
public static final String URL_LOGIN = "/jwt/login";
|
||||||
|
public static final String URL_SING_UP = "/sing_up";
|
||||||
|
public static final String URL_WHO_AM_I = "/who_am_i";
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public UserController(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(URL_LOGIN)
|
||||||
|
public String login(@RequestBody @Valid UserDto userDto) {
|
||||||
|
return userService.loginAndGetToken(userDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(URL_SING_UP)
|
||||||
|
public String singUp(@RequestBody @Valid UserSignupDto userSignupDto) {
|
||||||
|
try {
|
||||||
|
final User user = userService.addUser(userSignupDto.getLogin(), userSignupDto.getEmail(),
|
||||||
|
userSignupDto.getPassword(), userSignupDto.getPasswordConfirm(), UserRole.USER);
|
||||||
|
return "created " + user.getLogin();
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/user")
|
||||||
|
public UserDto getUser(@RequestParam("login") String login) {
|
||||||
|
User user = userService.findByLogin(login);
|
||||||
|
return new UserDto(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Secured(UserRole.AsString.ADMIN)
|
||||||
|
@PostMapping(OpenAPI30Configuration.API_PREFIX + "/user")
|
||||||
|
public String updateUser(@RequestBody @Valid UserDto userDto) {
|
||||||
|
try {
|
||||||
|
userService.updateUser(userDto);
|
||||||
|
return "Profile updated";
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Secured(UserRole.AsString.ADMIN)
|
||||||
|
@DeleteMapping(OpenAPI30Configuration.API_PREFIX + "/user/{id}")
|
||||||
|
public UserDto removeUser(@PathVariable Long id) {
|
||||||
|
User user = userService.deleteUser(id);
|
||||||
|
return new UserDto(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Secured(UserRole.AsString.ADMIN)
|
||||||
|
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/users")
|
||||||
|
public Pair<Page<UserDto>, List<Integer>> getUsers(@RequestParam(defaultValue = "1") int page,
|
||||||
|
@RequestParam(defaultValue = "5") int size) {
|
||||||
|
final Page<UserDto> users = userService.findAllPages(page, size)
|
||||||
|
.map(UserDto::new);
|
||||||
|
final int totalPages = users.getTotalPages();
|
||||||
|
final List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
||||||
|
.boxed()
|
||||||
|
.toList();
|
||||||
|
return new Pair<>(users, pageNumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(URL_WHO_AM_I)
|
||||||
|
public String whoAmI(@RequestParam("token") String token) {
|
||||||
|
UserDetails userDetails = userService.loadUserByToken(token);
|
||||||
|
User user = userService.findByLogin(userDetails.getUsername());
|
||||||
|
return user.getRole().toString();
|
||||||
|
}
|
||||||
|
}
|
@ -13,23 +13,10 @@ public class Creator {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank(message = "creatorName can't be null or empty")
|
|
||||||
@Column
|
|
||||||
private String creatorName;
|
|
||||||
|
|
||||||
@NotBlank(message = "hashedPassword can't be null or empty")
|
|
||||||
@Column
|
|
||||||
private String hashedPassword;
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "creator", cascade = CascadeType.REMOVE)
|
@OneToMany(fetch = FetchType.EAGER, mappedBy = "creator", cascade = CascadeType.REMOVE)
|
||||||
private List<Manga> mangas;
|
private List<Manga> mangas;
|
||||||
|
|
||||||
public Creator() {
|
public Creator() {
|
||||||
}
|
|
||||||
|
|
||||||
public Creator(String creatorName, String hashedPassword) {
|
|
||||||
this.creatorName = creatorName;
|
|
||||||
this.hashedPassword = hashedPassword;
|
|
||||||
this.mangas = new ArrayList<>();
|
this.mangas = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,26 +28,10 @@ public class Creator {
|
|||||||
return mangas;
|
return mangas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatorName() {
|
|
||||||
return creatorName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHashedPassword() {
|
|
||||||
return hashedPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMangas(List<Manga> mangas) {
|
public void setMangas(List<Manga> mangas) {
|
||||||
this.mangas = mangas;
|
this.mangas = mangas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreatorName(String creatorName) {
|
|
||||||
this.creatorName = creatorName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHashedPassword(String hashedPassword) {
|
|
||||||
this.hashedPassword = hashedPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
@ -78,8 +49,6 @@ public class Creator {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Creator{" +
|
return "Creator{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", creatorName='" + creatorName + '\'' +
|
|
||||||
", hashedPassword='" + hashedPassword + '\'' +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,40 +13,29 @@ public class Reader {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column
|
|
||||||
private String readerName;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String hashedPassword;
|
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||||
/*@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)*/
|
/*@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)*/
|
||||||
/*orphanRemoval=true*/
|
/*orphanRemoval=true*/
|
||||||
private List<Manga> mangas;
|
private List<Manga> mangas;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@MapsId
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
public Reader(User user) {
|
||||||
|
this.mangas = new ArrayList<>();
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
public Reader() {
|
public Reader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reader(String readerName, String hashedPassword) {
|
|
||||||
this.readerName = readerName;
|
|
||||||
this.hashedPassword = hashedPassword;
|
|
||||||
this.mangas = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getReaderName() { return readerName; }
|
|
||||||
|
|
||||||
public void setReaderName(String readerName) { this.readerName = readerName; }
|
|
||||||
|
|
||||||
public String getHashedPassword() { return hashedPassword; }
|
|
||||||
|
|
||||||
public void setHashedPassword(String hashedPassword) { this.hashedPassword = hashedPassword; }
|
|
||||||
|
|
||||||
public List<Manga> getMangas() { return mangas; }
|
public List<Manga> getMangas() { return mangas; }
|
||||||
|
|
||||||
public void setMangas(List<Manga> mangas) { this.mangas = mangas; }
|
public void setMangas(List<Manga> mangas) { this.mangas = mangas; }
|
||||||
@ -68,8 +57,6 @@ public class Reader {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Reader{" +
|
return "Reader{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", readerName='" + readerName + '\'' +
|
|
||||||
", hashedPassword='" + hashedPassword + '\'' +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
144
src/main/java/com/LabWork/app/MangaStore/model/Default/User.java
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
package com.LabWork.app.MangaStore.model.Default;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.UserDto;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.UserSignupDto;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
|
public class User {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
@NotBlank(message = "Login can't be null or empty")
|
||||||
|
@Size(min = 3, max = 64, message = "Incorrect login length")
|
||||||
|
private String login;
|
||||||
|
@NotBlank(message = "Email can't be null or empty")
|
||||||
|
@Size(min = 3, max = 64, message = "Incorrect login length")
|
||||||
|
private String email;
|
||||||
|
@NotBlank(message = "Password can't be null or empty")
|
||||||
|
@Size(min = 3, max = 64, message = "Incorrect password length")
|
||||||
|
private String password;
|
||||||
|
private UserRole role;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "creator_id")
|
||||||
|
private Creator creator;
|
||||||
|
|
||||||
|
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL)
|
||||||
|
@PrimaryKeyJoinColumn
|
||||||
|
private Reader reader;
|
||||||
|
|
||||||
|
public User() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(String login, String email, String password, UserRole role) {
|
||||||
|
this.login = login;
|
||||||
|
this.email = email;
|
||||||
|
this.password = password;
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(UserDto userDto) {
|
||||||
|
this.login = userDto.getLogin();
|
||||||
|
this.email = userDto.getEmail();
|
||||||
|
this.password = userDto.getPassword();
|
||||||
|
this.role = userDto.getRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(UserSignupDto userSignupDto) {
|
||||||
|
this.login = userSignupDto.getLogin();
|
||||||
|
this.email = userSignupDto.getEmail();
|
||||||
|
this.password = userSignupDto.getPassword();
|
||||||
|
this.role = UserRole.USER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogin() {
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogin(String login) {
|
||||||
|
this.login = login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserRole getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(UserRole role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreator(Creator creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Creator getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReader(Reader reader) {
|
||||||
|
this.reader = reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reader getReader() {
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ![Properties]
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
User marketUser = (User) o;
|
||||||
|
return Objects.equals(id, marketUser.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", userName='" + login + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
", password='" + password + '\'' +
|
||||||
|
", role='" + role + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.LabWork.app.MangaStore.model.Default;
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
@ -16,8 +16,6 @@ public class CreatorMangaDto {
|
|||||||
|
|
||||||
public CreatorMangaDto(Creator creator) {
|
public CreatorMangaDto(Creator creator) {
|
||||||
this.id = creator.getId();
|
this.id = creator.getId();
|
||||||
this.creatorName = creator.getCreatorName();
|
|
||||||
this.hashedPassword = creator.getHashedPassword();
|
|
||||||
this.mangas = creator.getMangas().stream()
|
this.mangas = creator.getMangas().stream()
|
||||||
.map(x -> new MangaDto(x))
|
.map(x -> new MangaDto(x))
|
||||||
.toList();
|
.toList();
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
package com.LabWork.app.MangaStore.model.Dto;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.SupportDto.ReaderDto;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MangaUserDto {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long creatorId;
|
||||||
|
private String mangaName;
|
||||||
|
private Integer chapterCount;
|
||||||
|
private List<ReaderDto> readers;
|
||||||
|
private String image;
|
||||||
|
|
||||||
|
public MangaUserDto() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MangaUserDto(Manga manga, List<User> listUser) {
|
||||||
|
this.id = manga.getId();
|
||||||
|
this.creatorId = manga.getCreator().getId();
|
||||||
|
this.mangaName = manga.getMangaName();
|
||||||
|
this.chapterCount = manga.getChapterCount();
|
||||||
|
this.image = new String(manga.getImage(), StandardCharsets.UTF_8);
|
||||||
|
this.readers = listUser.stream()
|
||||||
|
.map(y -> new ReaderDto(y.getReader(), y.getLogin()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMangaName() {
|
||||||
|
return mangaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReaderDto> getReaders() {
|
||||||
|
return readers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getChapterCount() {
|
||||||
|
return chapterCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCreatorId() {
|
||||||
|
return creatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(String image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMangaName(String mangaName) {
|
||||||
|
this.mangaName = mangaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaders(List<ReaderDto> readers) {
|
||||||
|
this.readers = readers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChapterCount(Integer chapterCount) {
|
||||||
|
this.chapterCount = chapterCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatorIdString(Long creatorId) {this.creatorId = creatorId;}
|
||||||
|
}
|
@ -19,8 +19,6 @@ public class ReaderMangaDto {
|
|||||||
|
|
||||||
public ReaderMangaDto(Reader reader) {
|
public ReaderMangaDto(Reader reader) {
|
||||||
this.id = reader.getId();
|
this.id = reader.getId();
|
||||||
this.readerName = reader.getReaderName();
|
|
||||||
this.hashedPassword = reader.getHashedPassword();
|
|
||||||
this.mangas = reader.getMangas().stream()
|
this.mangas = reader.getMangas().stream()
|
||||||
.map(y -> new MangaDto(y))
|
.map(y -> new MangaDto(y))
|
||||||
.toList();
|
.toList();
|
||||||
|
@ -16,8 +16,11 @@ public class ReaderDto {
|
|||||||
|
|
||||||
public ReaderDto(Reader reader) {
|
public ReaderDto(Reader reader) {
|
||||||
this.id = reader.getId();
|
this.id = reader.getId();
|
||||||
this.readerName = reader.getReaderName();
|
}
|
||||||
this.hashedPassword = reader.getHashedPassword();
|
|
||||||
|
public ReaderDto(Reader reader, String readerName) {
|
||||||
|
this.id = reader.getId();
|
||||||
|
this.readerName = readerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.LabWork.app.MangaStore.model.Dto;
|
||||||
|
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
|
|
||||||
|
public class UserDto {
|
||||||
|
private Long id;
|
||||||
|
private String login;
|
||||||
|
private String email;
|
||||||
|
private String password;
|
||||||
|
private UserRole role;
|
||||||
|
private Long creatortId;
|
||||||
|
|
||||||
|
private Long readerId;
|
||||||
|
|
||||||
|
public UserDto() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserDto(User user) {
|
||||||
|
this.id = user.getId();
|
||||||
|
this.login = user.getLogin();
|
||||||
|
this.email = user.getEmail();
|
||||||
|
this.password = user.getPassword();
|
||||||
|
this.role = user.getRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogin(String login) {
|
||||||
|
this.login = login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogin() {
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserRole getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getReaderId() {
|
||||||
|
return readerId;
|
||||||
|
}
|
||||||
|
public Long getCreatorId() {
|
||||||
|
return creatortId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.LabWork.app.MangaStore.model.Dto;
|
||||||
|
|
||||||
|
public class UserSignupDto {
|
||||||
|
private String login;
|
||||||
|
private String email;
|
||||||
|
private String password;
|
||||||
|
private String passwordConfirm;
|
||||||
|
|
||||||
|
public String getLogin() {
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogin(String login) {
|
||||||
|
this.login = login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -35,20 +35,20 @@ public class CreatorService {
|
|||||||
public List<Creator> findAllCreators() { return creatorRepository.findAll(); }
|
public List<Creator> findAllCreators() { return creatorRepository.findAll(); }
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Creator addCreator(String creatorName, String password) {
|
public Creator addCreator() {
|
||||||
final Creator creator = new Creator(creatorName, password);
|
final Creator creator = new Creator();
|
||||||
validatorUtil.validate(creator);
|
validatorUtil.validate(creator);
|
||||||
return creatorRepository.save(creator);
|
return creatorRepository.save(creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
/* @Transactional
|
||||||
public Creator updateCreator(Long id, String creatorName, String password) {
|
public Creator updateCreator(Long id, String creatorName, String password) {
|
||||||
final Creator currentCreator = findCreator(id);
|
final Creator currentCreator = findCreator(id);
|
||||||
currentCreator.setCreatorName(creatorName);
|
currentCreator.setCreatorName(creatorName);
|
||||||
currentCreator.setHashedPassword(password);
|
currentCreator.setHashedPassword(password);
|
||||||
validatorUtil.validate(currentCreator);
|
validatorUtil.validate(currentCreator);
|
||||||
return currentCreator;
|
return currentCreator;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Creator deleteCreator(Long id) {
|
public Creator deleteCreator(Long id) {
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.LabWork.app.MangaStore.service.Exception;
|
||||||
|
|
||||||
|
public class UserNotFoundException extends RuntimeException {
|
||||||
|
public UserNotFoundException(Long id) {
|
||||||
|
super(String.format("User with id [%s] is not found", id));
|
||||||
|
}
|
||||||
|
public UserNotFoundException(String login) {
|
||||||
|
super(String.format("User not found '%s'", login));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.LabWork.app.MangaStore.service;
|
|||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Default.Manga;
|
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||||
import com.LabWork.app.MangaStore.model.Default.Reader;
|
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
import com.LabWork.app.MangaStore.service.Repository.MangaRepository;
|
import com.LabWork.app.MangaStore.service.Repository.MangaRepository;
|
||||||
import com.LabWork.app.MangaStore.service.Repository.ReaderRepository;
|
import com.LabWork.app.MangaStore.service.Repository.ReaderRepository;
|
||||||
import com.LabWork.app.MangaStore.service.Exception.MangaNotFoundException;
|
import com.LabWork.app.MangaStore.service.Exception.MangaNotFoundException;
|
||||||
@ -39,20 +40,20 @@ public class ReaderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Reader addReader(String readerName, String password) {
|
public Reader addReader(User user) {
|
||||||
final Reader reader = new Reader(readerName, password);
|
final Reader reader = new Reader(user);
|
||||||
validatorUtil.validate(reader);
|
validatorUtil.validate(reader);
|
||||||
return readerRepository.save(reader);
|
return readerRepository.save(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
/* @Transactional
|
||||||
public Reader updateReader(Long id, String readername, String password) {
|
public Reader updateReader(Long id, String readername, String password) {
|
||||||
final Reader currentReader = findReader(id);
|
final Reader currentReader = findReader(id);
|
||||||
currentReader.setReaderName(readername);
|
currentReader.setReaderName(readername);
|
||||||
currentReader.setHashedPassword(password);
|
currentReader.setHashedPassword(password);
|
||||||
validatorUtil.validate(currentReader);
|
validatorUtil.validate(currentReader);
|
||||||
return currentReader;
|
return currentReader;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Reader deleteReader(Long id) {
|
public Reader deleteReader(Long id) {
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.LabWork.app.MangaStore.service.Repository;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
|
User findOneByLoginIgnoreCase(String login);
|
||||||
|
}
|
@ -0,0 +1,166 @@
|
|||||||
|
package com.LabWork.app.MangaStore.service;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.configuration.jwt.JwtException;
|
||||||
|
import com.LabWork.app.MangaStore.configuration.jwt.JwtProvider;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
|
import com.LabWork.app.MangaStore.model.Dto.UserDto;
|
||||||
|
import com.LabWork.app.MangaStore.service.Exception.UserNotFoundException;
|
||||||
|
import com.LabWork.app.MangaStore.service.Repository.UserRepository;
|
||||||
|
import com.LabWork.app.MangaStore.util.validation.ValidationException;
|
||||||
|
import com.LabWork.app.MangaStore.util.validation.ValidatorUtil;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||||
|
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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService implements UserDetailsService {
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final ValidatorUtil validatorUtil;
|
||||||
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
private final JwtProvider jwtProvider;
|
||||||
|
private final CreatorService creatorService;
|
||||||
|
private final ReaderService readerService;
|
||||||
|
|
||||||
|
public UserService(UserRepository userRepository,
|
||||||
|
ValidatorUtil validatorUtil,
|
||||||
|
PasswordEncoder passwordEncoder,
|
||||||
|
CreatorService creatorService,
|
||||||
|
ReaderService readerService,
|
||||||
|
JwtProvider jwtProvider) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
this.validatorUtil = validatorUtil;
|
||||||
|
this.passwordEncoder = passwordEncoder;
|
||||||
|
this.jwtProvider = jwtProvider;
|
||||||
|
this.creatorService = creatorService;
|
||||||
|
this.readerService = readerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public User findUser(Long id) {
|
||||||
|
final Optional<User> user = userRepository.findById(id);
|
||||||
|
return user.orElseThrow(() -> new UserNotFoundException(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public User findByLogin(String login) {
|
||||||
|
return userRepository.findOneByLoginIgnoreCase(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<User> findAllUsers() {
|
||||||
|
return userRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<User> findAllPages(int page, int size) {
|
||||||
|
return userRepository.findAll(PageRequest.of(page - 1, size, Sort.by("id").ascending()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public User addUser(String login, String email, String password, String passwordConfirm, UserRole role) {
|
||||||
|
if (findByLogin(login) != null) {
|
||||||
|
throw new ValidationException(String.format("User '%s' already exists", login));
|
||||||
|
}
|
||||||
|
if (!Objects.equals(password, passwordConfirm)) {
|
||||||
|
throw new ValidationException("Passwords not equals");
|
||||||
|
}
|
||||||
|
final User user = new User(login, email, passwordEncoder.encode(password), role);
|
||||||
|
//validatorUtil.validate(user);
|
||||||
|
userRepository.save(user);
|
||||||
|
if (role.toString().equals("ADMIN")){
|
||||||
|
final Creator creator = creatorService.addCreator();
|
||||||
|
bindCreator(user.getId(), creator.getId());
|
||||||
|
}
|
||||||
|
if (role.toString().equals("USER")){
|
||||||
|
final Reader reader = readerService.addReader(user);
|
||||||
|
bindReader(user.getId(), reader.getId());
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public User updateUser(UserDto userDto) {
|
||||||
|
final User currentUser = findUser(userDto.getId());
|
||||||
|
final User sameUser = findByLogin(userDto.getLogin());
|
||||||
|
if (sameUser != null && !Objects.equals(sameUser.getId(), currentUser.getId())) {
|
||||||
|
throw new ValidationException(String.format("User '%s' already exists", userDto.getLogin()));
|
||||||
|
}
|
||||||
|
if (!passwordEncoder.matches(userDto.getPassword(), currentUser.getPassword())) {
|
||||||
|
throw new ValidationException("Incorrect password");
|
||||||
|
}
|
||||||
|
currentUser.setLogin(userDto.getLogin());
|
||||||
|
currentUser.setEmail(userDto.getEmail());
|
||||||
|
validatorUtil.validate(currentUser);
|
||||||
|
return userRepository.save(currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public User deleteUser(Long id) {
|
||||||
|
final User currentUser = findUser(id);
|
||||||
|
userRepository.delete(currentUser);
|
||||||
|
return currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteAllUsers() {
|
||||||
|
userRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public User bindCreator(Long id, Long creatorId) {
|
||||||
|
final User user = findUser(id);
|
||||||
|
final Creator creator = creatorService.findCreator(creatorId);
|
||||||
|
user.setCreator(creator);
|
||||||
|
return userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public User bindReader(Long id, Long readerId) {
|
||||||
|
final User user = findUser(id);
|
||||||
|
final Reader reader = readerService.findReader(readerId);
|
||||||
|
user.setReader(reader);
|
||||||
|
return userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String loginAndGetToken(UserDto userDto) {
|
||||||
|
final User user = findByLogin(userDto.getLogin());
|
||||||
|
if (user == null) {
|
||||||
|
throw new UserNotFoundException(userDto.getLogin());
|
||||||
|
}
|
||||||
|
if (!passwordEncoder.matches(userDto.getPassword(), user.getPassword())) {
|
||||||
|
throw new ValidationException("Incorrect password");
|
||||||
|
}
|
||||||
|
return jwtProvider.generateToken(user.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserDetails loadUserByToken(String token) throws UsernameNotFoundException {
|
||||||
|
if (!jwtProvider.isTokenValid(token)) {
|
||||||
|
throw new JwtException("Bad token");
|
||||||
|
}
|
||||||
|
final String userLogin = jwtProvider.getLoginFromToken(token)
|
||||||
|
.orElseThrow(() -> new JwtException("Token is not contain Login"));
|
||||||
|
return loadUserByUsername(userLogin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()));
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,11 @@ package com.LabWork.app.MangaStore.util.validation;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ValidationException extends RuntimeException {
|
public class ValidationException extends RuntimeException {
|
||||||
public ValidationException(Set<String> errors) {
|
public <T> ValidationException(Set<String> errors) {
|
||||||
super(String.join("\n", errors));
|
super(String.join("\n", errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> ValidationException(String error) {
|
||||||
|
super(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package com.LabWork.app;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.servlet.config.annotation.*;
|
|
||||||
@Configuration
|
|
||||||
public class WebConfiguration implements WebMvcConfigurer {
|
|
||||||
public static final String REST_API = "/api";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**").allowedMethods("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configurePathMatch(PathMatchConfigurer configurer) {
|
|
||||||
configurer.setUseTrailingSlashMatch(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
|
||||||
ViewControllerRegistration registration = registry.addViewController("/notFound");
|
|
||||||
registration.setViewName("forward:/index.html");
|
|
||||||
registration.setStatusCode(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,3 +9,5 @@ spring.jpa.hibernate.ddl-auto=update
|
|||||||
spring.h2.console.enabled=true
|
spring.h2.console.enabled=true
|
||||||
spring.h2.console.settings.trace=false
|
spring.h2.console.settings.trace=false
|
||||||
spring.h2.console.settings.web-allow-others=false
|
spring.h2.console.settings.web-allow-others=false
|
||||||
|
jwt.dev-token=my-secret-jwt
|
||||||
|
jwt.dev=true
|
@ -1,111 +0,0 @@
|
|||||||
html,
|
|
||||||
body {
|
|
||||||
background-color: #000000;
|
|
||||||
color: #ffffff;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
font-family: sans-serif;
|
|
||||||
line-height: 1.15;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
header {
|
|
||||||
background-color: #3c3c3c;
|
|
||||||
color: #ffffff;
|
|
||||||
}
|
|
||||||
header a {
|
|
||||||
color: #ffffff;
|
|
||||||
text-decoration: none;
|
|
||||||
margin: 0 0.5em;
|
|
||||||
}
|
|
||||||
header a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
#logo {
|
|
||||||
margin-left: 0.5em;
|
|
||||||
}
|
|
||||||
article a {
|
|
||||||
color: #ffffff;
|
|
||||||
text-decoration: none;
|
|
||||||
margin: 0.5em 0.5em;
|
|
||||||
}
|
|
||||||
header a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.25em;
|
|
||||||
}
|
|
||||||
h3 {
|
|
||||||
font-size: 1.1em;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
background-color: #9c9c9c;
|
|
||||||
color: #ffffff;
|
|
||||||
height: 32px;
|
|
||||||
padding: 0.5em;
|
|
||||||
}
|
|
||||||
.manga_pages{
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.catalog_wrapper{
|
|
||||||
display: flex;
|
|
||||||
width: 73%;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.catalog_article{
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
.poster{
|
|
||||||
width:140px;
|
|
||||||
}
|
|
||||||
th {
|
|
||||||
border: 0px solid rgb(255, 255, 255);
|
|
||||||
}
|
|
||||||
.added_manga{
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
@media (min-width: 992px) {
|
|
||||||
.manga_pages img{
|
|
||||||
max-width: 900px;
|
|
||||||
width: auto;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.flex_grow {
|
|
||||||
flex-grow: 1;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
@media (min-width: 1024px){
|
|
||||||
.article_1 {
|
|
||||||
max-width: -webkit-calc(1600px + (100vw/64*7)*2);
|
|
||||||
max-width: -moz-calc(1600px + (100vw/64*7)*2);
|
|
||||||
max-width: calc(1600px + (100vw/64*7)*2);
|
|
||||||
padding-left: -webkit-calc(100vw/64*7);
|
|
||||||
padding-left: -moz-calc(100vw/64*7);
|
|
||||||
padding-left: calc(100vw/64*7);
|
|
||||||
padding-right: -webkit-calc(100vw/64*7);
|
|
||||||
padding-right: -moz-calc(100vw/64*7);
|
|
||||||
padding-right: calc(100vw/64*7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.registration_div {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slideshow{
|
|
||||||
height: 250px;
|
|
||||||
width: auto;/*maintain aspect ratio*/
|
|
||||||
max-width:180px;
|
|
||||||
border-radius: 7%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table > :not(:first-child) {
|
|
||||||
border-top: 0;
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
|
||||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
|
||||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="1280.000000pt" height="1280.000000pt" viewBox="0 0 1280.000000 1280.000000"
|
|
||||||
preserveAspectRatio="xMidYMid meet">
|
|
||||||
<metadata>
|
|
||||||
Created by potrace 1.15, written by Peter Selinger 2001-2017
|
|
||||||
</metadata>
|
|
||||||
<g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
|
|
||||||
fill="#000000" stroke="none">
|
|
||||||
<path d="M6090 12534 c-883 -44 -1693 -246 -2418 -604 -635 -313 -1146 -683
|
|
||||||
-1683 -1220 -1069 -1067 -1655 -2308 -1794 -3795 -22 -238 -30 -735 -16 -980
|
|
||||||
78 -1331 506 -2470 1306 -3470 280 -349 669 -743 1015 -1026 886 -725 1894
|
|
||||||
-1159 3035 -1308 299 -39 429 -46 870 -46 460 1 593 9 955 61 1137 162 2166
|
|
||||||
630 3055 1390 193 164 595 566 759 759 605 708 1027 1507 1251 2368 309 1191
|
|
||||||
269 2518 -110 3662 -317 956 -904 1845 -1705 2581 -1050 964 -2228 1484 -3640
|
|
||||||
1609 -167 15 -721 27 -880 19z m-141 -848 c-2 -2 -53 -25 -114 -50 -560 -238
|
|
||||||
-1123 -701 -1404 -1153 -235 -379 -358 -823 -380 -1369 -32 -790 142 -1362
|
|
||||||
564 -1852 156 -181 413 -398 660 -558 228 -147 595 -288 1140 -439 704 -195
|
|
||||||
876 -254 1145 -391 69 -35 159 -85 200 -112 41 -27 116 -72 165 -102 395 -233
|
|
||||||
696 -560 910 -987 122 -245 201 -498 247 -793 18 -114 18 -599 0 -740 -23
|
|
||||||
-182 -62 -360 -113 -516 -190 -578 -549 -979 -1124 -1255 -378 -182 -772 -281
|
|
||||||
-1360 -341 -73 -8 -274 -13 -515 -13 -415 0 -507 7 -785 56 -678 122 -1390
|
|
||||||
456 -1991 934 -1176 936 -1894 2146 -2088 3518 -44 309 -51 415 -51 792 0 377
|
|
||||||
7 487 51 793 137 964 544 1858 1207 2652 909 1089 2055 1733 3377 1899 91 11
|
|
||||||
181 22 200 24 19 2 41 5 49 5 8 1 12 0 10 -2z m576 -1850 c126 -41 218 -98
|
|
||||||
316 -195 74 -73 93 -100 132 -181 25 -52 51 -120 58 -150 20 -82 17 -300 -5
|
|
||||||
-380 -55 -201 -203 -378 -391 -470 -100 -49 -182 -69 -310 -76 -220 -12 -403
|
|
||||||
54 -568 206 -91 84 -156 184 -193 296 -27 83 -29 100 -29 239 1 143 2 154 32
|
|
||||||
232 87 228 281 414 508 486 77 24 90 26 235 23 114 -3 148 -8 215 -30z"/>
|
|
||||||
<path d="M6130 4301 c-162 -35 -293 -106 -419 -225 -116 -112 -199 -251 -242
|
|
||||||
-411 -32 -115 -32 -345 0 -460 85 -311 327 -549 639 -627 121 -31 313 -30 427
|
|
||||||
1 255 69 477 256 595 503 145 302 87 700 -137 939 -131 138 -252 215 -420 265
|
|
||||||
-120 36 -317 43 -443 15z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 2.2 KiB |
@ -1,19 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<article class="p-2 catalog_article">
|
|
||||||
<div class = "catalog_wrapper">
|
|
||||||
<h1>Каталог</h1>
|
|
||||||
<div class="p-2 d-flex flex-wrap">
|
|
||||||
<a th:each="manga: ${mangaList}" th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="${manga.image}" class="slideshow"/></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,31 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/creator/{id}(id=${id})}" th:object="${CreatorMangaDto}" method="post">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="creatorName" class="form-label">creatorName</label>
|
|
||||||
<input id="creatorName" type='text' class="form-control" th:field="${CreatorMangaDto.creatorName}" required="true"/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="hashedPassword" class="form-label">hashedPassword</label>
|
|
||||||
<input id="hashedPassword" type='text' class="form-control" th:field="${CreatorMangaDto.hashedPassword}" 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="@{/creator}">
|
|
||||||
Назад
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,60 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" id="root-div" layout:fragment="content">
|
|
||||||
<div class="content">
|
|
||||||
<h1>Creator</h1>
|
|
||||||
<a class="btn btn-success"
|
|
||||||
th:href="@{/creator/edit}">
|
|
||||||
<i class="fa-solid fa-plus"></i> Добавить
|
|
||||||
</a>
|
|
||||||
<div class="row table-responsive text-white">
|
|
||||||
<table class="table mt-3 text-white">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">#</th>
|
|
||||||
<th scope="col">CreatorName</th>
|
|
||||||
<th scope="col">Password</th>
|
|
||||||
<th scope="col">Mangas</th>
|
|
||||||
<th scope="col"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr th:each="creator: ${creators}">
|
|
||||||
<td th:text="${creator.id}"/>
|
|
||||||
<td th:text="${creator.creatorName}"/>
|
|
||||||
<td th:text="${creator.hashedPassword}"/>
|
|
||||||
<td>
|
|
||||||
<select className="form-select" aria-label="Default select example">
|
|
||||||
<option th:each="manga, iterator: ${creator.mangas}" th:text="${manga.mangaName}"/>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td style="width: 10%">
|
|
||||||
<div class="btn-group" role="group" aria-label="Basic example">
|
|
||||||
<a class="btn btn-warning button-fixed button-sm"
|
|
||||||
th:href="@{/creator/edit/{id}(id=${creator.id})}">
|
|
||||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
|
||||||
</a>
|
|
||||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
|
||||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${creator.id}').click()|">
|
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<form th:action="@{/creator/delete/{id}(id=${creator.id})}" method="post">
|
|
||||||
<button th:id="'remove-' + ${creator.id}" type="submit" style="display: none">
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,36 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/creatorAction/{controller}{id}(id=${id}, controller=${controller})}" th:object="${mangaDto}" enctype="multipart/form-data" method="post">
|
|
||||||
<div class="mb-3" th:if="${controller == 'creator/'}">
|
|
||||||
<label for="mangaName" class="form-label">mangaName</label>
|
|
||||||
<input id="mangaName" type='text' class="form-control" th:field="${mangaDto.mangaName}" required="true"/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="chapterCount" class="form-label">chapterCount</label>
|
|
||||||
<input id="chapterCount" type='number' class="form-control" th:field="${mangaDto.chapterCount}" required="true"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="multipartFile" class="form-label">image</label>
|
|
||||||
<input type="file" id="multipartFile" th:name="multipartFile" accept="image/png, image/jpeg" class="form-control" required="true"/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<button type="submit" class="btn btn-primary button-fixed">
|
|
||||||
<span th:if="${controller == 'creator/'}">Добавить</span>
|
|
||||||
<span th:if="${controller != 'creator/'}">Обновить</span>
|
|
||||||
</button>
|
|
||||||
<a class="btn btn-secondary button-fixed" th:href="@{/creator}">
|
|
||||||
Назад
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,77 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" id="root-div" layout:fragment="content">
|
|
||||||
<div class="content">
|
|
||||||
<h1>Creator</h1>
|
|
||||||
<form id="form mb-3">
|
|
||||||
<div class="d-flex mt-3">
|
|
||||||
<div class="d-grid col-sm-2">
|
|
||||||
<a class="btn btn-success"
|
|
||||||
th:href="@{/creatorAction/create/{id}(id=${creatorId})}">
|
|
||||||
<i class="fa-solid fa-plus"></i> Добавить
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/creatorAction}" method="get">
|
|
||||||
<div class="col-sm-2 mb-3">
|
|
||||||
<label for="creatorId" class="form-label">Reader</label>
|
|
||||||
<select id="creatorId" th:name="creatorId" class="form-select">
|
|
||||||
<option value="" disabled selected>Select your option</option>
|
|
||||||
<option th:each="value: ${creators}" th:selected="${creatorId} == ${value}" th:text="${value.creatorName}" th:value="${value.Id}">
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div class="row table-responsive text-white">
|
|
||||||
<div th:each="manga, iterator: ${currentCreator?.mangas}" class="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
|
||||||
<div class="me-3">
|
|
||||||
<a th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="${manga.image}" th:alt="${manga.mangaName}" class="slideshow"/></a>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
|
||||||
<h4>Название манги: <a class="text-white fs-5 unic_class fw-bold pt-3 mb-3" th:href="@{/mangapage/{id}(id=${manga.id})}" th:text="${manga.mangaName}"></a></h4>
|
|
||||||
<h4>
|
|
||||||
Количество глав:
|
|
||||||
<span th:text="${manga.chapterCount}"/>
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<a class="btn btn-primary" th:href="@{/creatorAction/edit/{id}(id=${manga.id})}">
|
|
||||||
<i class="fas fa-edit"></i>
|
|
||||||
</a>
|
|
||||||
</button>
|
|
||||||
<button type="button" class="delete bg-danger p-2 px-2 mx-2 border border-0 rounded text-white fw-bold"
|
|
||||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${manga.id}').click()|">
|
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
|
||||||
</button>
|
|
||||||
<form th:action="@{/creatorAction/delete/{id}(id=${manga.id})}" method="post">
|
|
||||||
<button th:id="'remove-' + ${manga.id}" type="submit" style="display: none">
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<th:block layout:fragment="scripts">
|
|
||||||
<script>
|
|
||||||
$(document).ready(function() {
|
|
||||||
$('#creatorId').on('change', function() {
|
|
||||||
this.form.submit();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</th:block>
|
|
||||||
</html>
|
|
@ -1,48 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru"
|
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<title>ReManga</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="icon" href="/favicon.svg">
|
|
||||||
<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="/css/style.css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark">
|
|
||||||
<div class="container-fluid">
|
|
||||||
<a class="navbar-brand" href="/">
|
|
||||||
<i class="fa-solid fa-yin-yang"></i>
|
|
||||||
ReManga
|
|
||||||
</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">
|
|
||||||
<a class="nav-link" href="/">Index</a>
|
|
||||||
<a class="nav-link" th:href="@{/creator}">Creator</a>
|
|
||||||
<a class="nav-link" href="/reader">Reader</a>
|
|
||||||
<a class="nav-link" href="/creatorAction">CreatorAction</a>
|
|
||||||
<a class="nav-link" href="/readerAction">ReaderAction</a>
|
|
||||||
<a class="nav-link" href="/manga">Catalog</a>
|
|
||||||
<a class="nav-link" href="/swagger-ui/index.html" target="_blank">Документация REST API</a>
|
|
||||||
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<div class="container-fluid">
|
|
||||||
<div class="container container-padding" layout:fragment="content">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<th:block layout:fragment="scripts">
|
|
||||||
</th:block>
|
|
||||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div><span th:text="${error}"></span></div>
|
|
||||||
<a href="/">На главную</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div>It's works!</div>
|
|
||||||
<a href="123">ERROR</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,57 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div class="container d-flex" >
|
|
||||||
<div class="d-flex flex-column">
|
|
||||||
<img class="img_style01" style={{borderRadius:"3%"}} th:src="${manga.image}" th:alt="${manga.mangaName}"/>
|
|
||||||
</div>
|
|
||||||
<div class="container table text-white fs-4 ms-4">
|
|
||||||
<div class="row text-white fw-bold fs-3">О манге</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-3">Год производства</div>
|
|
||||||
<div class="col-xs-6 col-sm-3">1000</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-3">Страна</div>
|
|
||||||
<div class="col-xs-6 col-sm-3">Россия</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-3">Жанр</div>
|
|
||||||
<div class="col-xs-6 col-sm-3">Драма</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-3">Количество глав</div>
|
|
||||||
<div class="col-xs-6 col-sm-3" th:text="${manga.chapterCount}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-3">Возраст</div>
|
|
||||||
<div class="col-xs-6 col-sm-3">16+</div>
|
|
||||||
</div>
|
|
||||||
<div class="row text-white fw-bold fs-3">Описание</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-6 col-sm-12">
|
|
||||||
<p>Ким Кон Чжа спокойно живет в своей халупе, завидуя всем популярным охотникам. Однажды его желание быть лучше всех сбывается и он получает легендарный навык “Копирование способностей”... ценой своей жизни.</p>
|
|
||||||
<p>Прежде чем он успевает понять это, его убивает охотник №1, Летний дух! Но это активирует его навык, и теперь он скопировал новый, “Путешествие во времени после смерти”.</p>
|
|
||||||
<p>Как Ким Кон Чжа же будет использовать эти навыки, чтобы победить конкурентов и подняться на вершину?</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row table-responsive text-white">
|
|
||||||
<div th:each="reader: ${readers}" class="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
|
||||||
<div>
|
|
||||||
<div class="pt-3 description mb-3 fs-6 fw-bold">
|
|
||||||
Имя пользователя:
|
|
||||||
<a th:href="@{/readerAction/{id}(id=${reader.id})}" th:text="${reader.readerName}"></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,31 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/reader/{id}(id=${id})}" th:object="${ReaderMangaDto}" method="post">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="readerName" class="form-label">readerName</label>
|
|
||||||
<input id="readerName" type='text' value class="form-control" th:field="${ReaderMangaDto.readerName}" required="true"/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="hashedPassword" class="form-label">hashedPassword</label>
|
|
||||||
<input id="hashedPassword" type='text' value class="form-control" th:field="${ReaderMangaDto.hashedPassword}" 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="@{/reader}">
|
|
||||||
Назад
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,60 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" id="root-div" layout:fragment="content">
|
|
||||||
<div class="content">
|
|
||||||
<h1>Reader</h1>
|
|
||||||
<a class="btn btn-success"
|
|
||||||
th:href="@{/reader/edit}">
|
|
||||||
<i class="fa-solid fa-plus"></i> Добавить
|
|
||||||
</a>
|
|
||||||
<div class="row table-responsive text-white">
|
|
||||||
<table class="table mt-3 text-white">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">#</th>
|
|
||||||
<th scope="col">ReaderName</th>
|
|
||||||
<th scope="col">Password</th>
|
|
||||||
<th scope="col">Mangas</th>
|
|
||||||
<th scope="col"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr th:each="reader, iterator: ${readers}">
|
|
||||||
<td th:text="${reader.id}"/>
|
|
||||||
<td th:text="${reader.readerName}"/>
|
|
||||||
<td th:text="${reader.hashedPassword}"/>
|
|
||||||
<td>
|
|
||||||
<select className="form-select" aria-label="Default select example">
|
|
||||||
<option th:each="manga, iterator: ${reader.mangas}" th:text="${manga.mangaName}"/>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td style="width: 10%">
|
|
||||||
<div class="btn-group" role="group" aria-label="Basic example">
|
|
||||||
<a class="btn btn-warning button-fixed button-sm"
|
|
||||||
th:href="@{/reader/edit/{id}(id=${reader.id})}">
|
|
||||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
|
||||||
</a>
|
|
||||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
|
||||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${reader.id}').click()|">
|
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<form th:action="@{/reader/delete/{id}(id=${reader.id})}" method="post">
|
|
||||||
<button th:id="'remove-' + ${reader.id}" type="submit" style="display: none">
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,82 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" id="root-div" layout:fragment="content">
|
|
||||||
<div class="content">
|
|
||||||
<h1>Reader</h1>
|
|
||||||
<div class="d-flex mt-3">
|
|
||||||
<div class="d-grid col-sm-2">
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/readerAction/manga/{id}(id=${readerId})}" method="post">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="mangaId" class="form-label">Манга</label>
|
|
||||||
<select th:name="mangaId" id="mangaId" class="form-select">
|
|
||||||
<option th:each="manga: ${mangaList}" th:value="${manga.id}" th:text="${manga.mangaName}"/>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<button type="submit" class="btn btn-primary button-fixed">
|
|
||||||
<i class="fa-solid fa-plus">Добавить</i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
|
||||||
<form action="#" th:action="@{/readerAction}" method="get">
|
|
||||||
<div class="col-sm-2 mb-3">
|
|
||||||
<label for="readerId" class="form-label">Reader</label>
|
|
||||||
<select id="readerId" th:name="readerId" class="form-select">
|
|
||||||
<option value="" disabled selected>Select your option</option>
|
|
||||||
<option th:each="value: ${readers}" th:selected="${readerId} == ${value}" th:text="${value.readerName}" th:value="${value.Id}">
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div class="row table-responsive text-white">
|
|
||||||
<div th:each="manga: ${reader?.mangas}" class="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
|
||||||
<div class="me-3">
|
|
||||||
<a th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="${manga.image}" th:alt="${manga.mangaName}" class="slideshow"/></a>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
|
||||||
<h4>Название манги: <a class="text-white fs-5 unic_class fw-bold pt-3 mb-3" th:href="@{/mangapage/{id}(id=${manga.id})}" th:text="${manga.mangaName}"></a></h4>
|
|
||||||
<h4>
|
|
||||||
Количество глав:
|
|
||||||
<span th:text="${manga.chapterCount}"/>
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
</button>
|
|
||||||
<button type="button" class="delete bg-danger p-2 px-2 mx-2 border border-0 rounded text-white fw-bold"
|
|
||||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${manga.id}').click()|">
|
|
||||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
|
||||||
</button>
|
|
||||||
<form th:action="@{'/readerAction/' + ${readerId} + '/removeManga/' + ${manga.id}}" method="post">
|
|
||||||
<button th:id="'remove-' + ${manga.id}" type="submit" style="display: none">
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<th:block layout:fragment="scripts">
|
|
||||||
<script>
|
|
||||||
$(document).ready(function() {
|
|
||||||
$('#readerId').on('change', function() {
|
|
||||||
this.form.submit();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</th:block>
|
|
||||||
</html>
|
|
77
src/test/java/com/LabWork/app/JpaUserTests.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package com.LabWork.app;
|
||||||
|
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.User;
|
||||||
|
import com.LabWork.app.MangaStore.model.Default.UserRole;
|
||||||
|
import com.LabWork.app.MangaStore.service.Exception.UserNotFoundException;
|
||||||
|
import com.LabWork.app.MangaStore.service.UserService;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JpaUserTests {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JpaUserTests.class);
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserCreate() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final User user = userService.addUser("User 1", "email@gmail.com",
|
||||||
|
"123456", "123456", UserRole.USER);
|
||||||
|
log.info("testUserCreate: " + user.toString());
|
||||||
|
Assertions.assertNotNull(user.getId());
|
||||||
|
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserRead() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final User user = userService.addUser("User 2", "email@gmail.com",
|
||||||
|
"123456", "123456", UserRole.USER);
|
||||||
|
log.info("testUserRead[0]: " + user.toString());
|
||||||
|
final User findUser = userService.findUser(user.getId());
|
||||||
|
log.info("testUserRead[1]: " + findUser.toString());
|
||||||
|
Assertions.assertEquals(user, findUser);
|
||||||
|
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserReadNotFound() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
Assertions.assertThrows(UserNotFoundException.class, () -> userService.findUser(-1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserReadAll() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
userService.addUser("User 3", "email@gmail.com", "123456",
|
||||||
|
"123456", UserRole.USER);
|
||||||
|
userService.addUser("User 4", "email@gmail.com", "123456",
|
||||||
|
"123456", UserRole.USER);
|
||||||
|
final List<User> users = userService.findAllUsers();
|
||||||
|
log.info("testUserReadAll: " + users.toString());
|
||||||
|
Assertions.assertEquals(users.size(), 2);
|
||||||
|
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserReadAllEmpty() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final List<User> users = userService.findAllUsers();
|
||||||
|
log.info("testUserReadAllEmpty: " + users.toString());
|
||||||
|
Assertions.assertEquals(users.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
|
/*
|
||||||
package com.LabWork.app;
|
package com.LabWork.app;
|
||||||
|
|
||||||
import com.LabWork.app.MangaStore.model.Default.Creator;
|
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||||
@ -103,6 +104,7 @@ public class ReMangaTest {
|
|||||||
creatorService.deleteAllCreators();
|
creatorService.deleteAllCreators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
/* @Test
|
/* @Test
|
||||||
void testCreatorAddManga() {
|
void testCreatorAddManga() {
|
||||||
readerService.deleteAllReaders();
|
readerService.deleteAllReaders();
|
||||||
@ -119,8 +121,10 @@ public class ReMangaTest {
|
|||||||
log.info(m1.getCreator().toString());
|
log.info(m1.getCreator().toString());
|
||||||
log.info(c1.toString());
|
log.info(c1.toString());
|
||||||
Assertions.assertEquals(c1.getCreatorName(), m1.getCreator().getCreatorName());
|
Assertions.assertEquals(c1.getCreatorName(), m1.getCreator().getCreatorName());
|
||||||
}*/
|
}*//*
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
/* //бесполезня штука
|
/* //бесполезня штука
|
||||||
@Test
|
@Test
|
||||||
void testCreatorDeleteManga() {
|
void testCreatorDeleteManga() {
|
||||||
@ -147,8 +151,11 @@ public class ReMangaTest {
|
|||||||
|
|
||||||
Assertions.assertEquals(1, c1.getMangas().size());
|
Assertions.assertEquals(1, c1.getMangas().size());
|
||||||
|
|
||||||
}*/
|
}*//*
|
||||||
/*тестстим работоспособность гита*/
|
|
||||||
|
*/
|
||||||
|
/*тестстим работоспособность гита*//*
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCreatorUpdated() {
|
void testCreatorUpdated() {
|
||||||
readerService.deleteAllReaders();
|
readerService.deleteAllReaders();
|
||||||
@ -429,3 +436,4 @@ public class ReMangaTest {
|
|||||||
creatorService.deleteAllCreators();
|
creatorService.deleteAllCreators();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|