Compare commits

...

13 Commits
main ... Lab5

Author SHA1 Message Date
60e6468423 сдано 2023-11-17 13:56:52 +04:00
40b56f7a59 да 2023-11-07 13:58:47 +04:00
deff0f7ff8 да 2023-11-07 13:43:07 +04:00
99b608e040 да 2023-11-07 13:36:13 +04:00
e4af02f2fe задаток на 5 лабу 2023-05-25 16:14:28 +04:00
dcff548ad8 задаток на 5 лабу 2023-05-25 15:38:06 +04:00
adac7867ab готово 2023-05-25 14:31:51 +04:00
de1f5ddfc2 задаток на 4 лабу 2023-05-25 13:40:51 +04:00
6e8c28b683 готово 2023-05-02 18:17:05 +04:00
Katerina881
35c2527b01 я того его сё 2023-05-02 15:20:13 +04:00
46dbd68eaf надо сделать на своё 2023-05-02 11:07:59 +04:00
99ddd9817c задаток на 4 лабу 2023-04-18 14:40:19 +04:00
c25bac19dd lab3 2023-03-21 12:50:56 +04:00
76 changed files with 4733 additions and 916 deletions

View File

@ -1,40 +0,0 @@
<!doctype html>
<html lang="en">
<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 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"/>
<title>Document</title>
</head>
<body>
<form id="frm-items" class="row g-3">
<div class="d-flex flex-column w-25 my-5 mx-3">
Введите первое число
<input id="first"></input>
Введите второе число
<input id="second"></input>
Выберите операцию
<div>
<button type="button" class="btn btn-primary" id="buttonPlus">+</button>
<button type="button" class="btn btn-primary" id="buttonMinus">-</button>
<button type="button" class="btn btn-primary" id="buttonMulti">*</button>
<button type="button" class="btn btn-primary" id="buttonDiv">/</button>
</div>
Выберите тип данных
<div>
<select id="type" class="form-select" >
<option value="int">Число</option>
<option value="string">Строка</option>
</select>
</div>
Результат
<input id="res" type="text"/>
</div>
</form>
<script src="/script.js"></script>
</body>
</html>

814
Front/package-lock.json generated
View File

@ -1,814 +0,0 @@
{
"name": "int-prog",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "int-prog",
"version": "1.0.0",
"dependencies": {
"@fortawesome/fontawesome-free": "6.2.0",
"bootstrap": "5.2.1"
},
"devDependencies": {
"http-server": "14.1.1"
}
},
"node_modules/@fortawesome/fontawesome-free": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.2.0.tgz",
"integrity": "sha512-CNR7qRIfCwWHNN7FnKUniva94edPdyQzil/zCwk3v6k4R6rR2Fr8i4s3PM7n/lyfPA6Zfko9z5WDzFxG9SW1uQ==",
"hasInstallScript": true,
"engines": {
"node": ">=6"
}
},
"node_modules/@popperjs/core": {
"version": "2.11.6",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz",
"integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==",
"peer": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/popperjs"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/async": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
"dev": true,
"dependencies": {
"lodash": "^4.17.14"
}
},
"node_modules/basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"dev": true,
"dependencies": {
"safe-buffer": "5.1.2"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/bootstrap": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.1.tgz",
"integrity": "sha512-UQi3v2NpVPEi1n35dmRRzBJFlgvWHYwyem6yHhuT6afYF+sziEt46McRbT//kVXZ7b1YUYEVGdXEH74Nx3xzGA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/twbs"
},
{
"type": "opencollective",
"url": "https://opencollective.com/bootstrap"
}
],
"peerDependencies": {
"@popperjs/core": "^2.11.6"
}
},
"node_modules/call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/corser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz",
"integrity": "sha512-utCYNzRSQIZNPIcGZdQc92UVJYAhtGAteCFg0yRaFm8f0P+CPtyGyHXJcGXnffjCybUCEx3FQ2G7U3/o9eIkVQ==",
"dev": true,
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dev": true,
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==",
"dev": true
},
"node_modules/follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true,
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"node_modules/get-intrinsic": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",
"integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.3"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.1"
},
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"dev": true,
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true,
"bin": {
"he": "bin/he"
}
},
"node_modules/html-encoding-sniffer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz",
"integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==",
"dev": true,
"dependencies": {
"whatwg-encoding": "^2.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/http-proxy": {
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
"integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
"dev": true,
"dependencies": {
"eventemitter3": "^4.0.0",
"follow-redirects": "^1.0.0",
"requires-port": "^1.0.0"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/http-server": {
"version": "14.1.1",
"resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz",
"integrity": "sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A==",
"dev": true,
"dependencies": {
"basic-auth": "^2.0.1",
"chalk": "^4.1.2",
"corser": "^2.0.1",
"he": "^1.2.0",
"html-encoding-sniffer": "^3.0.0",
"http-proxy": "^1.18.1",
"mime": "^1.6.0",
"minimist": "^1.2.6",
"opener": "^1.5.1",
"portfinder": "^1.0.28",
"secure-compare": "3.0.1",
"union": "~0.5.0",
"url-join": "^4.0.1"
},
"bin": {
"http-server": "bin/http-server"
},
"engines": {
"node": ">=12"
}
},
"node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"dev": true,
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/minimist": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"node_modules/mkdirp": {
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
"dev": true,
"dependencies": {
"minimist": "^1.2.6"
},
"bin": {
"mkdirp": "bin/cmd.js"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
},
"node_modules/object-inspect": {
"version": "1.12.2",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
"integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==",
"dev": true,
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/opener": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz",
"integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==",
"dev": true,
"bin": {
"opener": "bin/opener-bin.js"
}
},
"node_modules/portfinder": {
"version": "1.0.32",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.32.tgz",
"integrity": "sha512-on2ZJVVDXRADWE6jnQaX0ioEylzgBpQk8r55NE4wjXW1ZxO+BgDlY6DXwj20i0V8eB4SenDQ00WEaxfiIQPcxg==",
"dev": true,
"dependencies": {
"async": "^2.6.4",
"debug": "^3.2.7",
"mkdirp": "^0.5.6"
},
"engines": {
"node": ">= 0.12.0"
}
},
"node_modules/qs": {
"version": "6.11.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
"dev": true,
"dependencies": {
"side-channel": "^1.0.4"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==",
"dev": true
},
"node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
},
"node_modules/secure-compare": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/secure-compare/-/secure-compare-3.0.1.tgz",
"integrity": "sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==",
"dev": true
},
"node_modules/side-channel": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
"dev": true,
"dependencies": {
"call-bind": "^1.0.0",
"get-intrinsic": "^1.0.2",
"object-inspect": "^1.9.0"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/union": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz",
"integrity": "sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==",
"dev": true,
"dependencies": {
"qs": "^6.4.0"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/url-join": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==",
"dev": true
},
"node_modules/whatwg-encoding": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz",
"integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==",
"dev": true,
"dependencies": {
"iconv-lite": "0.6.3"
},
"engines": {
"node": ">=12"
}
}
},
"dependencies": {
"@fortawesome/fontawesome-free": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.2.0.tgz",
"integrity": "sha512-CNR7qRIfCwWHNN7FnKUniva94edPdyQzil/zCwk3v6k4R6rR2Fr8i4s3PM7n/lyfPA6Zfko9z5WDzFxG9SW1uQ=="
},
"@popperjs/core": {
"version": "2.11.6",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz",
"integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==",
"peer": true
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"async": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
"dev": true,
"requires": {
"lodash": "^4.17.14"
}
},
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"dev": true,
"requires": {
"safe-buffer": "5.1.2"
}
},
"bootstrap": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.1.tgz",
"integrity": "sha512-UQi3v2NpVPEi1n35dmRRzBJFlgvWHYwyem6yHhuT6afYF+sziEt46McRbT//kVXZ7b1YUYEVGdXEH74Nx3xzGA==",
"requires": {}
},
"call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"corser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz",
"integrity": "sha512-utCYNzRSQIZNPIcGZdQc92UVJYAhtGAteCFg0yRaFm8f0P+CPtyGyHXJcGXnffjCybUCEx3FQ2G7U3/o9eIkVQ==",
"dev": true
},
"debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dev": true,
"requires": {
"ms": "^2.1.1"
}
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==",
"dev": true
},
"follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"get-intrinsic": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",
"integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.3"
}
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"requires": {
"function-bind": "^1.1.1"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"dev": true
},
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true
},
"html-encoding-sniffer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz",
"integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==",
"dev": true,
"requires": {
"whatwg-encoding": "^2.0.0"
}
},
"http-proxy": {
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
"integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
"dev": true,
"requires": {
"eventemitter3": "^4.0.0",
"follow-redirects": "^1.0.0",
"requires-port": "^1.0.0"
}
},
"http-server": {
"version": "14.1.1",
"resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz",
"integrity": "sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A==",
"dev": true,
"requires": {
"basic-auth": "^2.0.1",
"chalk": "^4.1.2",
"corser": "^2.0.1",
"he": "^1.2.0",
"html-encoding-sniffer": "^3.0.0",
"http-proxy": "^1.18.1",
"mime": "^1.6.0",
"minimist": "^1.2.6",
"opener": "^1.5.1",
"portfinder": "^1.0.28",
"secure-compare": "3.0.1",
"union": "~0.5.0",
"url-join": "^4.0.1"
}
},
"iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"requires": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
}
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true
},
"mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"dev": true
},
"minimist": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"mkdirp": {
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
"dev": true,
"requires": {
"minimist": "^1.2.6"
}
},
"ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
},
"object-inspect": {
"version": "1.12.2",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
"integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==",
"dev": true
},
"opener": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz",
"integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==",
"dev": true
},
"portfinder": {
"version": "1.0.32",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.32.tgz",
"integrity": "sha512-on2ZJVVDXRADWE6jnQaX0ioEylzgBpQk8r55NE4wjXW1ZxO+BgDlY6DXwj20i0V8eB4SenDQ00WEaxfiIQPcxg==",
"dev": true,
"requires": {
"async": "^2.6.4",
"debug": "^3.2.7",
"mkdirp": "^0.5.6"
}
},
"qs": {
"version": "6.11.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
"dev": true,
"requires": {
"side-channel": "^1.0.4"
}
},
"requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==",
"dev": true
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
},
"secure-compare": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/secure-compare/-/secure-compare-3.0.1.tgz",
"integrity": "sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==",
"dev": true
},
"side-channel": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
"dev": true,
"requires": {
"call-bind": "^1.0.0",
"get-intrinsic": "^1.0.2",
"object-inspect": "^1.9.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"union": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz",
"integrity": "sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==",
"dev": true,
"requires": {
"qs": "^6.4.0"
}
},
"url-join": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==",
"dev": true
},
"whatwg-encoding": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz",
"integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==",
"dev": true,
"requires": {
"iconv-lite": "0.6.3"
}
}
}
}

View File

@ -1,16 +0,0 @@
{
"name": "int-prog",
"version": "1.0.0",
"main": "index.html",
"scripts": {
"start": "http-server -p 3000 ./",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"bootstrap": "5.2.1",
"@fortawesome/fontawesome-free": "6.2.0"
},
"devDependencies": {
"http-server": "14.1.1"
}
}

View File

@ -1,31 +0,0 @@
let calculateButton = document.getElementById("calculate");
let numberOneInput = document.getElementById("first");
let numberTwoInput = document.getElementById("second");
let resultInput = document.getElementById("res");
let typeInput = document.getElementById("type");
function f(operation, event){
event.preventDefault();
let num_1 = numberOneInput.value;
let num_2 = numberTwoInput.value;
let type = typeInput.value;
fetch('http://localhost:8080/sum?first=${num_1}&second=${num_2}&type=${type}')
.then(response => response.text())
.then(res => {
resultInput.value = res;
});
}
buttonPlus.onclick = function(event) {
f("sum",event);
}
buttonMinus.onclick = function(event) {
f("minus",event);
}
buttonMulti.onclick = function(event) {
f("multi",event);
}
buttonDiv.onclick = function(event) {
f("div",event);
}

View File

@ -14,6 +14,20 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'org.webjars:bootstrap:5.1.3'
implementation 'org.webjars:jquery:3.6.0'
implementation 'org.webjars:font-awesome:6.1.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'com.h2database:h2:2.1.210'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

BIN
data.mv.db Normal file

Binary file not shown.

1781
data.trace.db Normal file

File diff suppressed because it is too large Load Diff

6
package-lock.json generated Normal file
View File

@ -0,0 +1,6 @@
{
"name": "IP_PIbd-21_Pyatakov_KM",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

View File

@ -1,13 +1,14 @@
package com.example.demo;
import com.example.demo.author.controller.AuthorMvcController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);

View File

@ -1,13 +1,36 @@
package com.example.demo;
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.ViewControllerRegistration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
class WebConfiguration implements WebMvcConfigurer {
public class WebConfiguration implements WebMvcConfigurer {
public static final String REST_API = "/api";
@Override
public void addCorsMappings(CorsRegistry registry){
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");
}
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
return container -> {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound"));
};
}
}

View File

@ -0,0 +1,45 @@
package com.example.demo.author.controller;
import com.example.demo.WebConfiguration;
import com.example.demo.author.service.AuthorService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(WebConfiguration.REST_API +"/authors")
public class AuthorController {
private final AuthorService authorService;
public AuthorController(AuthorService authorService){
this.authorService = authorService;
}
@GetMapping("/{id}")
public AuthorDto getAuthor(@PathVariable Long id) {
return new AuthorDto(authorService.findAuthor(id));
}
@GetMapping
public List<AuthorDto> getAuthors() {
return authorService.findAllAuthors().stream()
.map(AuthorDto::new)
.toList();
}
@PostMapping
public AuthorDto createAuthor(@RequestBody @Valid AuthorDto authorDto) {
return new AuthorDto(authorService.addAuthor(authorDto.getName(), authorDto.getSurname(), authorDto.getPatronymic()));
}
@PutMapping("/{id}")
public AuthorDto updateAuthor(@PathVariable Long id,
@RequestBody @Valid AuthorDto authorDto) {
return new AuthorDto(authorService.updateAuthor(id, authorDto.getName(), authorDto.getSurname(), authorDto.getPatronymic()));
}
@DeleteMapping("/{id}")
public AuthorDto deleteAuthor(@PathVariable Long id) {
return new AuthorDto(authorService.deleteAuthor(id));
}
}

View File

@ -0,0 +1,52 @@
package com.example.demo.author.controller;
import com.example.demo.author.model.Author;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
public class AuthorDto {
private long id;
@NotBlank(message = "Name can't be null or empty")
private String name;
@NotBlank(message = "Surname can't be null or empty")
private String surname;
private String patronymic;
public AuthorDto(){
}
public AuthorDto(Author author){
id = author.getId();
name = author.getName();
surname = author.getSurname();
patronymic = author.getPatronymic();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public String getPatronymic() {
return patronymic;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setPatronymic(String patronymic) {
this.patronymic = patronymic;
}
}

View File

@ -0,0 +1,45 @@
package com.example.demo.author.controller;
import com.example.demo.author.model.Author;
import com.example.demo.film.controller.FilmDtoWithoutAuthor;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import java.util.List;
public class AuthorDtoFull {
private final long id;
@NotBlank(message = "Name can't be null or empty")
private final String name;
@NotBlank(message = "Surname can't be null or empty")
private final String surname;
private final String patronymic;
private final List<FilmDtoWithoutAuthor> films;
public AuthorDtoFull(Author author){
id = author.getId();
name = author.getName();
surname = author.getSurname();
patronymic = author.getPatronymic();
films = author.getFilms().stream().map(FilmDtoWithoutAuthor::new).toList();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public String getPatronymic() {
return patronymic;
}
public List<FilmDtoWithoutAuthor> getFilms() {
return films;
}
}

View File

@ -0,0 +1,63 @@
package com.example.demo.author.controller;
import com.example.demo.author.service.AuthorService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/authors")
public class AuthorMvcController {
private final AuthorService authorService;
public AuthorMvcController(AuthorService authorService){
this.authorService = authorService;
}
@ModelAttribute("requestURI")
public String requestURI(final HttpServletRequest request) {
return request.getRequestURI();
}
@GetMapping
public String getAuthors(Model model) {
model.addAttribute("authors",
authorService.findAllAuthors().stream()
.map(AuthorDto::new)
.toList());
return "author";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editAuthor(@PathVariable(required = false) Long id,
Model model) {
if (id == null || id <= 0) {
model.addAttribute("authorDto", new AuthorDto());
} else {
model.addAttribute("authorId", id);
model.addAttribute("authorDto", new AuthorDto(authorService.findAuthor(id)));
}
return "author-edit";
}
@PostMapping(value = {"", "/{id}"})
public String saveAuthor(@PathVariable(required = false) Long id,
@ModelAttribute("authorDto") @Valid AuthorDto authorDto,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("errors", bindingResult.getAllErrors());
return "author-edit";
}
if (id == null || id <= 0) {
authorService.addAuthor(authorDto.getName(), authorDto.getSurname(), authorDto.getPatronymic());
} else {
authorService.updateAuthor(id, authorDto.getName(), authorDto.getSurname(), authorDto.getPatronymic());
}
return "redirect:/authors";
}
@PostMapping("/delete/{id}")
public String deleteAuthor(@PathVariable Long id) {
authorService.deleteAuthor(id);
return "redirect:/authors";
}
}

View File

@ -0,0 +1,93 @@
package com.example.demo.author.model;
import com.example.demo.film.model.Film;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String surname;
private String patronymic;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "author", fetch = FetchType.EAGER)
private List<Film> films =new ArrayList<>();
public List<Film> getFilms() {
return films;
}
public void setFilms(List<Film> films) {
this.films = films;
}
public Author() {
}
public Author(String name, String surname) {
this.name = name;
this.surname = surname;
}
public Author(String name, String surname, String patronymic) {
this.name = name;
this.surname = surname;
this.patronymic = patronymic;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPatronymic() {
return patronymic;
}
public void setPatronymic(String patronymic) {
this.patronymic = patronymic;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Author author = (Author) o;
return Objects.equals(id, author.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Author{" +
"id=" + id +
", name='" + name + '\'' + '}' +
", surname='" + surname + '\'' + '}' +
", patronymic='" + patronymic + '\'' + '}';
}
}

View File

@ -0,0 +1,16 @@
package com.example.demo.author.repository;
import com.example.demo.author.model.Author;
import com.example.demo.film.model.Film;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface AuthorRepository extends JpaRepository<Author, Long> {
@Query("SELECT a.films FROM Author a WHERE a.id = :id")
List<Film> getFilmFromAuthor(Long id );
@Query("SELECT COUNT(g) FROM Author a join a.films f JOIN f.genres g WHERE a.id = :id")
Long getCountGenreOfFilmFromAuthor(Long id);
}

View File

@ -0,0 +1,7 @@
package com.example.demo.author.service;
public class AuthorNotFoundException extends RuntimeException{
public AuthorNotFoundException(Long id) {
super(String.format("Author with id [%s] is not found", id));
}
}

View File

@ -0,0 +1,76 @@
package com.example.demo.author.service;
import com.example.demo.author.model.Author;
import com.example.demo.author.repository.AuthorRepository;
import com.example.demo.film.model.Film;
import com.example.demo.genre.model.Genre;
import com.example.demo.util.validation.ValidatorUtil;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class AuthorService {
@PersistenceContext
private EntityManager em;
private final AuthorRepository authorRepository;
private final ValidatorUtil validatorUtil;
public AuthorService(AuthorRepository authorRepository, ValidatorUtil validatorUtil){
this.authorRepository = authorRepository;
this.validatorUtil = validatorUtil;
}
@Transactional
public Author addAuthor(String name, String surname, String patronymic) {
final Author author = new Author(name,surname,patronymic);
validatorUtil.validate(author);
return authorRepository.save(author);
}
@Transactional(readOnly = true)
public Author findAuthor(Long id) {
final Optional<Author> author = authorRepository.findById(id);
return author.orElseThrow(() -> new AuthorNotFoundException(id));
}
@Transactional(readOnly = true)
public List<Author> findAllAuthors() {
return authorRepository.findAll();
}
@Transactional
public Author updateAuthor(Long id, String name, String surname, String patronymic) {
final Author currentAuthor = findAuthor(id);
currentAuthor.setName(name);
currentAuthor.setSurname(surname);
currentAuthor.setPatronymic(patronymic);
validatorUtil.validate(currentAuthor);
return authorRepository.save(currentAuthor);
}
@Transactional
public Author deleteAuthor(Long id) {
final Author currentAuthor = findAuthor(id);
authorRepository.delete(currentAuthor);
return currentAuthor;
}
public Long getCountGenreOfFilmFromAuthor(Long id) {
return authorRepository.getCountGenreOfFilmFromAuthor(id);
}
public List<Film> getFilmsFromAuthor(Long id){
return authorRepository.getFilmFromAuthor(id);
}
@Transactional
public void deleteAllAuthors() {
authorRepository.deleteAll();
}
}

View File

@ -0,0 +1,70 @@
package com.example.demo.film.controller;
import com.example.demo.WebConfiguration;
import com.example.demo.author.service.AuthorService;
import com.example.demo.film.service.FilmService;
import com.example.demo.genre.controller.GenreDto;
import com.example.demo.genre.model.Genre;
import com.example.demo.genre.service.GenreService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(WebConfiguration.REST_API + "/films")
public class FilmController {
private final FilmService filmService;
private final AuthorService authorService;
private final GenreService genreService;
public FilmController(FilmService filmService, AuthorService authorService, GenreService genreService){
this.filmService = filmService;
this.authorService = authorService;
this.genreService = genreService;
}
@GetMapping("/{id}")
public FilmDto getFilm(@PathVariable Long id) {
return new FilmDto(filmService.findFilm(id));
}
@GetMapping
public List<FilmDto> getFilms(@RequestParam(value = "authorId", required = false) Long authorId,
@RequestParam(value = "genreId",required = false) Long genreId,
@RequestParam(value = "name", required = false) String name) {
return filmService.findAllFilms(authorId, genreId, name).stream()
.map(FilmDto::new)
.toList();
}
@PostMapping
public FilmDto createFilm(@RequestBody @Valid FilmDto filmDto) {
List<Genre> genres = new ArrayList<>();
for (GenreDto obj: filmDto.getGenres()) {
genres.add(genreService.findGenre(obj.getId()));
}
return new FilmDto(filmService.addFilm(filmDto.getName(), filmDto.getDescription(),
authorService.findAuthor(filmDto.getAuthor().getId()), genres));
}
@PutMapping("/{id}")
public FilmDto updateFilm(@PathVariable Long id,@RequestBody @Valid FilmDto filmDto) {
return new FilmDto(filmService.updateFilm(id, filmDto.getName(), filmDto.getDescription(),
authorService.findAuthor(filmDto.getAuthor().getId())));
}
@PostMapping("/{id}/genres/{genreId}")
public FilmDto addGenre(@PathVariable Long id,
@PathVariable Long genreId) {
return new FilmDto(filmService.addGenreToFilm(id, genreService.findGenre(genreId)));
}
@PutMapping("/{id}/genres/{genreId}")
public FilmDto removeGenre(@PathVariable Long id,
@PathVariable Long genreId) {
return new FilmDto(filmService.removeGenreFromFilm(id, genreService.findGenre(genreId)));
}
@DeleteMapping("/{id}")
public FilmDto deleteFilm(@PathVariable Long id) {
return new FilmDto(filmService.deleteFilm(id));
}
}

View File

@ -0,0 +1,67 @@
package com.example.demo.film.controller;
import com.example.demo.author.controller.AuthorDto;
import com.example.demo.film.model.Film;
import com.example.demo.genre.controller.GenreDto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.List;
public class FilmDto {
private long id;
@NotBlank(message = "Name can't be null or empty")
private String name;
@NotBlank(message = "Description can't be null or empty")
private String description;
@NotNull(message = "Author can't be null")
private AuthorDto author;
@NotNull(message = "Genres can't be null")
private List<GenreDto> genres;
public FilmDto(){
}
public FilmDto(Film film) {
this.id = film.getId();
this.name = film.getName();
this.description = film.getDescription();
this.author = new AuthorDto(film.getAuthor());
this.genres = film.getGenres().stream().map(GenreDto::new).toList();
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public AuthorDto getAuthor() {
return author;
}
public List<GenreDto> getGenres(){
return genres;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setAuthor(AuthorDto author) {
this.author = author;
}
public void setGenres(List<GenreDto> genres) {
this.genres = genres;
}
}

View File

@ -0,0 +1,62 @@
package com.example.demo.film.controller;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.example.demo.film.model.Film;
import com.example.demo.genre.model.Genre;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.List;
public class FilmDtoForTL {
private long id;
@NotBlank(message = "Name can't be null or empty")
private String name;
@NotBlank(message = "Description can't be null or empty")
private String description;
@NotNull(message = "AuthorId can't be null")
private long authorId;
@NotNull(message = "Genres can't be null")
private List<Long> genresId;
public FilmDtoForTL(){
}
public FilmDtoForTL(Film Film) {
this.id = Film.getId();
this.name = Film.getName();
this.description = Film.getDescription();
this.authorId = Film.getAuthor().getId();
this.genresId = Film.getGenres().stream().map(Genre::getId).toList();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getAuthorId() {
return authorId;
}
public void setAuthorId(long authorId) {
this.authorId = authorId;
}
public List<Long> getGenresId() {
return genresId;
}
public void setGenresId(List<Long> genresId) {
this.genresId = genresId;
}
}

View File

@ -0,0 +1,36 @@
package com.example.demo.film.controller;
import com.example.demo.film.model.Film;
import com.example.demo.genre.controller.GenreDto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.List;
public class FilmDtoWithoutAuthor {
private final long id;
@NotBlank(message = "Name can't be null or empty")
private final String name;
@NotBlank(message = "Description can't be null or empty")
private final String description;
@NotNull(message = "Genres can't be null")
private final List<GenreDto> genres;
public FilmDtoWithoutAuthor(Film film) {
this.id = film.getId();
this.name = film.getName();
this.description = film.getDescription();
this.genres = film.getGenres().stream().map(GenreDto::new).toList();
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public List<GenreDto> getGenres(){
return genres;
}
}

View File

@ -0,0 +1,86 @@
package com.example.demo.film.controller;
import com.example.demo.author.controller.AuthorDto;
import com.example.demo.author.service.AuthorService;
import com.example.demo.film.service.FilmService;
import com.example.demo.genre.controller.GenreDto;
import com.example.demo.genre.model.Genre;
import com.example.demo.genre.service.GenreService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/films")
public class FilmMvcController {
private final FilmService filmService;
private final AuthorService authorService;
private final GenreService genreService;
public FilmMvcController(FilmService filmService, AuthorService authorService, GenreService genreService){
this.filmService = filmService;
this.authorService = authorService;
this.genreService = genreService;
}
@ModelAttribute("requestURI")
public String requestURI(final HttpServletRequest request) {
return request.getRequestURI();
}
@GetMapping
public String getFilms(@RequestParam(value = "authorId", required = false) Long authorId,
@RequestParam(value = "genreId",required = false) Long genreId,
@RequestParam(value = "name", required = false) String name, Model model) {
model.addAttribute("films",
filmService.findAllFilms(authorId, genreId, name).stream()
.map(FilmDto::new)
.toList());
model.addAttribute("genres", genreService.findAllGenres());
return "film";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editFilm(@PathVariable(required = false) Long id,
Model model) {
if (id == null || id <= 0) {
model.addAttribute("filmDto", new FilmDtoForTL());
model.addAttribute("selectedAuthor", null);
} else {
FilmDtoForTL film = new FilmDtoForTL(filmService.findFilm(id));
model.addAttribute("selectedAuthor", film.getAuthorId());
model.addAttribute("filmDto", film);
}
model.addAttribute("authors", authorService.findAllAuthors().stream().map(AuthorDto::new).toList());
model.addAttribute("genres", genreService.findAllGenres().stream().map(GenreDto::new).toList());
return "film-edit";
}
@PostMapping(value = {"", "/{id}"})
public String saveFilm(@PathVariable(required = false) Long id,
@ModelAttribute("filmDto") @Valid FilmDtoForTL film,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("errors", bindingResult.getAllErrors());
return "film-edit";
}
List<Genre> genres = genreService.findGenresByListId(film.getGenresId());
if (id == null || id <= 0) {
filmService.addFilm(film.getName(), film.getDescription(), authorService.findAuthor(film.getAuthorId()),genres);
}
else {
filmService.updateFilmFull(id, film.getName(), film.getDescription(), authorService.findAuthor(film.getAuthorId()), genres);
}
return "redirect:/films";
}
@PostMapping("/delete/{id}")
public String deleteFilm(@PathVariable Long id) {
filmService.deleteFilm(id);
return "redirect:/films";
}
}

View File

@ -0,0 +1,125 @@
package com.example.demo.film.model;
import com.example.demo.author.model.Author;
import com.example.demo.genre.model.Genre;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Film {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String description;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "films_genres",
joinColumns = @JoinColumn(name = "film_id"),
inverseJoinColumns = @JoinColumn(name = "genre_id"))
private List<Genre> genres;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "author_id", nullable = false)
private Author author;
public Film() {
}
public void setGenres(List<Genre> genres){
this.genres = genres;
}
public Film(String name, String description) {
this.name = name;
this.description = description;
}
public void setAuthor(Author author){
if(this.author != null){
this.author.getFilms().remove(this);
}
this.author = author;
if (!author.getFilms().contains(this)) {
author.getFilms().add(this);
}
}
public Author getAuthor() {
return author;
}
public List<Genre> getGenres() {
return genres;
}
public String getNameGenres() {
StringBuilder result = new StringBuilder();
for(Genre g : genres)
result.append(g.getName()).append(", ");
return result.toString();
}
public void addGenre(Genre genre) {
if (genres == null){
genres = new ArrayList<>();
}
this.genres.add(genre);
}
public void removeGenre(Genre genre){
if(genres != null){
genres.remove(genre);
}
}
public Long getId() {
return id;
}
public String[] getGenresName(){
String[] result = new String[genres.size()];
for(int i = 0; i < genres.size(); ++i){
result[i] = genres.get(i).getName();
}
return result;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Film film = (Film) o;
return Objects.equals(id, film.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Film{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", author='" + author.toString() + '\'' +
", genres='" + String.join(", ",getGenresName()) + '\'' +
'}';
}
}

View File

@ -0,0 +1,19 @@
package com.example.demo.film.repository;
import com.example.demo.author.model.Author;
import com.example.demo.film.model.Film;
import com.example.demo.genre.model.Genre;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface FilmRepository extends JpaRepository<Film, Long> {
@Query("SELECT b FROM Film b WHERE :genre MEMBER OF b.genres")
List<Film> getFilmsByGenre(@Param("genre")Genre genre);
@Query("SELECT b FROM Film b WHERE b.author = :author")
List<Film> getFilmsByAuthor(@Param("author") Author author);
@Query("SELECT b FROM Film b WHERE b.name LIKE :name")
List<Film> getFilmsByName(@Param("name") String name);
}

View File

@ -0,0 +1,7 @@
package com.example.demo.film.service;
public class FilmNotFoundException extends RuntimeException{
public FilmNotFoundException(Long id) {
super(String.format("Film with id [%s] is not found", id));
}
}

View File

@ -0,0 +1,106 @@
package com.example.demo.film.service;
import com.example.demo.author.model.Author;
import com.example.demo.author.service.AuthorService;
import com.example.demo.film.model.Film;
import com.example.demo.film.repository.FilmRepository;
import com.example.demo.genre.model.Genre;
import com.example.demo.genre.service.GenreService;
import com.example.demo.util.validation.ValidatorUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@Service
public class FilmService {
private final FilmRepository filmRepository;
private final GenreService genreService;
private final AuthorService authorService;
private final ValidatorUtil validatorUtil;
public FilmService(FilmRepository filmRepository,GenreService genreService, AuthorService authorService, ValidatorUtil validatorUtil){
this.filmRepository = filmRepository;
this.genreService = genreService;
this.authorService = authorService;
this.validatorUtil = validatorUtil;
}
@Transactional
public Film updateFilmFull(Long id, String name, String description, Author author, List<Genre> genres){
final Film currentFilm = findFilm(id);
currentFilm.setName(name);
currentFilm.setDescription(description);
currentFilm.setAuthor(author);
currentFilm.setGenres(genres);
return filmRepository.save(currentFilm);
}
@Transactional
public Film addFilm(String name, String description, Author author, List<Genre> genres) {
final Film film = new Film(name, description);
film.setAuthor(author);
for (Genre genre: genres) {
film.addGenre(genre);
}
validatorUtil.validate(film);
return filmRepository.save(film);
}
@Transactional(readOnly = true)
public Film findFilm(Long id) {
final Optional<Film> film = filmRepository.findById(id);
return film.orElseThrow(() -> new FilmNotFoundException(id));
}
@Transactional(readOnly = true)
public List<Film> findAllFilms(Long authorId, Long genreId, String name) {
if(authorId != null){
Author author = authorService.findAuthor(authorId);
return filmRepository.getFilmsByAuthor(author);
}
else if(genreId != null){
Genre genre = genreService.findGenre(genreId);
return filmRepository.getFilmsByGenre(genre);
}
else if(name != null){
return filmRepository.getFilmsByName("%" + name + "%");
}
return filmRepository.findAll();
}
@Transactional
public Film updateFilm(Long id, String name, String description, Author author) {
final Film currentFilm = findFilm(id);
currentFilm.setName(name);
currentFilm.setDescription(description);
currentFilm.setAuthor(author);
validatorUtil.validate(currentFilm);
return filmRepository.save(currentFilm);
}
@Transactional
public Film addGenreToFilm(Long id, Genre genre){
final Film currentFilm = findFilm(id);
validatorUtil.validate(genre);
currentFilm.addGenre(genre);
validatorUtil.validate(currentFilm);
return filmRepository.save(currentFilm);
}
@Transactional
public Film removeGenreFromFilm(Long id, Genre genre){
final Film currentFilm = findFilm(id);
validatorUtil.validate(genre);
currentFilm.removeGenre(genre);
validatorUtil.validate(currentFilm);
return filmRepository.save(currentFilm);
}
@Transactional
public Film deleteFilm(Long id) {
final Film currentFilm = findFilm(id);
filmRepository.delete(currentFilm);
return currentFilm;
}
@Transactional
public void deleteAllFilms() {
filmRepository.deleteAll();
}
}

View File

@ -0,0 +1,44 @@
package com.example.demo.genre.controller;
import com.example.demo.WebConfiguration;
import com.example.demo.genre.service.GenreService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(WebConfiguration.REST_API + "/genres")
public class GenreController {
private final GenreService genreService;
public GenreController(GenreService genreService){
this.genreService = genreService;
}
@GetMapping("/{id}")
public GenreDto getGenre(@PathVariable Long id) {
return new GenreDto(genreService.findGenre(id));
}
@GetMapping
public List<GenreDto> getGenres() {
return genreService.findAllGenres().stream()
.map(GenreDto::new)
.toList();
}
@PostMapping
public GenreDto createGenre(@RequestBody @Valid GenreDto genreDto) {
return new GenreDto(genreService.addGenre(genreDto.getName()));
}
@PutMapping("/{id}")
public GenreDto updateGenre(@PathVariable Long id,
@RequestBody @Valid GenreDto genreDto) {
return new GenreDto(genreService.updateGenre(id, genreDto.getName()));
}
@DeleteMapping("/{id}")
public GenreDto deleteGenre(@PathVariable Long id) {
return new GenreDto(genreService.deleteGenre(id));
}
}

View File

@ -0,0 +1,30 @@
package com.example.demo.genre.controller;
import com.example.demo.genre.model.Genre;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
public class GenreDto {
private long id;
@NotBlank(message = "Name can't be null or empty")
private String name;
public GenreDto() {
}
public GenreDto(Genre genre) {
this.id = genre.getId();
this.name = genre.getName();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,63 @@
package com.example.demo.genre.controller;
import com.example.demo.genre.service.GenreService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/genres")
public class GenreMvcController {
private final GenreService genreService;
public GenreMvcController(GenreService genreService){
this.genreService = genreService;
}
@ModelAttribute("requestURI")
public String requestURI(final HttpServletRequest request) {
return request.getRequestURI();
}
@GetMapping
public String getGenres(Model model) {
model.addAttribute("genres",
genreService.findAllGenres().stream()
.map(GenreDto::new)
.toList());
return "genre";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editGenre(@PathVariable(required = false) Long id,
Model model) {
if (id == null || id <= 0) {
model.addAttribute("genreDto", new GenreDto());
} else {
model.addAttribute("genreId", id);
model.addAttribute("genreDto", new GenreDto(genreService.findGenre(id)));
}
return "genre-edit";
}
@PostMapping(value = {"", "/{id}"})
public String saveGenre(@PathVariable(required = false) Long id,
@ModelAttribute("genreDto") @Valid GenreDto genreDto,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("errors", bindingResult.getAllErrors());
return "genre-edit";
}
if (id == null || id <= 0) {
genreService.addGenre(genreDto.getName());
} else {
genreService.updateGenre(id, genreDto.getName());
}
return "redirect:/genres";
}
@PostMapping("/delete/{id}")
public String deleteGenre(@PathVariable Long id) {
genreService.deleteGenre(id);
return "redirect:/genres";
}
}

View File

@ -0,0 +1,49 @@
package com.example.demo.genre.model;
import jakarta.persistence.*;
import java.util.Objects;
@Entity
public class Genre {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Genre() {
}
public Genre(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Genre genre = (Genre) o;
return Objects.equals(id, genre.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Genre{" +
"id=" + id +
", name='" + name + '\'' + '}';
}
}

View File

@ -0,0 +1,13 @@
package com.example.demo.genre.repository;
import com.example.demo.film.model.Film;
import com.example.demo.genre.model.Genre;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface GenreRepository extends JpaRepository<Genre, Long> {
@Query("SELECT b FROM Film b WHERE ?1 MEMBER OF b.genres")
List<Film>getFilmsWithGenre(Genre genre);
}

View File

@ -0,0 +1,6 @@
package com.example.demo.genre.service;
public class GenreNotFoundException extends RuntimeException{
public GenreNotFoundException(Long id) {
super(String.format("Genre with id [%s] is not found", id));
}
}

View File

@ -0,0 +1,75 @@
package com.example.demo.genre.service;
import com.example.demo.film.model.Film;
import com.example.demo.genre.model.Genre;
import com.example.demo.genre.repository.GenreRepository;
import com.example.demo.util.validation.ValidatorUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class GenreService {
private final GenreRepository genreRepository;
private final ValidatorUtil validatorUtil;
public GenreService(GenreRepository genreRepository, ValidatorUtil validatorUtil){
this.genreRepository = genreRepository;
this.validatorUtil = validatorUtil;
}
@Transactional
public Genre addGenre(String name) {
final Genre genre = new Genre(name);
validatorUtil.validate(genre);
return genreRepository.save(genre);
}
@Transactional(readOnly = true)
public Genre findGenre(Long id) {
final Optional<Genre> genre = genreRepository.findById(id);
return genre.orElseThrow(() -> new GenreNotFoundException(id));
}
@Transactional
public List<Genre> findGenresByListId(List<Long> ll){
List<Genre> genres = new ArrayList<>();
for (Long l: ll){
genreRepository.findById(l).ifPresent(genres::add);
}
return genres;
}
@Transactional(readOnly = true)
public List<Genre> findAllGenres() {
return genreRepository.findAll();
}
@Transactional
public Genre updateGenre(Long id, String name) {
final Genre currentGenre = findGenre(id);
currentGenre.setName(name);
validatorUtil.validate(currentGenre);
return genreRepository.save(currentGenre);
}
@Transactional(readOnly = true)
public List<Film> findAllFilmsWithGenre(Genre genre){
if(genre == null){
throw new IllegalArgumentException("Genre is null or empty");
}
return genreRepository.getFilmsWithGenre(genre);
}
@Transactional
public Genre deleteGenre(Long id) {
final Genre currentGenre = findGenre(id);
genreRepository.delete(currentGenre);
return currentGenre;
}
@Transactional
public void deleteAllGenres() {
genreRepository.deleteAll();
}
}

View File

@ -1,6 +1,6 @@
package method.controller;
package com.example.demo.method.controller;
import method.service.MethodService;
import com.example.demo.method.service.MethodService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

View File

@ -1,4 +1,4 @@
package method.domain;
package com.example.demo.method.domain;
public interface IMethod<T> {
T Sum(T first, T second);

View File

@ -1,4 +1,4 @@
package method.domain;
package com.example.demo.method.domain;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package method.domain;
package com.example.demo.method.domain;
import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package method.service;
package com.example.demo.method.service;
import method.domain.IMethod;
import method.domain.MethodString;
import com.example.demo.method.domain.IMethod;
import com.example.demo.method.domain.MethodString;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

View File

@ -0,0 +1,84 @@
package com.example.demo.student.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Component {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column()
private String ComponentName;
private Integer Count;
@ManyToMany(mappedBy = "components", fetch = FetchType.EAGER)
@Cascade(CascadeType.REMOVE)
private List<Product> products;
public Component() {
}
public Component(String ComponentName, Integer Count) {
this.ComponentName = ComponentName;
this.Count = Count;
}
public Long getId() {
return id;
}
public String getComponentName() {
return ComponentName;
}
public void setComponentName(String ComponentName) {
this.ComponentName = ComponentName;
}
public List<Product> getProduct() {
return products;
}
public void setProduct(Product product) {
if (products == null){
products = new ArrayList<>();
}
this.products.add(product);
if (!product.getComponents().contains(this)) { // warning this may cause performance issues if you have a large data set since this operation is O(n)
product.getComponents().add(this);
}
}
public Integer getCount() {
return Count;
}
public void setCount(Integer Count) {
this.Count = Count;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Component component = (Component) o;
return Objects.equals(id, component.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Component{" +
"id=" + id +
", ComponentName='" + ComponentName + '\'' +
", Count='" + Count + '\'' +
'}';
}
}

View File

@ -0,0 +1,87 @@
package com.example.demo.student.model;
import jakarta.persistence.*;
import org.hibernate.annotations.Cascade;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name="tab_order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Temporal(TemporalType.DATE)
private Date CreateDate;
private Integer Count;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "ords_product",
joinColumns = @JoinColumn(name = "ord_fk"),
inverseJoinColumns = @JoinColumn(name = "product_fk"))
@Cascade(org.hibernate.annotations.CascadeType.REMOVE)
private List<Product> products;
public Order() {
}
public Order(Date CreateDate, Integer Count) {
this.CreateDate = CreateDate;
this.Count = Count;
}
public void addProduct(Product product) {
if (products == null){
products = new ArrayList<>();
}
this.products.add(product);
if (product.getOrder() == null) {
product.setOrder(this);
}
}
public Long getId() {
return id;
}
public Date getCreateDate() {
return CreateDate;
}
public void setCreateDate(Date CreateDate) {
this.CreateDate = CreateDate;
}
public Integer getCount() {
return Count;
}
public void setCount(Integer Count) {
this.Count = Count;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Order ord = (Order) o;
return Objects.equals(id, ord.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Ord{" +
"id=" + id +
", CreateDate='" + CreateDate + '\'' +
", Count='" + Count + '\'' +
'}';
}
public List<Product> getProducts() {
return products;
}
}

View File

@ -0,0 +1,105 @@
package com.example.demo.student.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column()
private String ProductName;
private Integer Price;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "products_component",
joinColumns = @JoinColumn(name = "product_fk"),
inverseJoinColumns = @JoinColumn(name = "component_fk"))
@Cascade(CascadeType.REMOVE)
private List<Component> components;
@ManyToMany(mappedBy = "products", fetch = FetchType.EAGER)
@Cascade(CascadeType.REMOVE)
private List<Order> ords;
public void addComponent(Component component) {
if (components == null){
components = new ArrayList<>();
}
this.components.add(component);
if (component.getProduct() == null) {
component.setProduct(this);
}
}
public Product() {
}
public Product(String ProductName, Integer Price) {
this.ProductName = ProductName;
this.Price = Price;
}
public Long getId() {
return id;
}
public String getProductName() {
return ProductName;
}
public void setProductName(String ProductName) {
this.ProductName = ProductName;
}
public Integer getPrice() {
return Price;
}
public void setPrice(Integer Price) {
this.Price = Price;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return Objects.equals(id, product.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Product{" +
"id=" + id +
", ProductName='" + ProductName + '\'' +
", Price='" + Price + '\'' +
'}';
}
public List<Component> getComponents() {
return components;
}
public List<Order> getOrder() {
return ords;
}
public void setOrder(Order order) {
if (ords == null){
ords = new ArrayList<>();
}
this.ords.add(order);
if (!order.getProducts().contains(this)) { // warning this may cause performance issues if you have a large data set since this operation is O(n)
order.getProducts().add(this);
}
}
}

View File

@ -0,0 +1,80 @@
package com.example.demo.student.service;
import com.example.demo.student.model.Component;
import com.example.demo.student.model.Order;
import com.example.demo.student.model.Product;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
@Service
public class ComponentService {
@PersistenceContext
private EntityManager em;
@Autowired
private ProductService productService;
@Transactional
public Component addComponent(String ComponentName, Integer Count) {
if (!StringUtils.hasText(ComponentName) || Count == 0) {
throw new IllegalArgumentException("Component is null or empty");
}
final Component component = new Component(ComponentName, Count);
em.persist(component);
return component;
}
@Transactional(readOnly = true)
public Component findComponent(Long id) {
final Component component = em.find(Component.class, id);
if (component == null) {
throw new EntityNotFoundException(String.format("Component with id [%s] is not found", id));
}
return component;
}
@Transactional(readOnly = true)
public List<Component> findAllComponent() {
return em.createQuery("select s from Component s", Component.class)
.getResultList();
}
@Transactional
public Component updateComponent(Long id, String ComponentName, Integer Count) {
if (!StringUtils.hasText(ComponentName) || Count != 0) {
throw new IllegalArgumentException("Component is null or empty");
}
final Component currentComponent = findComponent(id);
currentComponent.setComponentName(ComponentName);
currentComponent.setCount(Count);
return em.merge(currentComponent);
}
@Transactional
public Component deleteComponent(Long id) {
final Component currentComponent = findComponent(id);
/*List<Product> ls = productService.findAllProduct();
for (Product p: ls){
List<Component> cl = p.getComponents();
for(Component c:cl){
if(c.getId() == id){
productService.deleteProduct(p.getId());
break;
}
}
}*/
em.remove(currentComponent);
return currentComponent;
}
@Transactional
public void deleteAllComponent() {
em.createQuery("delete from Component").executeUpdate();
}
}

View File

@ -0,0 +1,83 @@
package com.example.demo.student.service;
import com.example.demo.student.model.Component;
import com.example.demo.student.model.Order;
import com.example.demo.student.model.Product;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class OrderService {
@PersistenceContext
private EntityManager em;
@Transactional
public Order addOrd(Date CreateDate, Integer Price, ArrayList<Product> products) {
if (!StringUtils.hasText(CreateDate.toString())) {
throw new IllegalArgumentException("Ord is null or empty");
}
final Order order = new Order(new Date(), Price);
for (Product product : products) {
order.addProduct(product);
}
em.persist(order);
return order;
}
@Transactional(readOnly = true)
public Order findOrd(Long id) {
final Order product = em.find(Order.class, id);
if (product == null) {
throw new EntityNotFoundException(String.format("Ord with id [%s] is not found", id));
}
return product;
}
@Transactional(readOnly = true)
public List<Order> findAllOrd() {
return em.createQuery("select s from Order s", Order.class)
.getResultList();
}
@Transactional
public Order updateOrd(Long id, Date CreateDate, Integer Count) {
if (!StringUtils.hasText(CreateDate.toString())) {
throw new IllegalArgumentException("Ord is null or empty");
}
final Order currentOrd = findOrd(id);
currentOrd.setCreateDate(CreateDate);
currentOrd.setCount(Count);
return em.merge(currentOrd);
}
@Transactional
public Order deleteOrd(Long id) {
final Order currentOrd = findOrd(id);
em.remove(currentOrd);
return currentOrd;
}
@Transactional
public void deleteAllOrd() {
em.createQuery("delete from Order").executeUpdate();
}
public Long getCountComponentFromOrder(Long id) {
var k = em.createQuery("SELECT COUNT(c) FROM Order o " +
"JOIN o.products p " +
"JOIN p.components c " +
"WHERE o.id = :id", Long.class)
.setParameter("id", id)
.getSingleResult();
return k;
}
}

View File

@ -0,0 +1,84 @@
package com.example.demo.student.service;
import com.example.demo.student.model.Component;
import com.example.demo.student.model.Order;
import com.example.demo.student.model.Product;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
@Service
public class ProductService {
@PersistenceContext
private EntityManager em;
@Autowired
private OrderService orderService;
@Transactional
public Product addProduct(String ProductName, Integer Price, List<Component> components) {
if (!StringUtils.hasText(ProductName)) {
throw new IllegalArgumentException("Product is null or empty");
}
final Product product = new Product(ProductName, Price);
for (int i = 0; i < components.size(); i++){
product.addComponent(components.get(i));
}
em.persist(product);
return product;
}
@Transactional(readOnly = true)
public Product findProduct(Long id) {
final Product product = em.find(Product.class, id);
if (product == null) {
throw new EntityNotFoundException(String.format("Product with id [%s] is not found", id));
}
return product;
}
@Transactional(readOnly = true)
public List<Product> findAllProduct() {
return em.createQuery("select s from Product s", Product.class)
.getResultList();
}
@Transactional
public Product updateProduct(Long id, String ProductName, Integer Count) {
if (!StringUtils.hasText(ProductName) || Count != 0) {
throw new IllegalArgumentException("Product is null or empty");
}
final Product currentProduct = findProduct(id);
currentProduct.setProductName(ProductName);
currentProduct.setPrice(Count);
return em.merge(currentProduct);
}
@Transactional
public Product deleteProduct(Long id) {
final Product currentProduct = findProduct(id);
/*List<Order> ls = orderService.findAllOrd();
for (Order k: ls) {
List<Product> pl = k.getProducts();
for (Product p:pl) {
if(p.getId() == id){
orderService.deleteOrd(k.getId());
break;
}
}
}*/
em.remove(currentProduct);
return currentProduct;
}
@Transactional
public void deleteAllProduct() {
em.createQuery("delete from Product").executeUpdate();
}
}

View File

@ -0,0 +1,45 @@
package com.example.demo.util;
import com.example.demo.author.controller.AuthorDto;
import com.example.demo.author.service.AuthorService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class StaticPagesMvcController {
private final AuthorService authorService;
public StaticPagesMvcController(AuthorService authorService) {
this.authorService = authorService;
}
@RequestMapping("/")
public String indexPage(){
return "index";
}
@RequestMapping("/forum")
public String forumPage(){
return "forum";
}
@RequestMapping("/login")
public String loginPage(){
return "login";
}
// @RequestMapping("/request")
// public String requestPage(){
// return "request";
// }
@RequestMapping(value = {"/request", "/request/{id}"})
public String editProduct(@PathVariable(required = false) Long id,
@ModelAttribute AuthorDto componentDTO,
Model model) {
if (componentDTO != null && componentDTO.getId() != 0){
model.addAttribute("count", authorService.getCountGenreOfFilmFromAuthor(componentDTO.getId()));
model.addAttribute("filmList", authorService.getFilmsFromAuthor(componentDTO.getId()));
}
model.addAttribute("componentDto", new AuthorDto());
model.addAttribute("components", authorService.findAllAuthors());
return "request";
}
}

View File

@ -0,0 +1,43 @@
package com.example.demo.util.error;
import com.example.demo.author.service.AuthorNotFoundException;
import com.example.demo.film.service.FilmNotFoundException;
import com.example.demo.genre.service.GenreNotFoundException;
import com.example.demo.util.validation.ValidationException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import java.util.stream.Collectors;
@ControllerAdvice(annotations = RestController.class)
public class AdviceController {
@ExceptionHandler({
GenreNotFoundException.class,
AuthorNotFoundException.class,
FilmNotFoundException.class,
ValidationException.class
})
public ResponseEntity<Object> handleException(Throwable e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
final ValidationException validationException = new ValidationException(
e.getBindingResult().getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.toSet()));
return handleException(validationException);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleUnknownException(Throwable e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View File

@ -0,0 +1,7 @@
package com.example.demo.util.validation;
import java.util.Set;
public class ValidationException extends RuntimeException{
public ValidationException(Set<String> errors) {
super(String.join("\n", errors));
}
}

View File

@ -0,0 +1,28 @@
package com.example.demo.util.validation;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.springframework.stereotype.Component;
import java.util.Set;
import java.util.stream.Collectors;
@Component
public class ValidatorUtil {
private final Validator validator;
public ValidatorUtil() {
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
this.validator = factory.getValidator();
}
}
public <T> void validate(T object) {
final Set<ConstraintViolation<T>> errors = validator.validate(object);
if (!errors.isEmpty()) {
throw new ValidationException(errors.stream()
.map(ConstraintViolation::getMessage)
.collect(Collectors.toSet()));
}
}
}

View File

@ -1 +1,12 @@
spring.main.banner-mode=off
server.port=8079
server.tomcat.relaxed-query-chars=|,{,},[,]
spring.datasource.url=jdbc:h2:file:./data
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

View File

@ -0,0 +1,18 @@
document.addEventListener("DOMContentLoaded", function () {
console.info("Loaded");
const banners = document.querySelectorAll("#banner img");
var old = banners.length - 1;
var current = 0;
function loop() {
banners[current].setAttribute("class", "show img-fluid");
banners[old].setAttribute("class", "hide img-fluid");
console.info("Banner changed");
old = current;
current++;
if (current === banners.length) {
current = 0;
}
setTimeout(loop, 5000);
}
loop();
});

View File

@ -0,0 +1,15 @@
const forms = document.querySelectorAll(".needs-validation");
for (let i = 0; i < forms.length; i++) {
const form = forms[i];
form.addEventListener(
"submit",
function (event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add("was-validated");
},
false
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,73 @@
.nav-link {
text-decoration: none;
font-weight: bold;
color: black;
}
.show{
display: block;
}
.hide{
display: none;
}
.nav-link:hover {
color: RGB(98, 73, 73);
text-decoration: underline;
}
.card .card-title a {
text-decoration: none;
color: black;
}
header .img-fluid {
width: 200px;
}
.card .card-title a:hover {
text-decoration: underline;
}
.btn {
background-color: RGB(98, 73, 73);
}
.btn:hover {
background-color: RGB(98, 33, 3);
}
.card .img-fluid {
width: auto;
height: 100%;
object-fit: cover;
}
.drop{
display: none;
}
@media (max-width: 1000px) {
.main_card {
flex-direction: column;
align-items: center;
}
.drop{
display: block;
}
.genres{
display: none;
}
.book_main{
width:50vw;
}
.forum_page{
display: flex;
flex-direction: column;
}
.forum_img{
width: 100px!important;
}
}
.all_genres {
word-wrap: break-word;
}
.forum_img{
width: 10vw;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/authors/{id}(id=*{id})}" th:object="${authorDto}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Имя</label>
<input type="text" class="form-control" id="name" name="name" th:field="*{name}" placeholder="Имя" required="true">
</div>
<div class="mb-3">
<label for="surname" class="form-label">Фамилия</label>
<input type="text" class="form-control" id="surname" name="surname" th:field="*{surname}" placeholder="Фамилия" required="true">
</div>
<div class="mb-3">
<label for="patronymic" class="form-label">Отчество</label>
<input type="text" class="form-control" id="patronymic" name="patronymic" th:field="*{patronymic}" placeholder="Отчество">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/authors}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<a class="btn btn-success button-fixed"
th:href="@{/authors/edit}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">ФИО</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="author, iterator: ${authors}">
<th scope="row" th:text="${iterator.index} + 1"></th>
<td th:text="${author.id}"></td>
<td th:text="${author.name} + ' ' + ${author.surname} + ' ' + ${author.patronymic}" style="width: 60%"></td>
<td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm"
th:href="@{/authors/edit/{id}(id=${author.id})}">
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
</a>
<button type="button" class="btn btn-danger button-fixed button-sm"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${author.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/authors/delete/{id}(id=${author.id})}" method="post">
<button th:id="'remove-' + ${author.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,105 @@
<!DOCTYPE html>
<html lang="ru"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<title>Онлайн-библиотека</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
<link th:href="@{/styles/style.css}" rel="stylesheet" />
</head>
<body class="d-flex flex-column min-vh-100">
<header style="background-color: RGB(235, 185, 185)">
<div class="container-fluid">
<div class="row align-items-start">
<div class="col">
<img class="img-fluid p-3" src="i.png" />
</div>
<div class="col align-items-center">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid d-flex flex-column">
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<h1 class="text-center">Онлайн-кинотеатр</h1>
<div
class="collapse navbar-collapse"
id="navbarSupportedContent"
>
<ul
class="nav nav-tabs justify-content-center border-bottom-0" th:with="activeLink=${requestURI}"
>
<li class="nav-item">
<a class="nav-link" href="/"
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/films"
th:classappend="${#strings.equals(activeLink, '/films')} ? 'active' : ''">Фильмы</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/authors"
th:classappend="${#strings.equals(activeLink, '/authors')} ? 'active' : ''">Авторы</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/genres"
th:classappend="${#strings.equals(activeLink, '/genres')} ? 'active' : ''">Жанры</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/forum">Форум</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/request">Запрос</a>
</li>
</ul>
</div>
<form class="w-100">
<input
class="p-2 form-control"
type="search"
placeholder="Найти"
/>
</form>
</div>
</nav>
</div>
<span class="col text-end">
<a class="nav-link" href="/login">Вход/регистрация</a>
</span>
</div>
</div>
</header>
<div class="container-fluid">
<div class="container container-padding" layout:fragment="content">
</div>
</div>
<footer class="mt-auto" style="background-color: RGB(235, 185, 185)">
<div class="container-fluid p-4 ms-0 border-bottom border-white">
<div class="col-lg-3 col-md-6 mb-4 mb-md-0">
<ul class="list-unstyled mb-0">
<li>
<a class="nav-link" href="#">Контакты</a>
</li>
<li>
<a class="nav-link" href="#">Политика приватности</a>
</li>
</ul>
</div>
</div>
<div class="text-end pb-1 pe-1">Пятаков Кирилл, 2023</div>
</footer>
<th:block layout:fragment="scripts">
</th:block>
</body>
</html>

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
>
<head>
</head>
<body>
<div layout:fragment="content">
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/films/{id}(id=*{id})}" th:object="${filmDto}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" name="name" th:field="*{name}" placeholder="Название" required="true">
</div>
<div class="mb-3">
<label for="description" class="form-label">Описание</label>
<textarea class="form-control" id="description" name="description" th:field="*{description}" required="true"></textarea>
</div>
<div class="mb-3">
<label for="author" class="form-label">Автор</label>
<select id="author" class="form-select" th:field="*{authorId}" th:name="${selectedAuthor}">
<option th:each="value: ${authors}" th:selected="${selectedAuthor != null and selectedAuthor == value.id}" th:value="${value.id}" th:text="${value.surname} + ' ' + ${value.name}"></option>
</select>
</div>
<p class="d-flex justify-content-between">
<label>Жанры:
<input type="checkbox" name="genres"
th:each="genre : ${genres}"
th:text="${genre.name}"
th:value="${genre.id}"
th:field="*{genresId}"
/>
</label>
</p>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/films}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
>
<head>
</head>
<body>
<div layout:fragment="content">
<div class="flex-shrink-0" style="background-color: RGB(255, 255, 255)">
<div class="row justify-content-center">
<div class="col-3 genres" style="background-color: rgb(211,211,211); min-height: 68vh">
<div class="d-flex flex-row justify-content-between div-with-button">
<h2>Список жанров</h2>
<a class="btn btn-success button-fixed"
th:href="@{/films/edit}">
<i class="fa fa-pencil" aria-hidden="true"></i> Добавить
</a>
</div>
<div class="all_genres">
<ul id="list-genres">
<li th:each="genre: ${genres}">
<a href="#" th:text="${genre.name}"></a>
</li>
</ul>
</div>
</div>
<div class="col-sm-9">
<h2>Фильмы</h2>
<div class="container p-4 row" th:each="film: ${films}" id="films-list">
<div
class="card film_card mb-3 me-3"
style="max-width: 540px"
>
<div class="row g-0 film_item d-flex">
<div class="col-md-8 d-flex flex-column card_text_div">
<div class="card-body">
<h5 class="card-title">
<a href="" th:text="${film.name}"></a>
</h5>
<p class="card-text" th:text="${film.description}"></p>
<p class="card-text">
<span>Автор:</span>
<a class="text-decoration-underline" th:href="@{/films?authorId={id}(id=${film.author.id})}" th:text="${film.author.surname} + ' ' + ${film.author.name}" role="button"></a>
</p>
<span>Жанры:</span>
<div class="card-text" th:each="value: ${film.genres}">
<a class="text-decoration-underline" th:href="@{/films?genreId={id}(id=${value.id})}" role="button" th:text="${value.name}"></a>
</div>
</div>
<div class="d-flex justify-content-end">
<a
role="button"
class="text-end align-self-end"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${film.id}').click()|">
Удалить
</a>
<a
class="px-2 text-end align-self-end"
th:href="@{/films/edit/{id}(id=${film.id})}"
>
Изменить
</a>
<form th:action="@{/films/delete/{id}(id=${film.id})}" method="post">
<button th:id="'remove-' + ${film.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
>
<head>
</head>
<body>
<div layout:fragment="content">
<h2>Форум</h2>
<div class="container-fluid column">
<div class="card text-end mb-3" style="background-color: rgb(211,211,211);">
<div class="row g-0 justify-content-between forum_page">
<div class="col-md-4 forum_img">
<img src="x5s0payf.jpg" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<a href="#" class="text-black"><h5 class="card-title">Обсуждение 1</h5></a>
<p class="card-text">Создатель: Пользователь 1</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
<div class="card text-end mb-3" style="background-color: rgb(211,211,211);">
<div class="row g-0 justify-content-between forum_page">
<div class="col-md-4 forum_img">
<img src="x5s0payf.jpg" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<a href="#" class="text-black"><h5 class="card-title">Обсуждение 2</h5></a>
<p class="card-text">Создатель: Пользователь 2</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/genres/{id}(id=*{id})}" th:object="${genreDto}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" name="name" th:field="*{name}" placeholder="Название" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/genres}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<a class="btn btn-success button-fixed"
th:href="@{/genres/edit}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">Название</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="genre, iterator: ${genres}">
<th scope="row" th:text="${iterator.index} + 1"></th>
<td th:text="${genre.id}"></td>
<td th:text="${genre.name}" style="width: 60%"></td>
<td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm"
th:href="@{/genres/edit/{id}(id=${genre.id})}">
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
</a>
<button type="button" class="btn btn-danger button-fixed button-sm"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${genre.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/genres/delete/{id}(id=${genre.id})}" method="post">
<button th:id="'remove-' + ${genre.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
>
<head>
</head>
<body>
<div layout:fragment="content">
<div id="banner" class="p-4 d-flex justify-content-center">
<img src="image_image_1199445.png" class="hide img-fluid" />
<img src="image.png" class="hide img-fluid" />
</div>
<h2 class="p-4">Новинки</h2>
<div class="container p-4">
<div class="main_card row d-flex">
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="besprinc.png"/>
<div class="card-body">
<h4 class="card-title">
<a href="#">Беспринципные в деревне</a>
</h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="atakatiti.png"
/>
<div class="card-body">
<h4 class="card-title"><a href="#">Атака на титанов</a></h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="mashaimed.png"
/>
<div class="card-body">
<h4 class="card-title">
<a href="#">Мастер и Маргарита</a>
</h4>
<p class="card-text"></p>
</div>
</div>
</div>
</div>
</div>
<h2 class="p-4">Самое популярное</h2>
<div class="container p-4">
<div class="row main_card">
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="dvaholma.png"
/>
<div class="card-body">
<h4 class="card-title">
<a href="#">Два холма ( .) ( .)</a>
</h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="ledijuk.png"
/>
<div class="card-body">
<h4 class="card-title"><a href="#">Леди Жук и Супер-Кiт: Пробуждение гноя</a></h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3 film_main">
<div class="card">
<img
class="img-fluid"
src="papaido4ki.png"
/>
<div class="card-body">
<h4 class="card-title">
<a href="#">Папины Д.о.ч.к.и</a>
</h4>
<p class="card-text"></p>
</div>
</div>
</div>
</div>
</div>
</div>
<th:block layout:fragment="scripts">
<script type="text/javascript" th:src="@{/js/banner.js}"></script>
</th:block>
</body>
</html>

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
>
<head>
</head>
<body>
<div layout:fragment="content">
<form class="w-50 ms-2 needs-validation"novalidate>
<h2 class="py-3">Вход</h2>
<h4>Логин</h4>
<input class="form-control my-2" type="email" required />
<div class="invalid-feedback">
Пожалуйста введите электронную почту вида: "..@.."
</div>
<h4>Пароль</h4>
<input class="form-control my-2" type="password" required />
<div>
<button class="btn btn-primary m-2" type="submit">Войти</button>
<a href="" style="margin-top: 1em; margin-left: 1em"
>Зарегистрируйтесь, если нет аккаунта, здесь</a
>
</div>
</form>
</div>
<th:block layout:fragment="scripts">
<script src="js/formValid.js"></script>
</th:block>
</body>
</html>

View File

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div class="flex-shrink-0" style="background-color: RGB(255, 255, 255)">
<div>
<form
action="#"
th:action="@{/request}"
th:object="${componentDto}"
method="post"
>
<div class="mb-3">
<label for="lang" class="form-label">Автор</label>
<select id="lang" class="form-select" th:field="${componentDto.id}">
<option
th:each="value: ${components}"
th:value="${value.getId()}"
th:selected="true"
th:text="${value.getSurname()}"
></option>
</select>
</div>
<div>
<div>
<button class="btn btn-success button-fixed" type="submit">
получить
</button>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">Название</th>
<th scope="col">Жанры</th>
</tr>
</thead>
<tbody>
<tr th:each="film, iterator: ${filmList}">
<th scope="row" th:text="${iterator.index} + 1"></th>
<td th:text="${film.id}"></td>
<td th:text="${film.name}" style="width: 60%"></td>
<td th:text="${film.getNameGenres()}" style="width: 60%"></td>
<td style="width: 10%">
</td>
</tr>
<tr>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col" style="text-align: end">Итого: </th>
<th th:if="${count != null}" th:text="${count}"></th>
</tr>
</tbody>
</table>
</form>
<br/>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,215 @@
package com.example.demo;
import com.example.demo.student.model.Component;
import com.example.demo.student.model.Order;
import com.example.demo.student.model.Product;
import com.example.demo.student.service.ComponentService;
import com.example.demo.student.service.OrderService;
import com.example.demo.student.service.ProductService;
import jakarta.persistence.EntityNotFoundException;
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.ArrayList;
import java.util.Date;
import java.util.List;
@SpringBootTest
public class JpaStudentTests {
private static final Logger log = LoggerFactory.getLogger(JpaStudentTests.class);
@Autowired
private ComponentService componentService;
@Autowired
private ProductService productService;
@Autowired
private OrderService ordService;
@Test
void testComponentCreate() {
componentService.deleteAllComponent();
final Component component = componentService.addComponent("c1", 3);
log.info(component.toString());
Assertions.assertNotNull(component.getId());
}
@Test
void testComponentRead() {
componentService.deleteAllComponent();
final Component component = componentService.addComponent("c1", 3);
log.info(component.toString());
final Component findComponent = componentService.findComponent(component.getId());
log.info(findComponent.toString());
Assertions.assertEquals(component, findComponent);
}
@Test
void testComponentReadNotFound() {
componentService.deleteAllComponent();
Assertions.assertThrows(EntityNotFoundException.class, () -> componentService.findComponent(-1L));
}
@Test
void testComponentReadAll() {
componentService.deleteAllComponent();
componentService.addComponent("c1", 3);
componentService.addComponent("c2", 2);
final List<Component> components = componentService.findAllComponent();
log.info(components.toString());
Assertions.assertEquals(components.size(), 2);
}
@Test
void testComponentReadAllEmpty() {
componentService.deleteAllComponent();
final List<Component> components = componentService.findAllComponent();
log.info(components.toString());
Assertions.assertEquals(components.size(), 0);
}
@Test
void testProductCreate() {
productService.deleteAllProduct();
componentService.deleteAllComponent();
final Component component1 = componentService.addComponent("c1", 3);
final Component component2 = componentService.addComponent("c2", 2);
final Component component3 = componentService.addComponent("c3", 3);
ArrayList<Component> components = new ArrayList<>();
components.add(component1);
components.add(component2);
components.add(component3);
final Product product = productService.addProduct("p", 300, components);
log.info(product.toString());
final Product product1 = productService.findProduct(product.getId());
Assertions.assertTrue(product1.getComponents().contains(component1));
Assertions.assertEquals(product,product1);
productService.deleteAllProduct();
Assertions.assertEquals(productService.findAllProduct().size(), 0);
Assertions.assertThrows(EntityNotFoundException.class, () -> productService.findProduct(-1L));
}
@Test
void testProductReadNotFound() {
productService.deleteAllProduct();
Assertions.assertThrows(EntityNotFoundException.class, () -> productService.findProduct(-1L));
}
@Test
void testProductReadAll() {
productService.deleteAllProduct();
final List<Product> products = productService.findAllProduct();
log.info(products.toString());
Assertions.assertEquals(products.size(), 0);
}
@Test
void testProductReadAllEmpty() {
productService.deleteAllProduct();
final List<Product> products = productService.findAllProduct();
log.info(products.toString());
Assertions.assertEquals(products.size(), 0);
}
@Test
void testOrderCreate() {
productService.deleteAllProduct();
componentService.deleteAllComponent();
ordService.deleteAllOrd();
final Component component1 = componentService.addComponent("c1", 3);
final Component component2 = componentService.addComponent("c2", 2);
final Component component3 = componentService.addComponent("c3", 3);
ArrayList<Component> components = new ArrayList<>();
components.add(component1);
components.add(component2);
components.add(component3);
final Product product = productService.addProduct("p", 300, components);
ArrayList<Product> products = new ArrayList<>();
products.add(product);
final Order ord = ordService.addOrd(new Date(), 3, products);
ordService.addOrd(new Date(), 4,products);
ordService.addOrd(new Date(), 5,products);
ordService.addOrd(new Date(), 6,products);
log.info(ord.toString());
Assertions.assertEquals(3, ordService.findOrd(ord.getId()).getProducts().get(0).getComponents().size());
Assertions.assertEquals(1, ordService.findOrd(ord.getId()).getProducts().size());
Assertions.assertEquals(4, ordService.findAllOrd().size());
final Order ord1 = ordService.findOrd(ord.getId());
Assertions.assertEquals(ord1, ord);
ordService.deleteAllOrd();
Assertions.assertThrows(EntityNotFoundException.class, () -> ordService.findOrd(-1L));
Assertions.assertEquals(0, ordService.findAllOrd().size());
}
@Test
void testDeleteCascade() {
productService.deleteAllProduct();
componentService.deleteAllComponent();
ordService.deleteAllOrd();
final Component component1 = componentService.addComponent("c1", 3);
final Component component2 = componentService.addComponent("c2", 2);
final Component component3 = componentService.addComponent("c3", 3);
ArrayList<Component> components = new ArrayList<>();
components.add(component1);
components.add(component2);
components.add(component3);
final Product product = productService.addProduct("p1", 300, components);
ArrayList<Product> products = new ArrayList<>();
products.add(product);
final Order ord = ordService.addOrd(new Date(), 3, products);
Assertions.assertEquals(ordService.findAllOrd().size(), 1);
componentService.deleteComponent(component1.getId());
Assertions.assertEquals(ordService.findAllOrd().size(), 0);
}
@Test
void testProductAddedToOrder(){
productService.deleteAllProduct();
componentService.deleteAllComponent();
ordService.deleteAllOrd();
final Component component1 = componentService.addComponent("c1", 3);
final Component component2 = componentService.addComponent("c2", 2);
final Component component3 = componentService.addComponent("c3", 3);
ArrayList<Component> components = new ArrayList<>();
components.add(component1);
components.add(component2);
components.add(component3);
final Product product = productService.addProduct("p1", 300, components);
ArrayList<Product> products = new ArrayList<>();
products.add(product);
final Order ord = ordService.addOrd(new Date(), 3, products);
Assertions.assertEquals(ordService.findAllOrd().size(), 1);
Assertions.assertTrue(ord.getProducts().contains(product));
}
@Test
void testCount(){
productService.deleteAllProduct();
componentService.deleteAllComponent();
ordService.deleteAllOrd();
final Component component1 = componentService.addComponent("c1", 3);
final Component component2 = componentService.addComponent("c2", 2);
final Component component3 = componentService.addComponent("c3", 3);
final Component component4 = componentService.addComponent("c4", 3);
ArrayList<Component> components = new ArrayList<>();
components.add(component1);
components.add(component2);
components.add(component3);
final Product product1 = productService.addProduct("p1", 300, components);
ArrayList<Product> products = new ArrayList<>();
products.add(product1);
components.add(component4);
final Product product2 = productService.addProduct("p1", 300, components);
products.add(product2);
final Order ord = ordService.addOrd(new Date(), 3, products);
Assertions.assertEquals(ordService.findAllOrd().size(), 1);
Assertions.assertEquals(ordService.getCountComponentFromOrder(ord.getId()),7 );
}
}

View File

@ -1,6 +1,6 @@
package com.example.demo;
import method.service.MethodService;
import com.example.demo.method.service.MethodService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;