Вроде бы всё работает, кроме запуска фронта через gradle
This commit is contained in:
parent
ef720bbc01
commit
4c199c456b
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
71
frontend/Mangs.html
Normal file
71
frontend/Mangs.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<title>Mangs</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" id="root-div">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="index.html">Creator</a>
|
||||
<a class="nav-link" href="Mangs.html">Manga</a>
|
||||
<a class="nav-link" href="Readers.html">Reader</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<h1>Manga</h1>
|
||||
<form id="form">
|
||||
<div class="d-flex justify-content-evenly mt-3">
|
||||
<div class="col-sm-2">
|
||||
<label for="mangaId" class="form-label">mangaId</label>
|
||||
<input type="number" class="form-control" value="0" id="mangaId" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="mangaName" class="form-label">mangaName</label>
|
||||
<input type="text" class="form-control" value="0" id="mangaName" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="chapterCount" class="form-label">chapterCount</label>
|
||||
<input type="number" class="form-control" value="0" id="chapterCount" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="creatorId" class="form-label">creatorId</label>
|
||||
<input type="number" class="form-control" id="creatorId" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Добавить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button type="submit" class="btn btn-success" id="btnUpdate" >Обновить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button id="btnRemove" class="btn btn-success">Удалить</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row table-responsive">
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">mangaName</th>
|
||||
<th scope="col">chapterCount</th>
|
||||
<th scope="col">creatorId</th>
|
||||
<th scope="col">readers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="scriptManga.js"></script>
|
||||
</body>
|
||||
</html>
|
76
frontend/Readers.html
Normal file
76
frontend/Readers.html
Normal file
@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<title>Readers</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" id="root-div">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="index.html">Creator</a>
|
||||
<a class="nav-link" href="Mangs.html">Manga</a>
|
||||
<a class="nav-link" href="Readers.html">Reader</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<h1>Reader</h1>
|
||||
<form id="form">
|
||||
<div class="d-flex justify-content-evenly mt-3">
|
||||
<div class="col-sm-2">
|
||||
<label for="readerId" class="form-label">readerId</label>
|
||||
<input type="number" class="form-control" value="0" id="readerId" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="mangaId" class="form-label">mangaId</label>
|
||||
<input type="number" class="form-control" value="0" id="mangaId" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="readerName" class="form-label">readerName</label>
|
||||
<input type="text" class="form-control" value="0" id="readerName" />
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="hashedPassword" class="form-label">hashedPassword</label>
|
||||
<input type="text" class="form-control" value="0" id="hashedPassword" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-2 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Добавить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-2 mx-auto">
|
||||
<button type="submit" class="btn btn-success" id="btnUpdate" >Обновить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-2 mx-auto">
|
||||
<button id="btnRemove" class="btn btn-success">Удалить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-2 mx-auto">
|
||||
<button id="btnRemoveManga" class="btn btn-success">Удалить мангу</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-2 mx-auto">
|
||||
<button id="btnAddManga" type="submit" class="btn btn-success">Добавить мангу</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row table-responsive">
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">readerName</th>
|
||||
<th scope="col">hashedPassword</th>
|
||||
<th scope="col">mangs</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="scriptReader.js"></script>
|
||||
</body>
|
||||
</html>
|
58
frontend/build.gradle
Normal file
58
frontend/build.gradle
Normal file
@ -0,0 +1,58 @@
|
||||
import com.github.gradle.node.util.PlatformHelper
|
||||
import groovy.text.SimpleTemplateEngine
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.node-gradle.node' version '3.5.1'
|
||||
id "de.undercouch.download" version '5.3.1'
|
||||
}
|
||||
|
||||
node {
|
||||
version = '18.15.0'
|
||||
download = true
|
||||
}
|
||||
|
||||
jar.dependsOn 'npmBuild'
|
||||
|
||||
clean.dependsOn 'npmClean'
|
||||
|
||||
nodeSetup.dependsOn 'downloadNode'
|
||||
|
||||
jar {
|
||||
from 'dist'
|
||||
into 'static'
|
||||
final devHost = 'http://localhost:8080'
|
||||
final prodHost = ''
|
||||
filesMatching('index.html') {
|
||||
filter { line -> line.replaceAll(devHost, prodHost) }
|
||||
}
|
||||
}
|
||||
|
||||
task downloadNode(type: Download) {
|
||||
final helper = new PlatformHelper()
|
||||
final templateData = [
|
||||
"url" : node.distBaseUrl.get(),
|
||||
"version": node.version.get(),
|
||||
"os" : helper.osName,
|
||||
"arch" : helper.osArch,
|
||||
"ext" : helper.windows ? 'zip' : 'tar.gz'
|
||||
]
|
||||
final urlTemplate = '${url}/v${version}/node-v${version}-${os}-${arch}.${ext}'
|
||||
final engine = new SimpleTemplateEngine()
|
||||
final url = engine.createTemplate(urlTemplate).make(templateData).toString()
|
||||
final String destDir = '.gradle/'
|
||||
file(destDir).mkdirs()
|
||||
src url
|
||||
dest destDir
|
||||
overwrite false
|
||||
}
|
||||
|
||||
tasks.register('npmBuild', NpmTask) {
|
||||
dependsOn npmInstall
|
||||
args = ['run-script', 'build']
|
||||
}
|
||||
|
||||
tasks.register('npmClean', NpmTask) {
|
||||
dependsOn npmInstall
|
||||
args = ['run-script', 'clean']
|
||||
}
|
@ -1,27 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="node_modules/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet" />
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<title>Main</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root-div">
|
||||
<header>
|
||||
<div>
|
||||
<a href="catalog.html" class="text-white">Creator</a>
|
||||
<a href="search.html" class="text-white">Manga</a>
|
||||
<a href="search.html" class="text-white">Reader</a>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container" id="root-div">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="index.html">Creator</a>
|
||||
<a class="nav-link" href="Mangs.html">Manga</a>
|
||||
<a class="nav-link" href="Readers.html">Reader</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<h1>Creator</h1>
|
||||
<form id="calculator-form">
|
||||
<form id="form">
|
||||
<div class="d-flex justify-content-evenly mt-3">
|
||||
<div class="col-sm-2">
|
||||
<label for="creatorId" class="form-label">creatorId</label>
|
||||
@ -37,29 +34,32 @@
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label for="password" class="form-label">password</label>
|
||||
<input type="text" readonly class="form-control" id="password" />
|
||||
</div>
|
||||
|
||||
<input type="text" class="form-control" id="password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="ms-5 me-5">
|
||||
<label for="operation" class="form-label">Operation</label>
|
||||
<select class="form-select" id="operation">
|
||||
<option value="getCreator">find</option>
|
||||
<option value="string">dinfAll</option>
|
||||
<option value="int">create</option>
|
||||
<option value="string">update</option>
|
||||
<option value="int">delete</option>
|
||||
</select>
|
||||
<button type="button" class="mt-3 btn btn-primary" id="apply-button">APPLY</button>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-3 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Добавить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-3 mx-auto">
|
||||
<button type="submit" class="btn btn-success" id="btnUpdate" >Обновить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-3 mx-auto">
|
||||
<button id="btnRemove" class="btn btn-success">Удалить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-3 mx-auto">
|
||||
<button id="btnRemoveAll" class="btn btn-success">Удалить всё</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row table-responsive">
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">creatorName</th>
|
||||
<th scope="col">password</th>
|
||||
<th scope="col">CreatorName</th>
|
||||
<th scope="col">Password</th>
|
||||
<th scope="col">Mangs</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
@ -68,6 +68,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
<script src="scriptCreator.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
127
frontend/scriptCreator.js
Normal file
127
frontend/scriptCreator.js
Normal file
@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
const host = "http://localhost:8080";
|
||||
const table = document.getElementById("tbody");
|
||||
const form = document.getElementById("form");
|
||||
const creatorIdInput = document.getElementById("creatorId");
|
||||
const mangaIdInput = document.getElementById("mangaId");
|
||||
const creatorNameInput = document.getElementById("creatorName");
|
||||
const passwordInput = document.getElementById("password");
|
||||
const buttonRemove = document.getElementById("btnRemove");
|
||||
const buttonUpdate = document.getElementById("btnUpdate");btnRemoveAll
|
||||
const buttonRemoveAll = document.getElementById("btnRemoveAll");
|
||||
const getData = async function () {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/creator");
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
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 (creatorName, password) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/creator?creatorName=${creatorName}&password=${password}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const remove = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (creatorIdInput.value !== 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 + `/creator/` + creatorIdInput.value, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const removeAll = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (!confirm('Do you really want to remove this item?')) {
|
||||
console.info('Canceled');
|
||||
return;
|
||||
}
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
};
|
||||
await fetch(host + `/creator/`, requestParams);
|
||||
}
|
||||
|
||||
const update = async function (){
|
||||
console.info('Try to update item');
|
||||
if (creatorIdInput.value === 0 || creatorNameInput.value == null || passwordInput.value === 0) {
|
||||
return;
|
||||
}
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/creator/${creatorIdInput.value}?creatorName=${creatorNameInput.value}&password=${passwordInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
buttonRemove.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
remove().then((result) => {
|
||||
getData()
|
||||
creatorIdInput.value = "";
|
||||
});
|
||||
});
|
||||
buttonRemoveAll.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
removeAll().then(() => {
|
||||
getData()
|
||||
});
|
||||
});
|
||||
|
||||
buttonUpdate.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
update().then((result) => {
|
||||
getData()
|
||||
creatorIdInput.value = "";
|
||||
passwordInput.value = "";
|
||||
creatorNameInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
create(creatorNameInput.value, passwordInput.value).then((result) => {
|
||||
getData();
|
||||
creatorNameInput.value = "";
|
||||
passwordInput.value = "";
|
||||
console.log(result);
|
||||
alert(`Creator[id=${result.id}, creatorNameInput=${result.creatorName}, passwordInput=${result.hashedPassword}]`);
|
||||
});
|
||||
});
|
||||
|
||||
getData();
|
||||
});
|
112
frontend/scriptManga.js
Normal file
112
frontend/scriptManga.js
Normal file
@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
const host = "http://localhost:8080";
|
||||
const table = document.getElementById("tbody");
|
||||
const form = document.getElementById("form");
|
||||
const creatorIdInput = document.getElementById("creatorId");
|
||||
const mangaIdInput = document.getElementById("mangaId");
|
||||
const mangaNameInput = document.getElementById("mangaName");
|
||||
const chapterCountInput = document.getElementById("chapterCount");
|
||||
const buttonRemove = document.getElementById("btnRemove");
|
||||
const buttonUpdate = document.getElementById("btnUpdate");
|
||||
const getData = async function () {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/manga");
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
data.forEach(Manga => {
|
||||
let temp = "<select>";
|
||||
Manga.readers.forEach(String => {
|
||||
temp += `<option>${String}</option>>`
|
||||
})
|
||||
temp += "</select>"
|
||||
table.innerHTML +=
|
||||
`<tr>
|
||||
<th scope="row" id="componentId">${Manga.id}</th>
|
||||
<td>${Manga.mangaName}</td>
|
||||
<td>${Manga.chapterCount}</td>
|
||||
<td>${Manga.creatorId}</td>
|
||||
<td>${temp}</td>
|
||||
</tr>`;
|
||||
})
|
||||
}
|
||||
|
||||
const create = async function (creatorId, chapterCount, mangaName) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
console.log(creatorId);
|
||||
console.log(chapterCount);
|
||||
console.log(mangaName);
|
||||
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 (mangaIdInput.value !== 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);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const update = async function (){
|
||||
console.info('Try to update item');
|
||||
if (mangaIdInput.value === 0 || chapterCountInput.value === null) {
|
||||
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();
|
||||
}
|
||||
|
||||
buttonRemove.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
remove().then((result) => {
|
||||
getData()
|
||||
mangaIdInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
buttonUpdate.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
update().then((result) => {
|
||||
getData()
|
||||
mangaIdInput.value = "";
|
||||
chapterCountInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
create(creatorIdInput.value, chapterCountInput.value, mangaNameInput.value).then((result) => {
|
||||
getData();
|
||||
mangaIdInput.value = "";
|
||||
creatorIdInput.value = "";
|
||||
chapterCountInput.value = "";
|
||||
mangaNameInput.value = "";
|
||||
alert(`Manga[id=${result.id}, mangaName=${result.mangaName}, chapterCount=${result.chapterCount}, chapterCount=${result.chapterCount}]`);
|
||||
});
|
||||
});
|
||||
|
||||
getData();
|
||||
});
|
158
frontend/scriptReader.js
Normal file
158
frontend/scriptReader.js
Normal file
@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
const host = "http://localhost:8080";
|
||||
const table = document.getElementById("tbody");
|
||||
const form = document.getElementById("form");
|
||||
const readerIdInput = document.getElementById("readerId");
|
||||
const mangaIdInput = document.getElementById("mangaId");
|
||||
const readerNameInput = document.getElementById("readerName");
|
||||
const hashedPasswordInput = document.getElementById("hashedPassword");
|
||||
const buttonRemove = document.getElementById("btnRemove");
|
||||
const buttonUpdate = document.getElementById("btnUpdate");
|
||||
const buttonRemoveManga = document.getElementById("btnRemoveManga");
|
||||
const buttonAddManga = document.getElementById("btnAddManga");
|
||||
const getData = async function () {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/reader");
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
data.forEach(Reader => {
|
||||
let temp = "<select>";
|
||||
Reader.mangas.forEach(String => {
|
||||
temp += `<option>${String}</option>>`
|
||||
})
|
||||
temp += "</select>"
|
||||
table.innerHTML +=
|
||||
`<tr>
|
||||
<th scope="row" id="componentId">${Reader.id}</th>
|
||||
<td>${Reader.readerName}</td>
|
||||
<td>${Reader.hashedPassword}</td>
|
||||
<td>${temp}</td>
|
||||
</tr>`;
|
||||
})
|
||||
}
|
||||
|
||||
const create = async function (readerName, hashedPassword) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
console.log(host + `/reader?readerName=${readerName}&password=${hashedPassword}`, requestParams);
|
||||
console.log(readerName);
|
||||
const response = await fetch(host + `/reader?readerName=${readerName}&password=${hashedPassword}`, requestParams);
|
||||
console.log(readerName);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const addManga = async function () {
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
console.log(host + `/reader/${readerIdInput.value}/addManga?mangaId=${mangaIdInput.value}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${readerIdInput.value}/addManga?mangaId=${mangaIdInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const remove = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (readerIdInput.value !== 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 + `/reader/` + readerIdInput.value, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const removeManga = async function (){
|
||||
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/${readerIdInput.value}/removeManga?mangaId=${mangaIdInput.value}`, requestParams);
|
||||
const response = await fetch(host + `/reader/${readerIdInput.value}/removeManga?mangaId=${mangaIdInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const update = async function (){
|
||||
console.info('Try to update item');
|
||||
if (readerIdInput.value === 0 || hashedPasswordInput.value === null) {
|
||||
return;
|
||||
}
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/reader/${readerIdInput.value}?readerName=${readerNameInput.value}&password=${hashedPasswordInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
buttonRemove.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
remove().then((result) => {
|
||||
getData()
|
||||
readerIdInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
buttonRemoveManga.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
removeManga().then((result) => {
|
||||
getData()
|
||||
mangaIdInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
buttonAddManga.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
addManga().then((result) => {
|
||||
getData()
|
||||
mangaIdInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
buttonUpdate.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
update().then((result) => {
|
||||
getData()
|
||||
readerIdInput.value = "";
|
||||
hashedPasswordInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
console.log(readerNameInput.value);
|
||||
create(readerNameInput.value, hashedPasswordInput.value).then((result) => {
|
||||
console.log(readerNameInput.value);
|
||||
getData();
|
||||
hashedPasswordInput.value = "";
|
||||
readerIdInput.value = "";
|
||||
alert(`Reader[id=${result.id}, readerName=${result.readerName}, password=${result.hashedPassword}]`);
|
||||
});
|
||||
});
|
||||
|
||||
getData();
|
||||
});
|
@ -42,6 +42,12 @@ public class CreatorController {
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public CreatorDto deleteCreator(@PathVariable Long id) {
|
||||
//creatorService.deleteAllCreators();
|
||||
return new CreatorDto(creatorService.deleteCreator(id));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public void deleteAllCreator() {
|
||||
creatorService.deleteAllCreators();
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class MangaController {
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public MangaDto updateManga(@PathVariable Long id,
|
||||
@RequestParam("chapterCount") Integer chapterCount) {
|
||||
@RequestParam("chapterCount") Integer chapterCount) {
|
||||
return new MangaDto(mangaService.updateManga(id, chapterCount));
|
||||
}
|
||||
|
||||
|
@ -41,15 +41,15 @@ public class ReaderController {
|
||||
return new ReaderDto(readerService.updateReader(id, readerName, password));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/manga/{manga_id}")
|
||||
@PutMapping("/{id}/addManga")
|
||||
public ReaderDto addManga(@PathVariable Long id,
|
||||
@PathVariable Long mangaId) {
|
||||
@RequestParam("mangaId") Long mangaId) {
|
||||
return new ReaderDto(readerService.addManga(mangaId, id));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/manga/{manga_id}")
|
||||
@PutMapping("/{id}/removeManga")
|
||||
public ReaderDto removeManga(@PathVariable Long id,
|
||||
@PathVariable Long mangaId) {
|
||||
@RequestParam("mangaId") Long mangaId) {
|
||||
return new ReaderDto(readerService.removeManga(mangaId, id));
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,10 @@ public class Manga {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getCreatorId() {
|
||||
return creator.getId();
|
||||
}
|
||||
|
||||
public String getMangaName() {
|
||||
return mangaName;
|
||||
}
|
||||
|
@ -3,18 +3,21 @@ package com.LabWork.app.MangaStore.model.Dto;
|
||||
import com.LabWork.app.MangaStore.model.Default.Creator;
|
||||
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CreatorDto {
|
||||
private final long id;
|
||||
private final String creatorName;
|
||||
private final String hashedPassword;
|
||||
private final List<Manga> mangas;
|
||||
private final List<MangaDto> mangas;
|
||||
|
||||
public CreatorDto(Creator creator) {
|
||||
this.id = creator.getId();
|
||||
this.creatorName = creator.getCreatorName();
|
||||
this.hashedPassword = creator.getHashedPassword();
|
||||
this.mangas = creator.getMangas();
|
||||
this.mangas = creator.getMangas().stream()
|
||||
.map(y -> new MangaDto(y))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
@ -29,5 +32,5 @@ public class CreatorDto {
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
public List<Manga> getMangas() { return mangas; }
|
||||
public List<MangaDto> getMangas() { return mangas; }
|
||||
}
|
||||
|
@ -4,23 +4,26 @@ 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.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MangaDto {
|
||||
|
||||
private final Long id;
|
||||
|
||||
private final Creator creator;
|
||||
private final Long creatorId;
|
||||
private final String mangaName;
|
||||
private final Integer chapterCount;
|
||||
|
||||
private final List<Reader> readers;
|
||||
private final List<String> readers;
|
||||
|
||||
public MangaDto(Manga manga) {
|
||||
this.id = manga.getId();
|
||||
this.creator = manga.getCreator();
|
||||
this.creatorId = manga.getCreator().getId();
|
||||
this.mangaName = manga.getMangaName();
|
||||
this.chapterCount = manga.getChapterCount();
|
||||
this.readers = manga.getReaders();
|
||||
this.readers = manga.getReaders().stream()
|
||||
.map(y -> new String(y.getReaderName()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@ -35,11 +38,11 @@ public class MangaDto {
|
||||
return chapterCount;
|
||||
}
|
||||
|
||||
public Creator getCreator() {
|
||||
return creator;
|
||||
public Long getCreatorId() {
|
||||
return creatorId;
|
||||
}
|
||||
|
||||
public List<Reader> getReaders() {
|
||||
public List<String> getReaders() {
|
||||
return readers;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.LabWork.app.MangaStore.model.Dto;
|
||||
import com.LabWork.app.MangaStore.model.Default.Manga;
|
||||
import com.LabWork.app.MangaStore.model.Default.Reader;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ReaderDto {
|
||||
private Long id;
|
||||
@ -11,13 +12,15 @@ public class ReaderDto {
|
||||
|
||||
private String hashedPassword;
|
||||
|
||||
private List<Manga> mangas;
|
||||
private List<String> mangas;
|
||||
|
||||
public ReaderDto(Reader reader) {
|
||||
this.id = reader.getId();
|
||||
this.readerName = reader.getReaderName();
|
||||
this.hashedPassword = reader.getHashedPassword();
|
||||
this.mangas = reader.getMangas();
|
||||
this.mangas = reader.getMangas().stream()
|
||||
.map(y -> new String(y.getMangaName()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@ -28,6 +31,6 @@ public class ReaderDto {
|
||||
|
||||
public String getHashedPassword() { return hashedPassword; }
|
||||
|
||||
public List<Manga> getMangas() { return mangas; }
|
||||
public List<String> getMangas() { return mangas; }
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,22 @@ public class ReMangaTest {
|
||||
creatorService.deleteAllCreators();
|
||||
}
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
readerService.deleteAllReaders();
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
Creator c1 = creatorService.addCreator("first", "1");
|
||||
Manga m1 = mangaService.addManga(c1.getId(), 0, "Vagabond");
|
||||
Manga m2 = mangaService.addManga(c1.getId(), 10, "Berserk");
|
||||
Manga m3 = mangaService.addManga(c1.getId(), 0, "Manga_3");
|
||||
Creator c2 = creatorService.findCreator(c1.getId());
|
||||
Assertions.assertEquals(3, c2.getMangas().size());
|
||||
readerService.deleteAllReaders();
|
||||
mangaService.deleteAllMangas();
|
||||
creatorService.deleteAllCreators();
|
||||
}
|
||||
|
||||
/* @Test
|
||||
void testCreatorAddManga() {
|
||||
readerService.deleteAllReaders();
|
||||
|
Loading…
Reference in New Issue
Block a user