Compare commits
2 Commits
LabWork06R
...
LabWork04
Author | SHA1 | Date | |
---|---|---|---|
b653d3808a | |||
6c6e8f96aa |
@ -16,18 +16,11 @@ jar {
|
||||
}
|
||||
dependencies {
|
||||
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-data-jpa'
|
||||
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:jquery:3.6.0'
|
||||
implementation 'org.webjars:font-awesome:6.1.0'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
//implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
|
||||
|
BIN
data.mv.db
2065
data.trace.db
BIN
front/img/4_popular.jpg
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
front/img/5_popular.jpg
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
front/img/6_popular.jpg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
front/img/popular_1.jpg
Normal file
After Width: | Height: | Size: 58 KiB |
BIN
front/img/popular_2.jpg
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
front/img/popular_3.jpg
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
front/img/существование.jpg
Normal file
After Width: | Height: | Size: 48 KiB |
@ -1,49 +1,45 @@
|
||||
import { Routes, BrowserRouter, Route } from 'react-router-dom';
|
||||
import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom';
|
||||
import Creator from './MainS/Creator';
|
||||
import Reader from './MainS/Reader';
|
||||
import Header from './components/Header';
|
||||
import Manga from './MainS/Manga';
|
||||
import CreatorAction from './Main/CreatorAction';
|
||||
import ReaderAction from './Main/ReaderAction';
|
||||
import UsersPage from './Main/UsersPage';
|
||||
import MangaPage from './Main/MangaPage';
|
||||
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) {
|
||||
return useRoutes(props.rootRoute);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
|
||||
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" }
|
||||
const routes = [
|
||||
{ index: true, element: <Creator /> },
|
||||
{ path: 'creator', element: <Creator />, label: 'Creator' },
|
||||
{ path: 'reader', element: <Reader />, label: 'Reader' },
|
||||
{ path: 'manga', element: <Manga />, label: 'Manga' },
|
||||
{ path: 'creatorAction', element: <CreatorAction />, label: 'CreatorAction' },
|
||||
{ path: 'readerAction', element: <ReaderAction />, label: 'ReaderAction' },
|
||||
{ path: 'catalog', element: <Catalog />, label: 'Catalog' },
|
||||
{ path: 'mangapage', element: <MangaPage /> },
|
||||
];
|
||||
return (
|
||||
const links = routes.filter(route => route.hasOwnProperty('label'));
|
||||
const rootRoute = [
|
||||
{ path: '/', element: render(links), children: routes }
|
||||
];
|
||||
|
||||
function render(links) {
|
||||
return (
|
||||
<>
|
||||
<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>
|
||||
<Header links={links} />
|
||||
<Outlet />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Router rootRoute={ rootRoute } />
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
export default class UserSignupDto {
|
||||
constructor(args) {
|
||||
this.login = args.login;
|
||||
this.email = args.email;
|
||||
this.password = args.password;
|
||||
this.passwordConfirm = args.passwordConfirm;
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import '../components/Banner/banner.css'
|
||||
import Banner from '../components/Banner/Banner.jsx'
|
||||
import { Link, NavLink } from 'react-router-dom';
|
||||
import MangaDto from "../Dto/Manga-Dto";
|
||||
|
||||
export default function Catalog() {
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [mangs, setMangs] = useState([]);
|
||||
|
||||
@ -14,18 +17,8 @@ export default function Catalog() {
|
||||
console.log(mangs);
|
||||
},[]);
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
const getMangs = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + "/manga", requestParams);
|
||||
const response = await fetch(host + "/manga");
|
||||
const _data = await response.json()
|
||||
console.log(_data);
|
||||
return _data;
|
||||
@ -33,8 +26,21 @@ export default function Catalog() {
|
||||
|
||||
return (
|
||||
<article className="p-2 catalog_article">
|
||||
<Banner />
|
||||
<div className = "catalog_wrapper">
|
||||
<h1>Каталог</h1>
|
||||
{/* <h2>
|
||||
<select>
|
||||
<option value="1">По рейтингу</option>
|
||||
<option value="2">По лайкам</option>
|
||||
<option value="3">По просмотрам</option>
|
||||
<option value="4">По кол-ву глав</option>
|
||||
<option value="5">По новизне</option>
|
||||
<option value="6">По последним обновлениям</option>
|
||||
<option value="7">Рандом</option>
|
||||
</select>
|
||||
<button type="button" className="btn btn-dark">↑↓</button>
|
||||
</h2> */}
|
||||
<div className="p-2 d-flex flex-wrap">
|
||||
{mangs.map((manga, index) => (
|
||||
<NavLink key={manga.id} to={`/mangapage?id=${manga.id}`}><img src={manga.image} alt={manga.mangaName} className="slideshow"/></NavLink>
|
||||
|
@ -8,10 +8,12 @@ import EditMangaModal from "../components/Modal/EditMangaModal";
|
||||
|
||||
export default function CreatorAction() {
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [creatorData, setCreatorData] = useState([]);
|
||||
|
||||
const [creatorId, setCreatorId] = useState(0);
|
||||
|
||||
const [creator, setCreator] = useState([]);
|
||||
|
||||
const [mangaId, setMangaId] = useState(0);
|
||||
@ -22,62 +24,39 @@ export default function CreatorAction() {
|
||||
|
||||
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
|
||||
|
||||
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
/* useEffect(() => {
|
||||
useEffect(() => {
|
||||
getCreatorData()
|
||||
.then(_data =>setCreatorData(_data));
|
||||
},[]);*/
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getCreator().then(_data => {
|
||||
setCreator(_data)
|
||||
console.log(_data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const getCreator = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
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 response = await fetch(host + "/creator");
|
||||
const _data = await response.json()
|
||||
return _data;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getCreator(creatorId)
|
||||
.then(_data =>setCreator(_data));
|
||||
},[creatorId]);
|
||||
|
||||
|
||||
|
||||
const getCreator = async function (id) {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/creator/` + id, requestParams);
|
||||
const _data = await response.json()
|
||||
return _data;
|
||||
}
|
||||
|
||||
const updateButton = (e) =>{
|
||||
e.preventDefault();
|
||||
update().then((result) => {
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||
getCreator(creator.id)
|
||||
getCreator(creatorId)
|
||||
.then(_data =>setCreator(_data));
|
||||
});
|
||||
}
|
||||
@ -89,14 +68,13 @@ export default function CreatorAction() {
|
||||
}
|
||||
mangaModel.id = mangaId;
|
||||
mangaModel.chapterCount = chapterCount;
|
||||
mangaModel.creatorId = creator.id;
|
||||
mangaModel.creatorId = creatorId;
|
||||
mangaModel.image = imageURL;
|
||||
mangaModel.mangaName = mangaName;
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
},
|
||||
body: JSON.stringify(mangaModel),
|
||||
};
|
||||
@ -110,7 +88,7 @@ export default function CreatorAction() {
|
||||
|
||||
const removeButton = (id) =>{
|
||||
remove(id).then(() => {
|
||||
getCreator(creator.id)
|
||||
getCreator(creatorId)
|
||||
.then(_data =>setCreator(_data));
|
||||
});
|
||||
}
|
||||
@ -126,7 +104,6 @@ export default function CreatorAction() {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/` + id, requestParams);
|
||||
@ -136,22 +113,20 @@ export default function CreatorAction() {
|
||||
e.preventDefault()
|
||||
create().then((result) => {
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||
getCreator(creator.id)
|
||||
getCreator(creatorId)
|
||||
.then(_data =>setCreator(_data));
|
||||
});
|
||||
}
|
||||
|
||||
const create = async function (){
|
||||
mangaModel.chapterCount = chapterCount;
|
||||
mangaModel.creatorId = creator.id;
|
||||
mangaModel.creatorId = creatorId;
|
||||
mangaModel.image = imageURL;
|
||||
mangaModel.mangaName = mangaName;
|
||||
console.log(mangaModel);
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
},
|
||||
body: JSON.stringify(mangaModel),
|
||||
};
|
||||
@ -181,6 +156,16 @@ export default function CreatorAction() {
|
||||
<h1>Creator</h1>
|
||||
<form id="form">
|
||||
<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">
|
||||
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
||||
</div>
|
||||
|
@ -1,90 +0,0 @@
|
||||
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,11 +8,7 @@ export default function MangaPage() {
|
||||
|
||||
const [readerData, setReaderData] = useState([]);
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
useEffect(() => {
|
||||
const quryString = window.location.search;
|
||||
@ -33,7 +29,6 @@ export default function MangaPage() {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/` + id + `/readers`, requestParams);
|
||||
@ -57,7 +52,6 @@ export default function MangaPage() {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/` + id, requestParams);
|
||||
@ -78,6 +72,7 @@ export default function MangaPage() {
|
||||
<div className="container d-flex" >
|
||||
<div className="d-flex flex-column">
|
||||
<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 className="container table text-white fs-4 ms-4">
|
||||
<div className="row text-white fw-bold fs-3">О манге</div>
|
||||
@ -113,7 +108,7 @@ export default function MangaPage() {
|
||||
readers={mangaModel.readers}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
@ -6,12 +6,14 @@ import AddMangaReaderModal from "../components/Modal/AddMangaReaderModal";
|
||||
|
||||
export default function ReaderAction() {
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [mangaData, setMangaData] = useState([]);
|
||||
|
||||
const [readerData, setReaderData] = useState([]);
|
||||
|
||||
const [readerId, setReaderId] = useState(0);
|
||||
|
||||
const [reader, setReader] = useState([]);
|
||||
|
||||
const [mangaId, setMangaId] = useState(0);
|
||||
@ -20,16 +22,11 @@ export default function ReaderAction() {
|
||||
|
||||
const [mangaName, setMangaName] = useState("");
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const quryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(quryString);
|
||||
const id = urlParams.get('id');
|
||||
console.log(id);
|
||||
if (id !== null) setReaderId(id);
|
||||
setReaderId(id);
|
||||
getReaderData()
|
||||
.then(_data =>setReaderData(_data));
|
||||
getMangaData()
|
||||
@ -39,61 +36,48 @@ export default function ReaderAction() {
|
||||
},[]);
|
||||
|
||||
const getReaderData = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + "/reader", requestParams);
|
||||
const response = await fetch(host + "/reader");
|
||||
const _data = await response.json()
|
||||
console.log(_data);
|
||||
return _data;
|
||||
}
|
||||
|
||||
const getMangaData = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + "/manga", requestParams);
|
||||
const response = await fetch(host + "/manga");
|
||||
const _data = await response.json()
|
||||
console.log(_data);
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getReader().then(_data => {
|
||||
setReader(_data);
|
||||
console.log(_data);
|
||||
});
|
||||
}, []);
|
||||
console.log(readerId);
|
||||
getReader(readerId)
|
||||
.then(_data =>setReader(_data));
|
||||
console.log(readerId);
|
||||
},[readerId]);
|
||||
|
||||
const getReader = async function () {
|
||||
const getReader = async function (id) {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
let login = localStorage.getItem("user");
|
||||
console.log(host + `/reader/` + login);
|
||||
const response = await fetch(host + `/reader/` + login, requestParams);
|
||||
const response = await fetch(host + `/reader/` + id, requestParams);
|
||||
const _data = await response.json()
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
const updateButton = (e) =>{
|
||||
e.preventDefault();
|
||||
update().then((result) => {
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||
getReader()
|
||||
getReader(readerId)
|
||||
.then(_data =>setReader(_data));
|
||||
});
|
||||
console.log(readerId);
|
||||
|
||||
console.log(readerId);
|
||||
console.log(reader);
|
||||
}
|
||||
|
||||
@ -106,7 +90,6 @@ export default function ReaderAction() {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/${mangaId}?chapterCount=${chapterCount}`, requestParams);
|
||||
@ -119,7 +102,7 @@ export default function ReaderAction() {
|
||||
|
||||
const removeButton = (id) =>{
|
||||
remove(id).then((result) => {
|
||||
getReader()
|
||||
getReader(readerId)
|
||||
.then(_data =>setReader(_data));
|
||||
});
|
||||
}
|
||||
@ -134,11 +117,10 @@ export default function ReaderAction() {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
console.log(host + `/reader/${reader.id}/removeManga?mangaId=${id}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${reader.id}/removeManga?mangaId=${id}`, requestParams);
|
||||
console.log(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
@ -148,7 +130,7 @@ export default function ReaderAction() {
|
||||
addManga().then((result) => {
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||
console.log(result);
|
||||
getReader()
|
||||
getReader(readerId)
|
||||
.then(_data =>setReader(_data));
|
||||
});
|
||||
}
|
||||
@ -158,11 +140,10 @@ export default function ReaderAction() {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
console.log(host + `/reader/${reader.id}/addManga?mangaId=${mangaId}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${reader.id}/addManga?mangaId=${mangaId}`, requestParams);
|
||||
console.log(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
@ -173,6 +154,16 @@ export default function ReaderAction() {
|
||||
<h1>Reader</h1>
|
||||
<form id="form">
|
||||
<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">
|
||||
<button type="button" className="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal2">Добавить</button>
|
||||
</div>
|
||||
|
@ -1,88 +0,0 @@
|
||||
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;
|
@ -1,112 +0,0 @@
|
||||
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() {
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [creatorId, setCreatorId] = useState(0);
|
||||
|
||||
@ -16,38 +16,46 @@ export default function Creator() {
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
const table = document.getElementById("tbody");
|
||||
|
||||
useEffect(() => {
|
||||
getData()
|
||||
.then(_data =>setData(_data)) ;
|
||||
console.log(2);
|
||||
},[]);
|
||||
|
||||
|
||||
const getData = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = host + `/creator`;
|
||||
const response = await fetch(requestUrl, requestParams);
|
||||
setData(await response.json())
|
||||
const response = await fetch(host + "/creator");
|
||||
const _data = await response.json()
|
||||
console.log(data);
|
||||
}
|
||||
return _data;
|
||||
|
||||
//table.innerHTML = "";
|
||||
// data.forEach(Creator => {
|
||||
// let temp = "<select>";
|
||||
// Creator.mangas.forEach(Manga => {
|
||||
// temp += `<option>${Manga.mangaName + " " + Manga.chapterCount}</option>>`
|
||||
// })
|
||||
// temp += "</select>"
|
||||
// table.innerHTML +=
|
||||
// `<tr>
|
||||
// <th scope="row">${Creator.id}</th>
|
||||
// <td>${Creator.creatorName}</td>
|
||||
// <td>${Creator.hashedPassword}</td>
|
||||
// <td>${temp}</td>
|
||||
// </tr>`;
|
||||
// })
|
||||
}
|
||||
|
||||
const create = async function (){
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
console.log((host + `/creator?creatorName=${creatorName}&password=${password}`));
|
||||
const response = await fetch(host + `/creator?creatorName=${creatorName}&password=${password}`, requestParams);
|
||||
getData();
|
||||
}
|
||||
@ -63,7 +71,6 @@ export default function Creator() {
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
@ -81,9 +88,6 @@ export default function Creator() {
|
||||
}
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
await fetch(host + `/creator/`, requestParams);
|
||||
}
|
||||
@ -96,7 +100,6 @@ export default function Creator() {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
|
171
front/src/MainS/Manga.jsx
Normal file
@ -0,0 +1,171 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import TableManga from '../components/Table/TableManga';
|
||||
|
||||
export default function Manga() {
|
||||
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [creatorId, setCreatorId] = useState(0);
|
||||
|
||||
const [mangaId, setMangaId] = useState(0);
|
||||
|
||||
const [mangaName, setMangaName] = useState("");
|
||||
|
||||
const [chapterCount, setChapterCount] = useState(0);
|
||||
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
|
||||
|
||||
const table = document.getElementById("tbody");
|
||||
|
||||
useEffect(() => {
|
||||
getData();
|
||||
},[]);
|
||||
|
||||
|
||||
const getData = async function () {
|
||||
const response = await fetch(host + "/manga");
|
||||
setData(await response.json())
|
||||
console.log(data);
|
||||
//table.innerHTML = "";
|
||||
// data.forEach(Manga => {
|
||||
// let temp = "<select>";
|
||||
// Manga.mangas.forEach(Manga => {
|
||||
// temp += `<option>${Manga.mangaName + " " + Manga.chapterCount}</option>>`
|
||||
// })
|
||||
// temp += "</select>"
|
||||
// table.innerHTML +=
|
||||
// `<tr>
|
||||
// <th scope="row">${Manga.id}</th>
|
||||
// <td>${Manga.mangaName}</td>
|
||||
// <td>${Manga.hashedPassword}</td>
|
||||
// <td>${temp}</td>
|
||||
// </tr>`;
|
||||
// })
|
||||
}
|
||||
|
||||
const create = async function (){
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga?creatorId=${creatorId}&chapterCount=${chapterCount}&mangaName=${mangaName}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const remove = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (mangaId !== 0) {
|
||||
if (!confirm('Do you really want to remove this item?')) {
|
||||
console.info('Canceled');
|
||||
return;
|
||||
}
|
||||
}
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/` + mangaIdInput.value, requestParams);
|
||||
console.log("REMOVE");
|
||||
getData();
|
||||
}
|
||||
|
||||
const update = async function (){
|
||||
console.info('Try to update item');
|
||||
if (mangaId === 0 || mangaName == null || password === 0) {
|
||||
return;
|
||||
}
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/manga/${mangaIdInput.value}?chapterCount=${chapterCountInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
const createButton = (e) =>{
|
||||
e.preventDefault()
|
||||
create().then((result) => {
|
||||
getData();
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
|
||||
});
|
||||
}
|
||||
|
||||
const removeButton = (e) =>{
|
||||
e.preventDefault()
|
||||
remove();
|
||||
getData();
|
||||
}
|
||||
|
||||
const updateButton = (e) =>{
|
||||
e.preventDefault()
|
||||
update();
|
||||
getData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div className="container" id="root-div">
|
||||
<div className="content">
|
||||
<h1>Manga</h1>
|
||||
<form id="form">
|
||||
<div className="d-flex justify-content-evenly mt-3">
|
||||
<div className="col-sm-2">
|
||||
<label htmlFor="mangaId" className="form-label">creatorId</label>
|
||||
<input type='number' value = {creatorId} onChange={event => setCreatorId(event.target.value)} className="form-control"/>
|
||||
</div>
|
||||
<div className="col-sm-2">
|
||||
<label htmlFor="mangaId" className="form-label">mangaId</label>
|
||||
<input type='number' value = {mangaId} onChange={event => setMangaId(event.target.value)} className="form-control"/>
|
||||
</div>
|
||||
<div className="col-sm-2">
|
||||
<label htmlFor="mangaName" className="form-label">mangaName</label>
|
||||
<input type='text' value = {mangaName} onChange={event => setMangaName(event.target.value)} className="form-control"/>
|
||||
</div>
|
||||
<div className="col-sm-2">
|
||||
<label htmlFor="chapterCount" className="form-label">chapterCount</label>
|
||||
<input type='number' value = {chapterCount} onChange={event => setChapterCount(event.target.value)} className="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row mt-3">
|
||||
<div className="d-grid col-sm-3 mx-auto">
|
||||
<button type="submit" onClick={createButton} className="btn btn-success">Добавить</button>
|
||||
</div>
|
||||
<div className="d-grid col-sm-3 mx-auto">
|
||||
<button type="submit" onClick={updateButton} className="btn btn-success" id="btnUpdate" >Обновить</button>
|
||||
</div>
|
||||
<div className="d-grid col-sm-3 mx-auto">
|
||||
<button id="btnRemove" onClick={removeButton} className="btn btn-success">Удалить</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div className="row table-responsive text-white">
|
||||
|
||||
<table className="table mt-3 text-white">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">mangaName</th>
|
||||
<th scope="col">chapterCount</th>
|
||||
<th scope="col">mangaId</th>
|
||||
<th scope="col">readers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<TableManga items = {data}/>
|
||||
{/* <tbody id="tbody">
|
||||
</tbody> */}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import TableReader from '../components/Table/TableReader';
|
||||
import MyModal from "../components/Modal/MyModal";
|
||||
import EditReaderForm from "../components/Form/EditReaderForm";
|
||||
|
||||
export default function ReaderS() {
|
||||
|
||||
const host = "http://localhost:8080/api/1.0";
|
||||
const host = "http://localhost:8080";
|
||||
|
||||
const [readerId, setReaderId] = useState(0);
|
||||
|
||||
@ -13,11 +15,12 @@ export default function ReaderS() {
|
||||
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
const [modal, setModal] = useState(false);
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
const table = document.getElementById("tbody");
|
||||
|
||||
@ -26,30 +29,21 @@ export default function ReaderS() {
|
||||
console.log(2);
|
||||
},[]);
|
||||
|
||||
|
||||
const getData = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = host + `/reader`;
|
||||
const response = await fetch(requestUrl, requestParams);
|
||||
const response = await fetch(host + "/reader");
|
||||
setData(await response.json())
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
|
||||
const create = async function (){
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/reader?readerName=${readerName}&password=${password}`, requestParams);
|
||||
alert(response);
|
||||
console.log(response);
|
||||
getData();
|
||||
}
|
||||
|
||||
@ -65,7 +59,6 @@ export default function ReaderS() {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/reader/` + id, requestParams);
|
||||
@ -81,9 +74,6 @@ export default function ReaderS() {
|
||||
}
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
await fetch(host + `/reader/`, requestParams);
|
||||
getData();
|
||||
@ -97,7 +87,6 @@ export default function ReaderS() {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
@ -115,7 +104,6 @@ export default function ReaderS() {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
@ -128,7 +116,6 @@ export default function ReaderS() {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
@ -171,7 +158,7 @@ export default function ReaderS() {
|
||||
<main>
|
||||
<div className="container" id="root-div">
|
||||
<div className="content">
|
||||
<h1>Readers</h1>
|
||||
<h1>Reader</h1>
|
||||
<form id="form">
|
||||
<div className="d-flex justify-content-evenly mt-3">
|
||||
<div className="col-sm-2">
|
||||
|
46
front/src/components/Banner/Banner.jsx
Normal file
@ -0,0 +1,46 @@
|
||||
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>
|
||||
);
|
||||
}
|
65
front/src/components/Banner/banner.css
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
|
||||
#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,65 +1,6 @@
|
||||
import {NavLink, useNavigate} from 'react-router-dom';
|
||||
import {useEffect, useState} from "react";
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
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 (
|
||||
<nav className="navbar navbar-expand-lg navbar-dark">
|
||||
<div className="container-fluid">
|
||||
@ -70,27 +11,14 @@ console.log(userRole);
|
||||
</button>
|
||||
<div className="collapse navbar-collapse" id="navbarNav">
|
||||
<ul className="navbar-nav">
|
||||
{props.links.map(route =>{
|
||||
if (validate(route.userGroup)) {
|
||||
return (
|
||||
{props.links.map(route =>
|
||||
<li key={route.path}
|
||||
className="nav-item">
|
||||
<NavLink className="nav-link" to={route.path}>
|
||||
{route.label}
|
||||
</NavLink>
|
||||
</li>
|
||||
);}}
|
||||
)}
|
||||
{userRole === "NONE"?
|
||||
null
|
||||
:
|
||||
<div className="border-bottom pb-3 mb-3">
|
||||
<button className="btn btn-primary"
|
||||
onClick={logoutButtonOnClick}>
|
||||
Log Out
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -10,8 +10,10 @@ export default function ReaderList(props) {
|
||||
props.readers?.map((reader) =>
|
||||
<div key={reader.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
||||
<div>
|
||||
<div className="text-white pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
||||
Имя пользователя: {reader.readerName}
|
||||
<div className="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"
|
||||
to={`/readeraction?id=${reader.id}`}>Имя пользователя: {reader.readerName}
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -14,7 +14,7 @@ export default function AddMangaModal(props) {
|
||||
<h5 className="modal-title" id="exampleModalLabel2">Создание манги</h5>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<label htmlFor="chapterCount" className="form-label">chapterCount</label>
|
||||
<input type='number' value = {props.chapterCount} onChange={event => props.setChapterCount(event.target.value)} className="form-control"/>
|
||||
|
@ -14,7 +14,7 @@ export default function AddMangaReaderModal(props) {
|
||||
<h5 className="modal-title" id="exampleModalLabel2">Добавление манги к читателю</h5>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<select className="form-select" value={props.mangaId} onChange={event => props.setMangaId(event.target.value)} aria-label="Default select example">
|
||||
<option value={0}>Manga</option>
|
||||
|
@ -13,7 +13,7 @@ export default function EditMangaModal(props) {
|
||||
<h5 className="modal-title" id="exampleModalLabel">Изменение манги</h5>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<label htmlFor="chapterCount" className="form-label">chapterCount</label>
|
||||
<input type='number' value={props.chapterCount} onChange={event => props.setChapterCount(event.target.value)} className="form-control"/>
|
||||
|
23
front/src/components/Modal/MyModal.jsx
Normal file
@ -0,0 +1,23 @@
|
||||
import cl from './MyModal.module.css';
|
||||
import React from 'react'
|
||||
const MyModal = (props) => {
|
||||
|
||||
const rootClasses = [cl.myModal]
|
||||
if(props.visible){
|
||||
rootClasses.push(cl.active);
|
||||
}
|
||||
|
||||
const setVisibleFunc = () =>{
|
||||
props.setVisible(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={rootClasses.join(' ')} onClick={() => setVisibleFunc()}>
|
||||
<div className={cl.MyModalContent} onClick={(e) => e.stopPropagation()}>
|
||||
{props.children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MyModal
|
20
front/src/components/Modal/MyModal.module.css
Normal file
@ -0,0 +1,20 @@
|
||||
.myModal{
|
||||
position:fixed;
|
||||
top:0;
|
||||
bottom:0;
|
||||
right:0;
|
||||
left:0;
|
||||
display: none;
|
||||
background: rgba(0,0,0,0.5)
|
||||
}
|
||||
.MyModalContent {
|
||||
padding: 25px;
|
||||
background: white;
|
||||
border-radius:16px;
|
||||
min-width:250px;
|
||||
}
|
||||
.myModal.active{
|
||||
display:flex;
|
||||
Justify-content:center;
|
||||
align-items:center;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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;
|
@ -6,13 +6,13 @@ export default function TableCreator(props) {
|
||||
return (
|
||||
<tbody>
|
||||
{
|
||||
props.items?.map((item, index) =>
|
||||
props.items.map((item, index) =>
|
||||
<tr key={item.id}>
|
||||
<td>{item.id}</td>
|
||||
<td>{item.creatorName}</td>
|
||||
<td>{item.hashedPassword}</td>
|
||||
<td>
|
||||
<select className="form-select" aria-label="Default select example">{item.mangas?.map(manga =>
|
||||
<select className="form-select" aria-label="Default select example">{item.mangas.map(manga =>
|
||||
<option key={manga.mangaName } >{manga.mangaName + " " +manga.chapterCount}</option>)}
|
||||
</select>
|
||||
</td>
|
||||
|
25
front/src/components/Table/TableManga.jsx
Normal file
@ -0,0 +1,25 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
|
||||
export default function TableManga(props) {
|
||||
|
||||
return (
|
||||
<tbody>
|
||||
{
|
||||
props.items.map((item, index) =>
|
||||
<tr key={item.id} >
|
||||
<td>{item.id}</td>
|
||||
<td>{item.mangaName}</td>
|
||||
<td>{item.chapterCount}</td>
|
||||
<td>{item.creatorId}</td>
|
||||
<td>
|
||||
<select className="form-select" aria-label="Default select example">{item.readers.map(reader =>
|
||||
<option key={reader.id}>{reader.readerName}</option>)}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
</tbody >
|
||||
);
|
||||
}
|
@ -6,13 +6,13 @@ export default function TableReader(props) {
|
||||
return (
|
||||
<tbody>
|
||||
{
|
||||
props.items?.map((item, index) =>
|
||||
props.items.map((item) =>
|
||||
<tr key={item.id}>
|
||||
<td>{item.id}</td>
|
||||
<td>{item.readerName}</td>
|
||||
<td>{item.hashedPassword}</td>
|
||||
<td>
|
||||
<select className="form-select" aria-label="Default select example">{item.mangas?.map(manga =>
|
||||
<select className="form-select" aria-label="Default select example">{item.mangas.map(manga =>
|
||||
<option key={manga.id}>{manga.mangaName}</option>)}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -3,9 +3,11 @@ package com.LabWork.app;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
public class AppApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AppApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
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")));
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.LabWork.app.MangaStore.configuration.jwt;
|
||||
|
||||
public class JwtException extends RuntimeException {
|
||||
public JwtException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public JwtException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,27 +2,22 @@ package com.LabWork.app.MangaStore.controller;
|
||||
|
||||
import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto;
|
||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
||||
import com.LabWork.app.MangaStore.service.UserService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/creator")
|
||||
@RequestMapping("/creator")
|
||||
public class CreatorController {
|
||||
private final CreatorService creatorService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public CreatorController(CreatorService creatorService,
|
||||
UserService userService) {
|
||||
public CreatorController(CreatorService creatorService) {
|
||||
this.creatorService = creatorService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/{login}")
|
||||
public CreatorMangaDto getCreator(@PathVariable String login) {
|
||||
return new CreatorMangaDto(creatorService.findCreator(userService.findByLogin(login).getCreator().getId()));
|
||||
@GetMapping("/{id}")
|
||||
public CreatorMangaDto getCreator(@PathVariable Long id) {
|
||||
return new CreatorMangaDto(creatorService.findCreator(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -32,18 +27,18 @@ public class CreatorController {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/* @PostMapping
|
||||
@PostMapping
|
||||
public CreatorMangaDto createCreator(@RequestParam("creatorName") String creatorName,
|
||||
@RequestParam("password") String password) {
|
||||
return new CreatorMangaDto(creatorService.addCreator());
|
||||
}*/
|
||||
return new CreatorMangaDto(creatorService.addCreator(creatorName, password));
|
||||
}
|
||||
|
||||
/* @PutMapping("/{id}")
|
||||
@PutMapping("/{id}")
|
||||
public CreatorMangaDto updateCreator(@PathVariable Long id,
|
||||
@RequestParam("creatorName") String creatorName,
|
||||
@RequestParam("password") String password) {
|
||||
return new CreatorMangaDto(creatorService.updateCreator(id, creatorName, password));
|
||||
}*/
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public CreatorMangaDto deleteCreator(@PathVariable Long id) {
|
||||
|
@ -2,35 +2,29 @@ package com.LabWork.app.MangaStore.controller;
|
||||
|
||||
|
||||
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.SupportDto.MangaDto;
|
||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
||||
import com.LabWork.app.MangaStore.service.MangaService;
|
||||
import com.LabWork.app.MangaStore.configuration.OpenAPI30Configuration;
|
||||
import com.LabWork.app.MangaStore.service.UserService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/manga")
|
||||
@RequestMapping("/manga")
|
||||
public class MangaController {
|
||||
private final MangaService mangaService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final CreatorService creatorService;
|
||||
public MangaController(MangaService mangaService,
|
||||
UserService userService) {
|
||||
CreatorService creatorService) {
|
||||
this.mangaService = mangaService;
|
||||
this.userService = userService;
|
||||
this.creatorService = creatorService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public MangaUserDto getManga(@PathVariable Long id) {
|
||||
return new MangaUserDto(mangaService.findManga(id), mangaService.getReader(id).stream()
|
||||
.map(x -> userService.findUser(x.getId()))
|
||||
.toList());
|
||||
public MangaReaderDto getManga(@PathVariable Long id) {
|
||||
return new MangaReaderDto(mangaService.findManga(id), mangaService.getReader(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -46,6 +40,19 @@ public class MangaController {
|
||||
.map(x -> new ReaderMangaDto(x))
|
||||
.toList();
|
||||
}
|
||||
/*
|
||||
@PostMapping
|
||||
public MangaReaderDto createManga(@RequestParam("creatorId") Long creatorId,
|
||||
@RequestParam("chapterCount") Integer chapterCount,
|
||||
@RequestParam("mangaName") String mangaName) {
|
||||
return new MangaReaderDto(mangaService.addManga(creatorId, chapterCount, mangaName), mangaService.getReader(creatorId));
|
||||
}*/
|
||||
|
||||
/* @PutMapping("/{id}")
|
||||
public MangaReaderDto updateManga(@PathVariable Long id,
|
||||
@RequestParam("chapterCount") Integer chapterCount) {
|
||||
return new MangaReaderDto(mangaService.updateManga(id, chapterCount), mangaService.getReader(id));
|
||||
}*/
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public MangaDto deleteManga(@PathVariable Long id) {
|
||||
@ -54,7 +61,7 @@ public class MangaController {
|
||||
|
||||
@PostMapping
|
||||
public MangaDto createManga(@RequestBody @Valid MangaDto mangaDto) {
|
||||
return new MangaDto(mangaService.addManga(mangaDto));
|
||||
return new MangaDto(creatorService.addManga(mangaDto));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
|
@ -1,19 +0,0 @@
|
||||
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,34 +1,30 @@
|
||||
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.SupportDto.MangaDto;
|
||||
import com.LabWork.app.MangaStore.service.CreatorService;
|
||||
import com.LabWork.app.MangaStore.service.MangaService;
|
||||
import com.LabWork.app.MangaStore.service.ReaderService;
|
||||
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 java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(OpenAPI30Configuration.API_PREFIX + "/reader")
|
||||
@RequestMapping("/reader")
|
||||
public class ReaderController {
|
||||
private final ReaderService readerService;
|
||||
|
||||
private final UserService userService;
|
||||
private final MangaService mangaService;
|
||||
|
||||
public ReaderController(ReaderService readerService,
|
||||
UserService userService) {
|
||||
MangaService mangaService) {
|
||||
this.readerService = readerService;
|
||||
this.userService = userService;
|
||||
this.mangaService = mangaService;
|
||||
}
|
||||
|
||||
@GetMapping("/{login}")
|
||||
public ReaderMangaDto getReader(@PathVariable String login) {
|
||||
return new ReaderMangaDto(readerService.findReader(userService.findByLogin(login).getReader().getId()));
|
||||
@GetMapping("/{id}")
|
||||
public ReaderMangaDto getReader(@PathVariable Long id) {
|
||||
return new ReaderMangaDto(readerService.findReader(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -38,15 +34,10 @@ public class ReaderController {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/* @PostMapping
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public String createReader(@RequestParam("readerName") String readerName,
|
||||
@PostMapping
|
||||
public ReaderMangaDto createReader(@RequestParam("readerName") String readerName,
|
||||
@RequestParam("password") String password) {
|
||||
try {
|
||||
return new ReaderMangaDto(readerService.addReader(readerName, password)).toString();
|
||||
} catch (ValidationException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
return new ReaderMangaDto(readerService.addReader(readerName, password));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@ -54,18 +45,18 @@ public class ReaderController {
|
||||
@RequestParam("readerName") String readerName,
|
||||
@RequestParam("password") String password) {
|
||||
return new ReaderMangaDto(readerService.updateReader(id, readerName, password));
|
||||
}*/
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/addManga")
|
||||
public MangaDto addManga(@PathVariable Long id,
|
||||
@RequestParam("mangaId") Long mangaId) {
|
||||
return new MangaDto(readerService.addManga(mangaId, id));
|
||||
return new MangaDto(mangaService.addMangaToReader(mangaId, id));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/removeManga")
|
||||
public MangaDto removeManga(@PathVariable Long id,
|
||||
@RequestParam("mangaId") Long mangaId) {
|
||||
return new MangaDto(readerService.removeManga(mangaId, id));
|
||||
return new MangaDto(mangaService.removeMangaToReader(mangaId, id));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -1,90 +0,0 @@
|
||||
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,10 +13,23 @@ public class Creator {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
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)
|
||||
private List<Manga> mangas;
|
||||
|
||||
public Creator() {
|
||||
}
|
||||
|
||||
public Creator(String creatorName, String hashedPassword) {
|
||||
this.creatorName = creatorName;
|
||||
this.hashedPassword = hashedPassword;
|
||||
this.mangas = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -28,10 +41,26 @@ public class Creator {
|
||||
return mangas;
|
||||
}
|
||||
|
||||
public String getCreatorName() {
|
||||
return creatorName;
|
||||
}
|
||||
|
||||
public String getHashedPassword() {
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
public void setMangas(List<Manga> mangas) {
|
||||
this.mangas = mangas;
|
||||
}
|
||||
|
||||
public void setCreatorName(String creatorName) {
|
||||
this.creatorName = creatorName;
|
||||
}
|
||||
|
||||
public void setHashedPassword(String hashedPassword) {
|
||||
this.hashedPassword = hashedPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -49,6 +78,8 @@ public class Creator {
|
||||
public String toString() {
|
||||
return "Creator{" +
|
||||
"id=" + id +
|
||||
", creatorName='" + creatorName + '\'' +
|
||||
", hashedPassword='" + hashedPassword + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,12 @@ public class Manga {
|
||||
public Manga() {
|
||||
}
|
||||
|
||||
public Manga(Creator creator, String mangaName, Integer chapterCount, String image) {
|
||||
public Manga(Creator creator, String mangaName, Integer chapterCount) {
|
||||
this.creator = creator;
|
||||
this.creatorId = creatorId;
|
||||
this.mangaName = mangaName;
|
||||
this.chapterCount = chapterCount;
|
||||
this.image = image.getBytes();
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Manga(Creator creator, MangaDto mangaDto) {
|
||||
|
@ -13,29 +13,40 @@ public class Reader {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
private String readerName;
|
||||
|
||||
@Column
|
||||
private String hashedPassword;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||
/*@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)*/
|
||||
/*orphanRemoval=true*/
|
||||
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(String readerName, String hashedPassword) {
|
||||
this.readerName = readerName;
|
||||
this.hashedPassword = hashedPassword;
|
||||
this.mangas = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
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 void setMangas(List<Manga> mangas) { this.mangas = mangas; }
|
||||
@ -57,6 +68,8 @@ public class Reader {
|
||||
public String toString() {
|
||||
return "Reader{" +
|
||||
"id=" + id +
|
||||
", readerName='" + readerName + '\'' +
|
||||
", hashedPassword='" + hashedPassword + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,144 +0,0 @@
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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";
|
||||
}
|
||||
}
|
@ -6,16 +6,15 @@ import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
||||
import java.util.List;
|
||||
|
||||
public class CreatorMangaDto {
|
||||
private long id;
|
||||
private String creatorName;
|
||||
private String hashedPassword;
|
||||
private List<MangaDto> mangas;
|
||||
|
||||
public CreatorMangaDto() {
|
||||
}
|
||||
private final long id;
|
||||
private final String creatorName;
|
||||
private final String hashedPassword;
|
||||
private final List<MangaDto> mangas;
|
||||
|
||||
public CreatorMangaDto(Creator creator) {
|
||||
this.id = creator.getId();
|
||||
this.creatorName = creator.getCreatorName();
|
||||
this.hashedPassword = creator.getHashedPassword();
|
||||
this.mangas = creator.getMangas().stream()
|
||||
.map(x -> new MangaDto(x))
|
||||
.toList();
|
||||
@ -34,16 +33,4 @@ public class CreatorMangaDto {
|
||||
}
|
||||
|
||||
public List<MangaDto> getMangas() { return mangas; }
|
||||
|
||||
public void setCreatorName(String creatorName) {
|
||||
this.creatorName = creatorName;
|
||||
}
|
||||
|
||||
public void setHashedPassword(String hashedPassword) {
|
||||
this.hashedPassword = hashedPassword;
|
||||
}
|
||||
|
||||
public void setMangas(List<MangaDto> mangas) {
|
||||
this.mangas = mangas;
|
||||
}
|
||||
}
|
||||
|
@ -3,24 +3,20 @@ package com.LabWork.app.MangaStore.model.Dto;
|
||||
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.ReaderDto;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class MangaReaderDto {
|
||||
private Long id;
|
||||
private final Long id;
|
||||
|
||||
private Long creatorId;
|
||||
private String mangaName;
|
||||
private Integer chapterCount;
|
||||
private List<ReaderDto> readers;
|
||||
private final Long creatorId;
|
||||
private final String mangaName;
|
||||
private final Integer chapterCount;
|
||||
private final List<ReaderDto> readers;
|
||||
private String image;
|
||||
|
||||
public MangaReaderDto() {
|
||||
}
|
||||
|
||||
public MangaReaderDto(Manga manga, List<Reader> listReader) {
|
||||
this.id = manga.getId();
|
||||
this.creatorId = manga.getCreator().getId();
|
||||
@ -56,21 +52,4 @@ public class MangaReaderDto {
|
||||
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;}
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
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;}
|
||||
}
|
@ -14,11 +14,10 @@ public class ReaderMangaDto {
|
||||
|
||||
private List<MangaDto> mangas;
|
||||
|
||||
public ReaderMangaDto() {
|
||||
}
|
||||
|
||||
public ReaderMangaDto(Reader reader) {
|
||||
this.id = reader.getId();
|
||||
this.readerName = reader.getReaderName();
|
||||
this.hashedPassword = reader.getHashedPassword();
|
||||
this.mangas = reader.getMangas().stream()
|
||||
.map(y -> new MangaDto(y))
|
||||
.toList();
|
||||
@ -34,16 +33,4 @@ public class ReaderMangaDto {
|
||||
|
||||
public List<MangaDto> getMangas() { return mangas; }
|
||||
|
||||
public void setReaderName(String readerName) {
|
||||
this.readerName = readerName;
|
||||
}
|
||||
|
||||
public void setHashedPassword(String hashedPassword) {
|
||||
this.hashedPassword = hashedPassword;
|
||||
}
|
||||
|
||||
public void setMangas(List<MangaDto> mangas) {
|
||||
this.mangas = mangas;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,9 +14,6 @@ public class MangaDto {
|
||||
private Integer chapterCount;
|
||||
private String image;
|
||||
|
||||
public MangaDto() {
|
||||
}
|
||||
|
||||
public MangaDto(Manga manga) {
|
||||
this.id = manga.getId();
|
||||
this.creatorId = manga.getCreator().getId();
|
||||
@ -24,6 +21,9 @@ public class MangaDto {
|
||||
this.chapterCount = manga.getChapterCount();
|
||||
this.image = new String(manga.getImage(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public MangaDto() {
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -44,17 +44,4 @@ public class MangaDto {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setMangaName(String mangaName) {
|
||||
this.mangaName = mangaName;
|
||||
}
|
||||
|
||||
public void setChapterCount(Integer chapterCount) {
|
||||
this.chapterCount = chapterCount;
|
||||
}
|
||||
|
||||
public void setCreatorId(Long creatorId) {
|
||||
this.creatorId = creatorId;
|
||||
}
|
||||
|
||||
public void setImage(String image) {this.image = image;}
|
||||
}
|
||||
|
@ -11,16 +11,10 @@ public class ReaderDto {
|
||||
|
||||
private String hashedPassword;
|
||||
|
||||
public ReaderDto() {
|
||||
}
|
||||
|
||||
public ReaderDto(Reader reader) {
|
||||
this.id = reader.getId();
|
||||
}
|
||||
|
||||
public ReaderDto(Reader reader, String readerName) {
|
||||
this.id = reader.getId();
|
||||
this.readerName = readerName;
|
||||
this.readerName = reader.getReaderName();
|
||||
this.hashedPassword = reader.getHashedPassword();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@ -30,12 +24,4 @@ public class ReaderDto {
|
||||
public String getReaderName() { return readerName; }
|
||||
|
||||
public String getHashedPassword() { return hashedPassword; }
|
||||
|
||||
public void setrRaderName(String readerName) {
|
||||
this.readerName = readerName;
|
||||
}
|
||||
|
||||
public void setHashedPassword(String hashedPassword) {
|
||||
this.hashedPassword = hashedPassword;
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -3,8 +3,12 @@ package com.LabWork.app.MangaStore.service;
|
||||
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
|
||||
import com.LabWork.app.MangaStore.service.Exception.MangaNotFoundException;
|
||||
import com.LabWork.app.MangaStore.service.Repository.CreatorRepository;
|
||||
import com.LabWork.app.MangaStore.service.Exception.CreatorNotFoundException;
|
||||
import com.LabWork.app.MangaStore.service.Repository.MangaRepository;
|
||||
import com.LabWork.app.MangaStore.service.Repository.ReaderRepository;
|
||||
import com.LabWork.app.MangaStore.util.validation.ValidatorUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -15,13 +19,16 @@ import java.util.Optional;
|
||||
public class CreatorService {
|
||||
private final CreatorRepository creatorRepository;
|
||||
private final MangaService mangaService;
|
||||
private final MangaRepository mangaRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public CreatorService(CreatorRepository creatorRepository,
|
||||
MangaService mangaService,
|
||||
ValidatorUtil validatorUtil) {
|
||||
ValidatorUtil validatorUtil,
|
||||
MangaRepository mangaRepository) {
|
||||
this.creatorRepository = creatorRepository;
|
||||
this.mangaService = mangaService;
|
||||
this.mangaRepository = mangaRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@ -35,20 +42,20 @@ public class CreatorService {
|
||||
public List<Creator> findAllCreators() { return creatorRepository.findAll(); }
|
||||
|
||||
@Transactional
|
||||
public Creator addCreator() {
|
||||
final Creator creator = new Creator();
|
||||
public Creator addCreator(String creatorName, String password) {
|
||||
final Creator creator = new Creator(creatorName, password);
|
||||
validatorUtil.validate(creator);
|
||||
return creatorRepository.save(creator);
|
||||
}
|
||||
|
||||
/* @Transactional
|
||||
@Transactional
|
||||
public Creator updateCreator(Long id, String creatorName, String password) {
|
||||
final Creator currentCreator = findCreator(id);
|
||||
currentCreator.setCreatorName(creatorName);
|
||||
currentCreator.setHashedPassword(password);
|
||||
validatorUtil.validate(currentCreator);
|
||||
return currentCreator;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Creator deleteCreator(Long id) {
|
||||
@ -67,4 +74,20 @@ public class CreatorService {
|
||||
public void deleteAllCreators() {
|
||||
creatorRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addManga(Long creatorId, Integer chapterCount, String mangaName) {
|
||||
final Creator currentCreator = findCreator(creatorId);
|
||||
final Manga manga = new Manga(currentCreator, mangaName, chapterCount);
|
||||
validatorUtil.validate(manga);
|
||||
return mangaRepository.save(manga);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addManga(MangaDto mangaDto) {
|
||||
final Creator currentCreator = findCreator(mangaDto.getCreatorId());
|
||||
final Manga manga = new Manga(currentCreator, mangaDto);
|
||||
validatorUtil.validate(manga);
|
||||
return mangaRepository.save(manga);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
@ -17,17 +17,14 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class MangaService {
|
||||
public final MangaRepository mangaRepository;
|
||||
public final CreatorRepository creatorRepository;
|
||||
public final ReaderService readerService;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public MangaService(MangaRepository mangaRepository,
|
||||
CreatorRepository creatorRepository,
|
||||
ReaderService readerService,
|
||||
ValidatorUtil validatorUtil) {
|
||||
this.mangaRepository = mangaRepository;
|
||||
this.readerService = readerService;
|
||||
this.creatorRepository = creatorRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@ -49,33 +46,10 @@ public class MangaService {
|
||||
return mangaRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Creator findCreator(Long id) {
|
||||
final Optional<Creator> creator = creatorRepository.findById(id);
|
||||
return creator.orElseThrow(() -> new CreatorNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addManga(Long creatorId, Integer chapterCount, String mangaName, String Image) {
|
||||
final Creator currentCreator = findCreator(creatorId);
|
||||
final Manga manga = new Manga(currentCreator, mangaName, chapterCount, Image);
|
||||
validatorUtil.validate(manga);
|
||||
return mangaRepository.save(manga);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addManga(MangaDto mangaDto) {
|
||||
final Creator currentCreator = findCreator(mangaDto.getCreatorId());
|
||||
final Manga manga = new Manga(currentCreator, mangaDto);
|
||||
validatorUtil.validate(manga);
|
||||
return mangaRepository.save(manga);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga updateManga(Long id, Integer chapterCount, String Image) {
|
||||
public Manga updateManga(Long id, Integer chapterCount) {
|
||||
final Manga currentManga = findManga(id);
|
||||
currentManga.setChapterCount(chapterCount);
|
||||
currentManga.setImage(Image.getBytes());
|
||||
validatorUtil.validate(currentManga);
|
||||
return currentManga;
|
||||
}
|
||||
@ -104,4 +78,25 @@ public class MangaService {
|
||||
public void deleteAllMangas() {
|
||||
mangaRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addMangaToReader(Long mangaId, Long readerId) {
|
||||
final Manga manga = findManga(mangaId);
|
||||
final Reader reader = readerService.findReader(readerId);
|
||||
validatorUtil.validate(reader);
|
||||
if (reader.getMangas().contains(manga))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
reader.getMangas().add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga removeMangaToReader(Long mangaId, Long readerId) {
|
||||
final Reader currentReader = readerService.findReader(readerId);
|
||||
final Manga currentManga = findManga(mangaId);
|
||||
currentReader.getMangas().remove(currentManga);
|
||||
return currentManga;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.LabWork.app.MangaStore.service;
|
||||
|
||||
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.service.Repository.MangaRepository;
|
||||
import com.LabWork.app.MangaStore.service.Repository.ReaderRepository;
|
||||
import com.LabWork.app.MangaStore.service.Exception.MangaNotFoundException;
|
||||
@ -17,14 +16,11 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class ReaderService {
|
||||
private final ReaderRepository readerRepository;
|
||||
private final MangaRepository mangaRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public ReaderService(ReaderRepository readerRepository,
|
||||
ValidatorUtil validatorUtil,
|
||||
MangaRepository mangaRepository) {
|
||||
ValidatorUtil validatorUtil) {
|
||||
this.readerRepository = readerRepository;
|
||||
this.mangaRepository = mangaRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@ -40,20 +36,20 @@ public class ReaderService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Reader addReader(User user) {
|
||||
final Reader reader = new Reader(user);
|
||||
public Reader addReader(String readerName, String password) {
|
||||
final Reader reader = new Reader(readerName, password);
|
||||
validatorUtil.validate(reader);
|
||||
return readerRepository.save(reader);
|
||||
}
|
||||
|
||||
/* @Transactional
|
||||
@Transactional
|
||||
public Reader updateReader(Long id, String readername, String password) {
|
||||
final Reader currentReader = findReader(id);
|
||||
currentReader.setReaderName(readername);
|
||||
currentReader.setHashedPassword(password);
|
||||
validatorUtil.validate(currentReader);
|
||||
return currentReader;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Reader deleteReader(Long id) {
|
||||
@ -67,31 +63,4 @@ public class ReaderService {
|
||||
public void deleteAllReaders() {
|
||||
readerRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Manga findManga(Long id) {
|
||||
final Optional<Manga> manga = mangaRepository.findById(id);
|
||||
return manga.orElseThrow(() -> new MangaNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga addManga(Long mangaId, Long readerId) {
|
||||
final Manga manga = findManga(mangaId);
|
||||
final Reader reader = findReader(readerId);
|
||||
validatorUtil.validate(reader);
|
||||
if (reader.getMangas().contains(manga))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
reader.getMangas().add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Manga removeManga(Long mangaId, Long readerId) {
|
||||
final Reader currentReader = findReader(readerId);
|
||||
final Manga currentManga = findManga(mangaId);
|
||||
currentReader.getMangas().remove(currentManga);
|
||||
return currentManga;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
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);
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
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,11 +3,7 @@ package com.LabWork.app.MangaStore.util.validation;
|
||||
import java.util.Set;
|
||||
|
||||
public class ValidationException extends RuntimeException {
|
||||
public <T> ValidationException(Set<String> errors) {
|
||||
public ValidationException(Set<String> errors) {
|
||||
super(String.join("\n", errors));
|
||||
}
|
||||
|
||||
public <T> ValidationException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.LabWork.app.MangaStore.configuration;
|
||||
package com.LabWork.app;
|
||||
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
@ -7,24 +7,24 @@ 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.ViewControllerRegistration;
|
||||
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("*");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
ViewControllerRegistration registration = registry.addViewController("/notFound");
|
||||
registration.setViewName("forward:/index.html");
|
||||
registration.setStatusCode(HttpStatus.OK);
|
||||
|
||||
// Alternative way (404 error hits the console):
|
||||
// > registry.addViewController("/notFound").setViewName("forward:/index.html");
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
spring.main.banner-mode=off
|
||||
server.port=8080
|
||||
#server.port=8080
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
@ -9,5 +9,3 @@ spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
jwt.dev-token=my-secret-jwt
|
||||
jwt.dev=true
|
@ -1,12 +1,62 @@
|
||||
package com.LabWork.app;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class AppApplicationTests {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AppApplicationTests.class, args);
|
||||
}
|
||||
|
||||
/* @Autowired
|
||||
MethodService methodService;
|
||||
|
||||
@Test
|
||||
void testMethodSumInt() {
|
||||
final String res = methodService.Sum(1, 2, "int");
|
||||
Assertions.assertEquals(3, Integer.parseInt(res));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodSumString() {
|
||||
final String res = methodService.Sum("1", "2", "string");
|
||||
Assertions.assertEquals("12", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusInt() {
|
||||
final String res = methodService.Difference(1, 2, "int");
|
||||
Assertions.assertEquals(-1, Integer.parseInt(res));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusString() {
|
||||
final String res = methodService.Difference("214324", "4", "string");
|
||||
Assertions.assertEquals("2132", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultInt() {
|
||||
final String res = methodService.Multiplication(1, 2, "int");
|
||||
Assertions.assertEquals(2, Integer.parseInt(res));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultString() {
|
||||
final String res = methodService.Multiplication("1", "2", "string");
|
||||
Assertions.assertEquals("11", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsInt() {
|
||||
final String res = methodService.Contains(123, 2, "int");
|
||||
Assertions.assertEquals(61, Integer.parseInt(res));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsString() {
|
||||
final String res = methodService.Contains("1", "2", "string");
|
||||
Assertions.assertEquals("false", res);
|
||||
}*/
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
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,4 +1,3 @@
|
||||
/*
|
||||
package com.LabWork.app;
|
||||
|
||||
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||
@ -33,12 +32,12 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
|
||||
Reader r11 = readerService.findReader(r1.getId());
|
||||
readerService.deleteReader(r11.getId());
|
||||
@ -55,13 +54,13 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "vagabond", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "vagabond");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
Reader r2 = readerService.addReader("2", "2");
|
||||
Reader r3 = readerService.addReader("3", "3");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m1.getId(), r2.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r2.getId());
|
||||
|
||||
log.info(r1.getMangas().toString());
|
||||
|
||||
@ -94,9 +93,9 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m3 = mangaService.addManga(c1.getId(), 0, "Manga_3", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Manga m3 = creatorService.addManga(c1.getId(), 0, "Manga_3");
|
||||
Creator c2 = creatorService.findCreator(c1.getId());
|
||||
Assertions.assertEquals(3, c2.getMangas().size());
|
||||
readerService.deleteAllReaders();
|
||||
@ -104,7 +103,6 @@ public class ReMangaTest {
|
||||
creatorService.deleteAllCreators();
|
||||
}
|
||||
|
||||
*/
|
||||
/* @Test
|
||||
void testCreatorAddManga() {
|
||||
readerService.deleteAllReaders();
|
||||
@ -121,10 +119,8 @@ public class ReMangaTest {
|
||||
log.info(m1.getCreator().toString());
|
||||
log.info(c1.toString());
|
||||
Assertions.assertEquals(c1.getCreatorName(), m1.getCreator().getCreatorName());
|
||||
}*//*
|
||||
}*/
|
||||
|
||||
|
||||
*/
|
||||
/* //бесполезня штука
|
||||
@Test
|
||||
void testCreatorDeleteManga() {
|
||||
@ -151,11 +147,8 @@ public class ReMangaTest {
|
||||
|
||||
Assertions.assertEquals(1, c1.getMangas().size());
|
||||
|
||||
}*//*
|
||||
|
||||
*/
|
||||
/*тестстим работоспособность гита*//*
|
||||
|
||||
}*/
|
||||
/*тестстим работоспособность гита*/
|
||||
@Test
|
||||
void testCreatorUpdated() {
|
||||
readerService.deleteAllReaders();
|
||||
@ -194,8 +187,8 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
creatorService.deleteCreator(c1.getId());
|
||||
log.info(mangaService.findAllMangas().toString());
|
||||
Assertions.assertEquals(0, mangaService.findAllMangas().size());
|
||||
@ -224,11 +217,11 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("1", "1");
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
creatorService.deleteCreator(c1.getId());
|
||||
log.info(mangaService.findAllMangas().toString());
|
||||
Assertions.assertEquals(0, mangaService.findAllMangas().size());
|
||||
@ -243,8 +236,8 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
c1 = creatorService.findCreator(c1.getId());
|
||||
m1 = mangaService.findManga(m1.getId());
|
||||
log.info(c1.getMangas().toString());
|
||||
@ -261,8 +254,8 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.updateManga(m1.getId(), 10, "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = mangaService.updateManga(m1.getId(), 10);
|
||||
m2 = mangaService.findManga(m2.getId());
|
||||
c1 = creatorService.findCreator(c1.getId());
|
||||
log.info(m2.toString());
|
||||
@ -281,12 +274,12 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("reader1", "password1");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
mangaService.deleteManga(m1.getId());
|
||||
r1 = readerService.findReader(r1.getId());
|
||||
|
||||
@ -306,8 +299,8 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
mangaService.deleteAllMangas();
|
||||
Assertions.assertEquals(0, mangaService.findAllMangas().size());
|
||||
readerService.deleteAllReaders();
|
||||
@ -321,12 +314,12 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
|
||||
log.info(r1.getMangas().toString());
|
||||
|
||||
@ -365,15 +358,15 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
|
||||
Reader r11 = readerService.findReader(r1.getId());
|
||||
readerService.removeManga(m1.getId(), r11.getId());
|
||||
mangaService.removeMangaToReader(m1.getId(), r11.getId());
|
||||
Reader r12 = readerService.findReader(r11.getId());
|
||||
|
||||
Manga m11 = mangaService.findManga(m1.getId());
|
||||
@ -391,13 +384,13 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
Reader r2 = readerService.addReader("2_R", "2");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
|
||||
Reader r11 = readerService.findReader(r1.getId());
|
||||
readerService.deleteReader(r11.getId());
|
||||
@ -417,12 +410,12 @@ public class ReMangaTest {
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first_C", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond", "1");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk", "1");
|
||||
Manga m1 = creatorService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = creatorService.addManga(c1.getId(), 10, "Berserk");
|
||||
Reader r1 = readerService.addReader("first_R", "1");
|
||||
|
||||
readerService.addManga(m1.getId(), r1.getId());
|
||||
readerService.addManga(m2.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m1.getId(), r1.getId());
|
||||
mangaService.addMangaToReader(m2.getId(), r1.getId());
|
||||
|
||||
Reader r11 = readerService.updateReader(r1.getId(), "reader", "password");
|
||||
r11 = readerService.findReader(r11.getId());
|
||||
@ -436,4 +429,3 @@ public class ReMangaTest {
|
||||
creatorService.deleteAllCreators();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|