Вроде готовая 4

This commit is contained in:
Николай 2023-04-08 22:37:28 +04:00
parent 13c1c40aa5
commit c73632f42f
44 changed files with 1108 additions and 130 deletions

Binary file not shown.

BIN
front/img/4_popular.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
front/img/5_popular.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
front/img/6_popular.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
front/img/popular_1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
front/img/popular_2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
front/img/popular_3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -6,6 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="module" src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/node_modules/@fortawesome/fontawesome-free/css/all.min.css">
<title>ReManga</title>
</head>
<body >

View File

@ -8,6 +8,7 @@
"name": "front",
"version": "1.0.0",
"dependencies": {
"@fortawesome/fontawesome-free": "^6.2.1",
"bootstrap": "5.3.0-alpha2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
@ -118,6 +119,15 @@
"node": ">=4"
}
},
"node_modules/@fortawesome/fontawesome-free": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.4.0.tgz",
"integrity": "sha512-0NyytTlPJwB/BF5LtRV8rrABDbe3TdTXqNB3PdZ+UUUZAEIrdOJdmABqKjt4AXwIoJNaRVVZEXxpNrqvE1GAYQ==",
"hasInstallScript": true,
"engines": {
"node": ">=6"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz",

View File

@ -11,7 +11,8 @@
"bootstrap": "5.3.0-alpha2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.4"
"react-router-dom": "^6.4.4",
"@fortawesome/fontawesome-free": "^6.2.1"
},
"devDependencies": {
"@types/react": "^18.0.24",

View File

@ -1,8 +1,12 @@
import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom';
import Creator from './components/Creator';
import Reader from './components/Reader';
import Creator from './MainS/Creator';
import Reader from './MainS/Reader';
import Header from './components/Header';
import Manga from './components/Manga';
import Manga from './MainS/Manga';
import CreatorAction from './Main/CreatorAction';
import ReaderAction from './Main/ReaderAction';
import MangaPage from './Main/MangaPage';
import Catalog from './Main/Catalog';
function Router(props) {
return useRoutes(props.rootRoute);
@ -14,6 +18,10 @@ export default function App() {
{ 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 /> },
];
const links = routes.filter(route => route.hasOwnProperty('label'));
const rootRoute = [

View File

@ -0,0 +1,9 @@
export default class MangaDto {
constructor(args) {
this.id = args.id || null;
this.creatorId = args.creatorId || 0;
this.mangaName = args.mangaName || "";
this.image = args.image;
this.chapterCount = args.chapterCount || 0;
}
}

View File

@ -0,0 +1,53 @@
import React, { useEffect, useState } from 'react'
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";
const [mangs, setMangs] = useState([]);
useEffect(() => {
getMangs()
.then(_data =>setMangs(_data));
console.log(2);
console.log(mangs);
},[]);
const getMangs = async function () {
const response = await fetch(host + "/manga");
const _data = await response.json()
console.log(_data);
return _data;
}
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">&#8593;&#8595;</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>
))}
</div>
</div>
</article>
);
}

View File

@ -0,0 +1,198 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../components/Table/TableCreator';
import MangaDto from "../Dto/Manga-Dto";
import MangaCreatorList from "../components/List/MangaCreatorList";
import AddMangaModal from "../components/Modal/AddMangaModal";
import EditMangaModal from "../components/Modal/EditMangaModal";
export default function CreatorAction() {
const host = "http://localhost:8080";
const [creatorData, setCreatorData] = useState([]);
const [creatorId, setCreatorId] = useState(0);
const [creator, setCreator] = useState([]);
const [mangaId, setMangaId] = useState(0);
const [chapterCount, setChapterCount] = useState(0);
const [mangaName, setMangaName] = useState("");
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
useEffect(() => {
getCreatorData()
.then(_data =>setCreatorData(_data));
},[]);
const getCreatorData = async function () {
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(creatorId)
.then(_data =>setCreator(_data));
});
}
const update = async function (){
console.info('Try to update item');
if (mangaId === 0) {
return;
}
mangaModel.id = mangaId;
mangaModel.chapterCount = chapterCount;
mangaModel.creatorId = creatorId;
mangaModel.image = imageURL;
mangaModel.mangaName = mangaName;
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(mangaModel),
};
const response = await fetch(host + `/manga/` + mangaModel.id, requestParams);
return await response.json();
}
const setMangaIdButton = (id) =>{
setMangaId(id);
}
const removeButton = (id) =>{
remove(id).then(() => {
getCreator(creatorId)
.then(_data =>setCreator(_data));
});
}
const remove = async function (id){
console.info('Try to remove item');
if (id !== 0) {
if (!confirm('Do you really want to remove this item?')) {
return;
}
}
const requestParams = {
method: "DELETE",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/manga/` + id, requestParams);
}
const createButton = (e) =>{
e.preventDefault()
create().then((result) => {
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
getCreator(creatorId)
.then(_data =>setCreator(_data));
});
}
const create = async function (){
mangaModel.chapterCount = chapterCount;
mangaModel.creatorId = creatorId;
mangaModel.image = imageURL;
mangaModel.mangaName = mangaName;
const requestParams = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(mangaModel),
};
const response = await fetch(host + `/manga`, requestParams);
return await response.json();
}
const [imageURL, setImageURL] = useState();
const fileReader = new FileReader();
fileReader.onloadend = () => {
setImageURL(fileReader.result);
};
const handleOnChange = (event) => {
event.preventDefault();
if (event.target.files && event.target.files.length) {
const file = event.target.files[0];
fileReader.readAsDataURL(file);
}
};
return (
<main>
<div className="container" id="root-div">
<div className="content">
<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>
</div>
</form>
<MangaCreatorList
creator={creator}
setMangaIdButton={setMangaIdButton}
removeButton={removeButton}
/>
<EditMangaModal
chapterCount={chapterCount}
setChapterCount={setChapterCount}
handleOnChange={handleOnChange}
updateButton={updateButton}
/>
<AddMangaModal
chapterCount={chapterCount}
setChapterCount={setChapterCount}
mangaName={mangaName}
setMangaName={setMangaName}
handleOnChange={handleOnChange}
createButton={createButton}
/>
</div>
</div>
</main>
);
}

View File

@ -0,0 +1,81 @@
import React, {useState, useEffect} from 'react';
import MangaDto from '../Dto/Manga-Dto';
export default function MangaPage() {
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
const host = "http://localhost:8080";
useEffect(() => {
const quryString = window.location.search;
const urlParams = new URLSearchParams(quryString);
const id = urlParams.get('id');
getCreator(id)
.then(_data =>setMangaModel(_data));
}, []);
const transformer = (mangaModel) => new MangaDto(mangaModel);
const url = "manga/";
useEffect(() => {
console.log(mangaModel);
}, [mangaModel]);
const getCreator = async function (id) {
const requestParams = {
method: "GET",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/manga/` + id, requestParams);
const _data = await response.json()
return _data;
}
return (
<main className="p-3">
<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" 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>
<div className="row">
<div className="col-xs-6 col-sm-3">Год производства</div>
<div className="col-xs-6 col-sm-3">1000</div>
</div>
<div className="row">
<div className="col-xs-6 col-sm-3">Страна</div>
<div className="col-xs-6 col-sm-3">Россия</div>
</div>
<div className="row">
<div className="col-xs-6 col-sm-3">Жанр</div>
<div className="col-xs-6 col-sm-3">Драма</div>
</div>
<div className="row">
<div className="col-xs-6 col-sm-3">Количество глав</div>
<div className="col-xs-6 col-sm-3">{mangaModel.chapterCount}</div>
</div>
<div className="row">
<div className="col-xs-6 col-sm-3">Возраст</div>
<div className="col-xs-6 col-sm-3">16+</div>
</div>
<div className="row text-white fw-bold fs-3">Описание</div>
<div className="row">
<div className="col-xs-6 col-sm-12">
<p>Ким Кон Чжа спокойно живет в своей халупе, завидуя всем популярным охотникам. Однажды его желание быть лучше всех сбывается и он получает легендарный навык Копирование способностей... ценой своей жизни.</p>
<p>Прежде чем он успевает понять это, его убивает охотник 1, Летний дух! Но это активирует его навык, и теперь он скопировал новый, Путешествие во времени после смерти.</p>
<p>Как Ким Кон Чжа же будет использовать эти навыки, чтобы победить конкурентов и подняться на вершину?</p>
</div>
</div>
</div>
</div>
</main>
);
}

View File

@ -0,0 +1,182 @@
import { useEffect, useState } from "react";
import TableReader from '../components/Table/TableReader';
import { NavLink } from 'react-router-dom';
import MangaReaderList from "../components/List/MangaReaderList";
import AddMangaReaderModal from "../components/Modal/AddMangaReaderModal";
export default function ReaderAction() {
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);
const [chapterCount, setChapterCount] = useState(0);
const [mangaName, setMangaName] = useState("");
useEffect(() => {
getReaderData()
.then(_data =>setReaderData(_data));
getMangaData()
.then(_data =>setMangaData(_data));
console.log(2);
console.log(readerData);
},[]);
const getReaderData = async function () {
const response = await fetch(host + "/reader");
const _data = await response.json()
console.log(_data);
return _data;
}
const getMangaData = async function () {
const response = await fetch(host + "/manga");
const _data = await response.json()
console.log(_data);
return _data;
}
useEffect(() => {
console.log(readerId);
getReader(readerId)
.then(_data =>setReader(_data));
console.log(readerId);
},[readerId]);
const getReader = async function (id) {
const requestParams = {
method: "GET",
headers: {
"Content-Type": "application/json",
}
};
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(readerId)
.then(_data =>setReader(_data));
});
console.log(readerId);
console.log(readerId);
console.log(reader);
}
const update = async function (){
console.info('Try to update item');
if (mangaId === 0) {
return;
}
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/manga/${mangaId}?chapterCount=${chapterCount}`, requestParams);
return await response.json();
}
const setMangaIdButton = (id) =>{
setMangaId(id);
}
const removeButton = (id) =>{
remove(id).then((result) => {
getReader(readerId)
.then(_data =>setReader(_data));
});
}
const remove = async function (id){
console.info('Try to remove item');
if (!confirm('Do you really want to remove this item?')) {
console.info('Canceled');
return;
}
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
console.log(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
const response = await fetch(host + `/reader/${readerId}/removeManga?mangaId=${id}`, requestParams);
return await response.json();
}
const addMangaButton = (e) =>{
e.preventDefault()
addManga().then((result) => {
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}]`);
console.log(result);
getReader(readerId)
.then(_data =>setReader(_data));
});
}
const addManga = async function (){
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
console.log(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
const response = await fetch(host + `/reader/${readerId}/addManga?mangaId=${mangaId}`, requestParams);
return await response.json();
}
return (
<main>
<div className="container" id="root-div">
<div className="content">
<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>
</div>
</form>
<MangaReaderList
reader={reader}
removeButton={removeButton}
/>
<AddMangaReaderModal
mangaId={mangaId}
setMangaId={setMangaId}
mangaData={mangaData}
addMangaButton={addMangaButton}
/>
</div>
</div>
</main>
);
}

View File

@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import TableCreator from './TableCreator';
import TableCreator from '../components/Table/TableCreator';
import MangaDto from '../Dto/Manga-Dto';
export default function Creator() {
@ -11,6 +12,7 @@ export default function Creator() {
const [password, setPassword] = useState("");
const [mangaModel, setMangaModel] = useState(new MangaDto({}));
const [data, setData] = useState([]);
@ -154,7 +156,7 @@ export default function Creator() {
</form>
<div className="row table-responsive text-white">
<table className="table mt-3">
<table className="table mt-3 text-white">
<thead>
<tr>
<th scope="col">#</th>

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import TableManga from './TableManga';
import TableManga from '../components/Table/TableManga';
export default function Manga() {
@ -149,7 +149,7 @@ export default function Manga() {
</form>
<div className="row table-responsive text-white">
<table className="table mt-3">
<table className="table mt-3 text-white">
<thead>
<tr>
<th scope="col">#</th>

View File

@ -1,7 +1,9 @@
import { useEffect, useState } from "react";
import TableReader from './TableReader';
import TableReader from '../components/Table/TableReader';
import MyModal from "../components/Modal/MyModal";
import EditReaderForm from "../components/Form/EditReaderForm";
export default function Reader() {
export default function ReaderS() {
const host = "http://localhost:8080";
@ -13,9 +15,12 @@ export default function Reader() {
const [password, setPassword] = useState("");
const [modal, setModal] = useState(false);
const [data, setData] = useState([]);
const table = document.getElementById("tbody");
@ -29,21 +34,6 @@ export default function Reader() {
const response = await fetch(host + "/reader");
setData(await response.json())
console.log(data);
//table.innerHTML = "";
// data.forEach(Reader => {
// let temp = "<select>";
// Reader.mangas.forEach(Manga => {
// temp += `<option>${Manga.mangaName + " " + Manga.chapterCount}</option>>`
// })
// temp += "</select>"
// table.innerHTML +=
// `<tr>
// <th scope="row">${Reader.id}</th>
// <td>${Reader.readerName}</td>
// <td>${Reader.hashedPassword}</td>
// <td>${temp}</td>
// </tr>`;
// })
}
const create = async function (){
@ -57,9 +47,9 @@ export default function Reader() {
getData();
}
const remove = async function (){
const remove = async function (id){
console.info('Try to remove item');
if (readerId !== 0) {
if (id !== 0) {
if (!confirm('Do you really want to remove this item?')) {
console.info('Canceled');
return;
@ -71,7 +61,7 @@ export default function Reader() {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/reader/` + readerId, requestParams);
const response = await fetch(host + `/reader/` + id, requestParams);
getData();
return await response.json();
}
@ -138,9 +128,8 @@ export default function Reader() {
create();
}
const removeButton = (e) =>{
e.preventDefault()
remove();
const removeButton = (id) =>{
remove(id);
}
@ -159,7 +148,11 @@ export default function Reader() {
addManga();
}
const setModal_Click = (e) =>{
e.preventDefault()
setModal(true)
//setData({type:'', name:'', description:'' })
}
return (
<main>
@ -192,9 +185,6 @@ export default function Reader() {
<div className="d-grid col-sm-3 m-3 mx-auto">
<button onClick={updateButton} className="btn btn-success">Обновить</button>
</div>
<div className="d-grid col-sm-3 m-3 mx-auto">
<button onClick={removeButton} className="btn btn-success">Удалить</button>
</div>
<div className="d-grid col-sm-2 m-3 mx-auto">
<button onClick={removeMangaButton} className="btn btn-success">Удалить мангу</button>
</div>
@ -205,16 +195,22 @@ export default function Reader() {
</form>
<div className="row table-responsive text-white">
<table className="table mt-3">
<table className="table mt-3 text-white">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">readerName</th>
<th scope="col">Password</th>
<th scope="col">Mangs</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<TableReader items = {data}/>
<TableReader
items = {data}
remove ={removeButton}
update ={updateButton}
/>
{/* <tbody id="tbody">
</tbody> */}
</table>

View File

@ -1,58 +0,0 @@
import { useEffect, useState } from "react";
export default function Adding() {
const [outcome, setOutcome] = useState(0);
const [first, setFirst] = useState(0);
const [second, setSecond] = useState(0);
const sum = (e) =>{
e.preventDefault()
fetch('http://localhost:8080/sum?first=' + first + '&second=' + second)
.then(response=>response.text())
.then(result=>setOutcome(result))
}
const ras = (e) =>{
e.preventDefault()
fetch('http://localhost:8080/ras?first=' + first + '&second=' + second)
.then(response=>response.text())
.then(result=>setOutcome(result))
}
const del = (e) =>{
e.preventDefault()
fetch('http://localhost:8080/del?first=' + first + '&second=' + second)
.then(response=>response.text())
.then(result=>setOutcome(result))
}
const pros = (e) =>{
e.preventDefault()
fetch('http://localhost:8080/pros?first=' + first + '&second=' + second)
.then(response=>response.text())
.then(result=>setOutcome(result))
}
return (
<main className="flex-shrink-0">
<div className="p-2">
<form>
<div className="form-group">
<label>Первое число</label>
<input type='number' value = {first} onChange={event => setFirst(event.target.value)} className="form-control"/>
</div>
<div className="form-group">
<label >Второе число</label>
<input type='number' value = {second} onChange={event => setSecond(event.target.value)} className="form-control"/>
</div>
<button onClick={sum} type="submit" className="btn btn-primary">Sum</button>
<button onClick={ras} type="submit" className="btn btn-primary">-</button>
<button onClick={del} type="submit" className="btn btn-primary">/</button>
<button onClick={pros} type="submit" className="btn btn-primary">*</button>
{outcome}
</form>
</div>
</main>
);
}

View 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>
);
}

View 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;
}
}

View File

@ -0,0 +1,43 @@
import React from 'react';
const EditReaderForm =(props) => {
const types = ([
{name:'Манга'},
{name:'Манхва'},
{name:'Маньхуа'},
])
function done(e) {
e.preventDefault();
// if (formRef.current.checkValidity()) {
// props.onDone();
// props.setModalEdit();
// props.setData({type:'', name:'', description:'' })
// }else {
// formRef.current.reportValidity();
// props.setData({type:'', name:'', description:'' })
// }
}
const formRef = React.createRef();
return (
<form id="frm-items" ref={formRef} className="row g-3 text-dark">
<div className="col-md-3 ">
</div>
<div className="col-sm-2">
<label htmlFor="readerName" className="form-label">readerName</label>
<input type='text' value = {props.readerName} onChange={event => props.setReaderName(event.target.value)} className="form-control"/>
</div>
<div className="col-sm-2">
<label htmlFor="password" className="form-label">password</label>
<input type='text' value = {props.password} onChange={event => props.setPassword(event.target.value)} className="form-control"/>
</div>
<div className="col-md-3">
<button onClick={() => props.update(item.id)} id="btn-add-item" className="btn btn-primary" type="submit">Изменить</button>
</div>
</form>
);
}
export default EditReaderForm

View File

@ -2,7 +2,7 @@ import { NavLink } from 'react-router-dom';
export default function Header(props) {
return (
<nav className="navbar navbar-expand-lg bg-light">
<nav className="navbar navbar-expand-lg navbar-dark">
<div className="container-fluid">
<button className="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"

View File

@ -0,0 +1,36 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../Table/TableCreator';
import MangaDto from "../../Dto/Manga-Dto";
export default function MangaCreatorList(props) {
return (
<div className="row table-responsive text-white">
{
props.creator.mangas?.map((manga) =>
<div key={manga.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
<div className="me-3">
<NavLink to={`/mangapage?id=${manga.id}`} ><img src={manga.image} alt={manga.mangaName} className="slideshow" /></NavLink>
</div>
<div>
<div className="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
<NavLink className="text-white fs-5 unic_class fw-bold pt-3 mb-3"
to={`/mangapage?id=${manga.id}`}>Название: {manga.mangaName}
</NavLink>
<p>Глав: {manga.chapterCount}</p>
</div>
<div>
<button type="button" className="btn btn-primary" onClick = {() => props.setMangaIdButton(manga.id)} data-bs-toggle="modal" data-bs-target="#exampleModal">
<i className="fas fa-edit"></i>
</button>
<button className="delete bg-danger p-2 px-2 mx-2 border border-0 rounded text-white fw-bold" onClick = {() => props.removeButton(manga.id)} type="button">Удалить</button>
</div>
</div>
</div>
)
}
</div>
);
}

View File

@ -0,0 +1,33 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../Table/TableCreator';
import MangaDto from "../../Dto/Manga-Dto";
export default function MangaReaderList(props) {
return (
<div className="row table-responsive text-white">
{
props.reader.mangas?.map((manga) =>
<div key={manga.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
<div className="me-3">
<NavLink to={`/mangapage?id=${manga.id}`} ><img src={manga.image} alt={manga.mangaName} className="slideshow" /></NavLink>
</div>
<div>
<div className="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
<NavLink className="text-white fs-5 unic_class fw-bold pt-3 mb-3"
to={`/mangapage?id=${manga.id}`}>Название: {manga.mangaName}
</NavLink>
<p>Глав: {manga.chapterCount}</p>
</div>
<div>
<button className="delete bg-danger p-2 px-2 mx-2 border border-0 rounded text-white fw-bold" onClick = {() => props.removeButton(manga.id)} type="button">Удалить</button>
</div>
</div>
</div>
)
}
</div>
);
}

View File

@ -0,0 +1,49 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../Table/TableCreator';
import MangaDto from "../../Dto/Manga-Dto";
export default function AddMangaModal(props) {
return (
<div className="modal fade text-black" id="exampleModal2" tabIndex="-1" aria-labelledby="exampleModalLabel2" aria-hidden="true">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalLabel2">Создание манги</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<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"/>
</div>
<div>
<label htmlFor="mangaName" className="form-label">mangaName</label>
<input type='text' value = {props.mangaName} onChange={event => props.setMangaName(event.target.value)} className="form-control"/>
</div>
<div>
<label
htmlFor="file-loader-button"
className="form-label">
Загрузить файл
</label>
<input
id="file-loader-button"
type="file"
className="form-control text-white"
onChange={props.handleOnChange}
/>
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" onClick={props.createButton} className="btn btn-primary" data-bs-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
);
}

View File

@ -0,0 +1,37 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../Table/TableCreator';
import MangaDto from "../../Dto/Manga-Dto";
export default function AddMangaReaderModal(props) {
return (
<div className="modal fade text-black" id="exampleModal2" tabIndex="-1" aria-labelledby="exampleModalLabel2" aria-hidden="true">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalLabel2">Добавление манги к читателю</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<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>
{
props.mangaData.map((mangaD) =>
<option key={mangaD.id} value={mangaD.id}>{mangaD.mangaName}</option>
)
}
</select>
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" onClick={props.addMangaButton} className="btn btn-primary" data-bs-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
);
}

View File

@ -0,0 +1,44 @@
import { useEffect, useState } from "react";
import { NavLink } from 'react-router-dom';
import TableCreator from '../Table/TableCreator';
import MangaDto from "../../Dto/Manga-Dto";
export default function EditMangaModal(props) {
return (
<div className="modal fade text-black" id="exampleModal" tabIndex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalLabel">Изменение манги</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<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"/>
</div>
<div>
<label
htmlFor="file-loader-button"
className="form-label">
Загрузить файл
</label>
<input
id="file-loader-button"
type="file"
className="form-control text-white"
onChange={props.handleOnChange}
/>
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" onClick={props.updateButton} className="btn btn-primary" data-bs-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
);
}

View 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

View 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;
}

View File

@ -12,7 +12,7 @@ export default function TableCreator(props) {
<td>{item.creatorName}</td>
<td>{item.hashedPassword}</td>
<td>
<select>{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>

View File

@ -1,20 +1,20 @@
import { useState } from 'react';
export default function TableCreator(props) {
export default function TableManga(props) {
return (
<tbody>
{
props.items.map((item, index) =>
<tr key={item.id}>
<tr key={item.id} >
<td>{item.id}</td>
<td>{item.mangaName}</td>
<td>{item.chapterCount}</td>
<td>{item.creatorId}</td>
<td>
<select>{item.readers.map(reader =>
<option key={reader}>{reader}</option>)}
<select className="form-select" aria-label="Default select example">{item.readers.map(reader =>
<option key={reader.id}>{reader.readerName}</option>)}
</select>
</td>
</tr>

View File

@ -6,15 +6,18 @@ 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>{item.mangas.map(manga =>
<option key={manga}>{manga}</option>)}
<select className="form-select" aria-label="Default select example">{item.mangas.map(manga =>
<option key={manga.id}>{manga.mangaName}</option>)}
</select>
</td>
<td>
<button onClick={() => props.remove(item.id)} className="btn btn-success">Удалить</button>
</td>
</tr>
)

View File

@ -1,4 +1,4 @@
/* html,
html,
body {
background-color: #000000;
color: #ffffff;
@ -31,9 +31,7 @@ article a {
header a:hover {
text-decoration: underline;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.25em;
}
@ -99,4 +97,11 @@ th {
.registration_div {
width: 100%;
height: 100%;
} */
}
.slideshow{
height: 250px;
width: auto;/*maintain aspect ratio*/
max-width:180px;
border-radius: 7%;
}

View File

@ -4,6 +4,7 @@ package com.LabWork.app.MangaStore.controller;
import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto;
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import com.LabWork.app.MangaStore.service.MangaService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -28,22 +29,32 @@ public class MangaController {
.map(x -> new MangaReaderDto(x, mangaService.getReader(x.getId())))
.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}")
/* @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) {
return new MangaDto(mangaService.deleteManga(id));
}
@PostMapping
public MangaDto createManga(@RequestBody @Valid MangaDto mangaDto) {
return new MangaDto(mangaService.addManga(mangaDto));
}
@PutMapping("/{id}")
public MangaDto updateManga(@RequestBody @Valid MangaDto mangaDto) {
return new MangaDto(mangaService.updateManga(mangaDto));
}
}

View File

@ -2,6 +2,7 @@ package com.LabWork.app.MangaStore.controller;
import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto;
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import com.LabWork.app.MangaStore.service.ReaderService;
import org.springframework.web.bind.annotation.*;
@ -42,15 +43,15 @@ public class ReaderController {
}
@PutMapping("/{id}/addManga")
public ReaderMangaDto addManga(@PathVariable Long id,
@RequestParam("mangaId") Long mangaId) {
return new ReaderMangaDto(readerService.addManga(mangaId, id));
public MangaDto addManga(@PathVariable Long id,
@RequestParam("mangaId") Long mangaId) {
return new MangaDto(readerService.addManga(mangaId, id));
}
@PutMapping("/{id}/removeManga")
public ReaderMangaDto removeManga(@PathVariable Long id,
public MangaDto removeManga(@PathVariable Long id,
@RequestParam("mangaId") Long mangaId) {
return new ReaderMangaDto(readerService.removeManga(mangaId, id));
return new MangaDto(readerService.removeManga(mangaId, id));
}
@DeleteMapping("/{id}")

View File

@ -1,5 +1,6 @@
package com.LabWork.app.MangaStore.model.Default;
import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import com.LabWork.app.MangaStore.service.CreatorService;
import com.LabWork.app.MangaStore.service.MangaService;
import jakarta.persistence.*;
@ -24,13 +25,34 @@ public class Manga {
@JoinColumn(name="creator_fk")
private Creator creator;
private Long creatorId;
@Lob
private byte[] image;
public Manga() {
}
public Manga(Creator creator, String mangaName, Integer chapterCount) {
this.creator = creator;
this.creatorId = creatorId;
this.mangaName = mangaName;
this.chapterCount = chapterCount;
this.image = image;
}
public Manga(Creator creator, MangaDto mangaDto) {
this.creator = creator;
this.mangaName = mangaDto.getMangaName();
this.chapterCount = mangaDto.getChapterCount();
this.image = mangaDto.getImage().getBytes();
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public Long getId() {

View File

@ -5,6 +5,7 @@ import com.LabWork.app.MangaStore.model.Default.Manga;
import com.LabWork.app.MangaStore.model.Default.Reader;
import com.LabWork.app.MangaStore.model.Dto.SupportDto.ReaderDto;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class MangaReaderDto {
@ -13,14 +14,15 @@ public class MangaReaderDto {
private final Long creatorId;
private final String mangaName;
private final Integer chapterCount;
private final List<ReaderDto> readers;
private String image;
public MangaReaderDto(Manga manga, List<Reader> listReader) {
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 = listReader.stream()
.map(y -> new ReaderDto(y))
.toList();
@ -30,6 +32,10 @@ public class MangaReaderDto {
return id;
}
public String getImage() {
return image;
}
public String getMangaName() {
return mangaName;
}

View File

@ -1,24 +1,29 @@
package com.LabWork.app.MangaStore.model.Dto.SupportDto;
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 java.nio.charset.StandardCharsets;
import java.util.List;
public class MangaDto {
private final Long id;
private final Long creatorId;
private final String mangaName;
private final Integer chapterCount;
private Long id;
private Long creatorId;
private String mangaName;
private Integer chapterCount;
private String image;
public MangaDto(Manga manga) {
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);
}
public MangaDto() {
}
public Long getId() {
return id;
}
@ -35,4 +40,8 @@ public class MangaDto {
return creatorId;
}
public String getImage() {
return image;
}
}

View File

@ -3,6 +3,7 @@ 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.Repository.CreatorRepository;
import com.LabWork.app.MangaStore.service.Repository.MangaRepository;
import com.LabWork.app.MangaStore.service.Exception.CreatorNotFoundException;
@ -75,12 +76,31 @@ public class MangaService {
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) {
final Manga currentManga = findManga(id);
currentManga.setChapterCount(chapterCount);
validatorUtil.validate(currentManga);
return mangaRepository.save(currentManga);
mangaRepository.save(currentManga);
return currentManga;
}
@Transactional
public Manga updateManga(MangaDto mangaDto) {
final Manga currentManga = findManga(mangaDto.getId());
currentManga.setChapterCount(mangaDto.getChapterCount());
currentManga.setImage(mangaDto.getImage().getBytes());
validatorUtil.validate(currentManga);
mangaRepository.save(currentManga);
return currentManga;
}
@Transactional

View File

@ -53,7 +53,7 @@ public class ReaderService {
//СКОРЕЕ ВСЕГО НЕ БУДЕТ РАБОТАТЬ
@Transactional
public Reader addManga(Long mangaId, Long readerId) {
public Manga addManga(Long mangaId, Long readerId) {
final Manga manga = findManga(mangaId);
final Reader reader = findReader(readerId);
validatorUtil.validate(reader);
@ -62,19 +62,21 @@ public class ReaderService {
return null;
}
reader.getMangas().add(manga);
readerRepository.save(reader);
/* manga.getReaders().add(reader);*/
return readerRepository.save(reader);
return manga;
}
@Transactional
public Reader removeManga(Long mangaId, Long readerId) {
public Manga removeManga(Long mangaId, Long readerId) {
//em.createNativeQuery("delete from Mangas_Readers where MANGA_FK = " + manga.getId() + " AND READER_FK = "+ readerId).executeUpdate();
final Reader currentReader = findReader(readerId);
final Manga currentManga = findManga(mangaId);
currentReader.getMangas().remove(currentManga);
/* currentManga.getReaders().remove(currentReader);*/
mangaRepository.save(currentManga);
return readerRepository.save(currentReader);
readerRepository.save(currentReader);
return currentManga;
}
@Transactional

View File

@ -1,7 +1,13 @@
package com.LabWork.app;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@ -10,4 +16,18 @@ public class WebConfiguration implements WebMvcConfigurer {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/notFound").setViewName("forward:/index.html");
}
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
return container -> {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
"/notFound"));
};
}
}