Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 93464f7382 | |||
| 72166d3a35 | |||
| c8f79a0d98 | |||
| a3de182a22 | |||
| 1423f5da0b | |||
| 21c085917a | |||
| f3f0e851ed |
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@@ -1,6 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="jpab" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -15,6 +15,11 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'com.h2database:h2:2.1.210'
|
||||||
|
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||||
|
implementation 'org.hibernate.validator:hibernate-validator:7.0.1.Final'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
|
|||||||
BIN
data.mv.db
Normal file
BIN
data.mv.db
Normal file
Binary file not shown.
@@ -1,44 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
|
|
||||||
<title>Калькулятор</title>
|
|
||||||
</head>
|
|
||||||
<body class="m-5">
|
|
||||||
<h1>Калькулятор</h1>
|
|
||||||
|
|
||||||
<form class="" id="form">
|
|
||||||
<div class="row my-3">
|
|
||||||
<div class="col-md-3">
|
|
||||||
<input name="num1" input type="text" class="form-control" placeholder="Первый аргумент">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<input name="num2" input type="text" class="form-control" placeholder="Второй аргумент">
|
|
||||||
</div>
|
|
||||||
<div class = "col-md-2">
|
|
||||||
<select class="form-select" name="selected" aria-label="Default select example">
|
|
||||||
<option selected>Действие</option>
|
|
||||||
<option value="1">+</option>
|
|
||||||
<option value="2">-</option>
|
|
||||||
<option value="3">*</option>
|
|
||||||
<option value="4">/</option>
|
|
||||||
<option value="5">%</option>
|
|
||||||
<option value="6">con</option>
|
|
||||||
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-success">Выполнить</button>
|
|
||||||
<div class="my-2 col-md-3">
|
|
||||||
<input name="res" input type="text" class="form-control " placeholder="Результат">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<script src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
|
||||||
<script src="../js/script.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
let form = document.getElementById("form");
|
|
||||||
let info = document.getElementById("res");
|
|
||||||
|
|
||||||
form.onsubmit = async (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
if(form.num1.value === "") return;
|
|
||||||
if(form.num2.value === "") return;
|
|
||||||
|
|
||||||
let index = form.selected.selectedIndex;
|
|
||||||
let op = form.selected.options[index].textContent;
|
|
||||||
let res = "";
|
|
||||||
|
|
||||||
function chooseOperation(oper){
|
|
||||||
switch(oper){
|
|
||||||
case "+":
|
|
||||||
return "sum"
|
|
||||||
case "-":
|
|
||||||
return "diff"
|
|
||||||
case "*":
|
|
||||||
return "mul"
|
|
||||||
case "/":
|
|
||||||
return "div"
|
|
||||||
case "%":
|
|
||||||
return "ost"
|
|
||||||
case "con":
|
|
||||||
return "con"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let operstor = chooseOperation(op)
|
|
||||||
if(form.num2.value == 0) return;
|
|
||||||
res = await fetch(`http://localhost:8080/${operstor}?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
res = await res.text();
|
|
||||||
|
|
||||||
// switch(op) {
|
|
||||||
// case "+":
|
|
||||||
// res = await fetch(`http://localhost:8080/sum?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
// case "-":
|
|
||||||
// res = await fetch(`http://localhost:8080/diff?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case "*":
|
|
||||||
// res = await fetch(`http://localhost:8080/mul?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case "/":
|
|
||||||
// if(form.num2.value == 0) return;
|
|
||||||
// res = await fetch(`http://localhost:8080/div?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case "%":
|
|
||||||
// if(form.num2.value == 0) return;
|
|
||||||
// res = await fetch(`http://localhost:8080/ost?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case "con":
|
|
||||||
// res = await fetch(`http://localhost:8080/con?num1=${form.num1.value}&num2=${form.num2.value}`)
|
|
||||||
// res = await res.text();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
form.res.value = res;
|
|
||||||
}
|
|
||||||
30233
front/package-lock.json
generated
30233
front/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,43 @@
|
|||||||
{
|
{
|
||||||
"name": "front",
|
"name": "my-app",
|
||||||
"version": "1.0.0",
|
"version": "0.1.0",
|
||||||
"description": "",
|
"private": true,
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "http-server -p 3000 -c-1 -o ./"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
|
"@testing-library/react": "^13.4.0",
|
||||||
|
"@testing-library/user-event": "^13.5.0",
|
||||||
"bootstrap": "^5.2.3",
|
"bootstrap": "^5.2.3",
|
||||||
"http-server": "^14.1.1"
|
"json-server": "^0.17.1",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"react-router-dom": "^6.4.5",
|
||||||
|
"react-scripts": "5.0.1",
|
||||||
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"fake-server": "json-server data.json -p 8079",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
front/src/components/catalogs/CatalogCommunities.jsx
Normal file
47
front/src/components/catalogs/CatalogCommunities.jsx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import Catalog from "../common/Catalog";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import DataService from "../../services/DataService";
|
||||||
|
|
||||||
|
let headers = [
|
||||||
|
{label: "name", text: "Имя"},
|
||||||
|
]
|
||||||
|
|
||||||
|
export default function CatalogActors() {
|
||||||
|
const url = "/communities";
|
||||||
|
|
||||||
|
const [data, setData] = useState({
|
||||||
|
name: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const [communities, setCommunities] = useState([]);
|
||||||
|
|
||||||
|
function handleFormChange(e) {
|
||||||
|
setData({ ...data, [e.target.id]: e.target.value })
|
||||||
|
}
|
||||||
|
|
||||||
|
//уточнить
|
||||||
|
function onAdd() {
|
||||||
|
setData({name: "", music: communities[0]});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onChange(data) {
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate(data) {
|
||||||
|
if(data.name === "") return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Catalog url={url} headers={headers} data={data} onAdd={onAdd} onChange={onChange} validate={validate}>
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="name" className="form-label">Имя</label>
|
||||||
|
<input type="text" value={data.name} id="name" className="form-control" required autoComplete="off"
|
||||||
|
onChange={handleFormChange}/>
|
||||||
|
</div>
|
||||||
|
</Catalog>
|
||||||
|
)
|
||||||
|
}
|
||||||
145
front/src/components/catalogs/CatalogUsers.jsx
Normal file
145
front/src/components/catalogs/CatalogUsers.jsx
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
import Catalog from "../common/Catalog";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import DataService from "../../services/DataService"
|
||||||
|
|
||||||
|
let headers = [
|
||||||
|
{label: "name", text: "Имя"},
|
||||||
|
{label: "music", text: "Музыка"},
|
||||||
|
{label: "fullNames", text: "Группы"}
|
||||||
|
]
|
||||||
|
export default function CatalogUsers() {
|
||||||
|
const url = "/users";
|
||||||
|
|
||||||
|
const [data, setData] = useState({
|
||||||
|
name: "",
|
||||||
|
music: [],
|
||||||
|
fullNames: []
|
||||||
|
});
|
||||||
|
|
||||||
|
const [selectedData, setSelectedData] = useState({
|
||||||
|
music: "",
|
||||||
|
community: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
const [musics, setMusics] = useState([]);
|
||||||
|
const [communities, setCommunities] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let music;
|
||||||
|
DataService.readAll("/musics").then(res => {
|
||||||
|
setMusics(res)
|
||||||
|
music = res[0].name;
|
||||||
|
}).then(() => (
|
||||||
|
DataService.readAll("/communities")
|
||||||
|
)).then(res => {
|
||||||
|
setCommunities(res)
|
||||||
|
setSelectedData({music, community: res[0].name});
|
||||||
|
});
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
function handleFormChange(e) {
|
||||||
|
console.log(e.target.value);
|
||||||
|
setData({ ...data, [e.target.id]: e.target.value })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChangeSelected(e) {
|
||||||
|
setSelectedData({...selectedData, [e.target.id]: e.target.value});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMusic() {
|
||||||
|
for(let g of data.music) {
|
||||||
|
if(g == selectedData.music) return;
|
||||||
|
}
|
||||||
|
let temp = data.music.slice(0);
|
||||||
|
temp.push(selectedData.music);
|
||||||
|
setData({...data, music: temp});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCommunity() {
|
||||||
|
for(let a of data.fullNames) {
|
||||||
|
if(a == selectedData.community) return;
|
||||||
|
}
|
||||||
|
let temp = data.fullNames.slice(0);
|
||||||
|
temp.push(selectedData.community);
|
||||||
|
setData({...data, fullNames: temp});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteMusic(e) {
|
||||||
|
let musicName = e.target.previousSibling.textContent;
|
||||||
|
let temp = data.music.filter(x => (x != musicName));
|
||||||
|
setData({...data, music: temp})
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCommunity(e) {
|
||||||
|
let communityName = e.target.previousSibling.textContent;
|
||||||
|
let temp = data.fullNames.filter(x => (x != communityName));
|
||||||
|
setData({...data, fullNames: temp})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAdd() {
|
||||||
|
setData({name: "", music: [], fullNames: []});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onChange(data) {
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate(data) {
|
||||||
|
if(data.name === "") return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Catalog url={url} headers={headers} data={data} onAdd={onAdd} onChange={onChange} validate={validate}>
|
||||||
|
<div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="name" className="form-label">Название</label>
|
||||||
|
<input type="text" value={data.name} id="name" className="form-control" required autoComplete="off"
|
||||||
|
onChange={handleFormChange}/>
|
||||||
|
</div>
|
||||||
|
<select id="music" className="form-select" required
|
||||||
|
value={selectedData.music} onChange={handleChangeSelected}>
|
||||||
|
<option disabled value="">Укажите музыку</option>
|
||||||
|
{
|
||||||
|
musics.map(({name, id}) =>
|
||||||
|
<option key={id} value={name}>{name}</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
{
|
||||||
|
data.music.map(value => (
|
||||||
|
<div className="badge bg-secondary m-1" key={value}>
|
||||||
|
<span>{value}</span>
|
||||||
|
<button className="btn-close bg-danger m-1" onClick={deleteMusic}></button>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
<br></br>
|
||||||
|
<button onClick={addMusic} className="btn btn-success">Добавить музыку</button>
|
||||||
|
|
||||||
|
<select id="community" className="form-select" required
|
||||||
|
value={selectedData.community} onChange={handleChangeSelected}>
|
||||||
|
<option disabled value="">Укажите группу</option>
|
||||||
|
{
|
||||||
|
communities.map(({name, id}) =>
|
||||||
|
<option key={id} value={name}>{name}</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
{
|
||||||
|
data.fullNames.map(value => (
|
||||||
|
<div className="badge bg-secondary m-1" key={value}>
|
||||||
|
<span>{value}</span>
|
||||||
|
<button className="btn-close bg-danger m-1" onClick={deleteCommunity}></button>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
<br></br>
|
||||||
|
<button onClick={addCommunity} className="btn btn-success">Добавить группу</button>
|
||||||
|
</div>
|
||||||
|
</Catalog>
|
||||||
|
)
|
||||||
|
}
|
||||||
15
front/src/components/pages/User.jsx
Normal file
15
front/src/components/pages/User.jsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import playIcon from "../../img/play.png";
|
||||||
|
import "./Contacts.css";
|
||||||
|
|
||||||
|
export default function User() {
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<div class="player">
|
||||||
|
<div class="player__menu">
|
||||||
|
<button class="player__button"><img class="player__button-img" src={playIcon} alt=""/></button>
|
||||||
|
<div class="player__progress"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
21
front/src/components/pages/Users.jsx
Normal file
21
front/src/components/pages/Users.jsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import Banner from "../Banner";
|
||||||
|
|
||||||
|
export default function Users() {
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<section className="categories">
|
||||||
|
|
||||||
|
<h2 className="text-white">Музыка</h2>
|
||||||
|
<div className="btn-group">
|
||||||
|
<button className="btn btn-success">Комедии</button>
|
||||||
|
<button className="btn btn-success">Драмы</button>
|
||||||
|
<button className="btn btn-success">Трилер</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section className="banner">
|
||||||
|
<h2 className="text-white">Все фильмы</h2>
|
||||||
|
<Banner images={images}/>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
25
front/src/components/reports/ReportUsers.jsx
Normal file
25
front/src/components/reports/ReportUsers.jsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import Catalog from "../common/Catalog";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import DataService from "../../services/DataService"
|
||||||
|
import Table from "../common/Table";
|
||||||
|
|
||||||
|
import ReportSelector from "./ReportSelector";
|
||||||
|
|
||||||
|
let headers = [
|
||||||
|
{label: "name", text: "Имя"},
|
||||||
|
{label: "music", text: "Музыка"}
|
||||||
|
]
|
||||||
|
|
||||||
|
export default function ReportsFilms() {
|
||||||
|
const [url, setUrl] = useState("/users?music=mus1");
|
||||||
|
|
||||||
|
function formData(music) {
|
||||||
|
console.log(music);
|
||||||
|
setUrl("/users?music=" + music);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReportSelector headers={headers} url={url} formData={formData}/>
|
||||||
|
)
|
||||||
|
}
|
||||||
BIN
front/src/img/play.png
Normal file
BIN
front/src/img/play.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
@@ -13,43 +13,4 @@ public class SbappApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SbappApplication.class, args);
|
SpringApplication.run(SbappApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/hello")
|
|
||||||
public String hello(){
|
|
||||||
return "Hello, world";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/sum")
|
|
||||||
public Integer sum(@RequestParam(defaultValue = "0")Integer num1,
|
|
||||||
@RequestParam(defaultValue = "0")Integer num2){
|
|
||||||
return num1 + num2;
|
|
||||||
}
|
|
||||||
@GetMapping("/div")
|
|
||||||
public Integer div(@RequestParam(defaultValue = "0")Integer num1,
|
|
||||||
@RequestParam(defaultValue = "0")Integer num2){
|
|
||||||
return num1 / num2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/mul")
|
|
||||||
public Integer mul(@RequestParam(defaultValue = "0")Integer num1,
|
|
||||||
@RequestParam(defaultValue = "0")Integer num2){
|
|
||||||
return num1 * num2;
|
|
||||||
}
|
|
||||||
@GetMapping("/diff")
|
|
||||||
public Integer diff(@RequestParam(defaultValue = "0")Integer num1,
|
|
||||||
@RequestParam(defaultValue = "0")Integer num2){
|
|
||||||
return num1 - num2;
|
|
||||||
}
|
|
||||||
@GetMapping("/ost")
|
|
||||||
public Integer ost(@RequestParam(defaultValue = "0")Integer num1,
|
|
||||||
@RequestParam(defaultValue = "0")Integer num2){
|
|
||||||
return num1 % num2;
|
|
||||||
}
|
|
||||||
@GetMapping("/con")
|
|
||||||
public String con(@RequestParam(defaultValue = "")String num1,
|
|
||||||
@RequestParam(defaultValue = "")String num2){
|
|
||||||
return num1.concat(num2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.is.sbapp.calculator.service.CalculatorService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class CalcController {
|
||||||
|
private final CalculatorService speakerService;
|
||||||
|
|
||||||
|
public CalcController(CalculatorService speakerService) {
|
||||||
|
this.speakerService = speakerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/sum")
|
||||||
|
public String Sum(@RequestParam(value = "first", defaultValue = "1") Object first,
|
||||||
|
@RequestParam(value = "second", defaultValue = "1") Object second,
|
||||||
|
@RequestParam(value = "type", defaultValue = "int") String type) {
|
||||||
|
return speakerService.Sum(first, second, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/minus")
|
||||||
|
public String Ras(@RequestParam(value = "first", defaultValue = "1") Object first,
|
||||||
|
@RequestParam(value = "second", defaultValue = "1") Object second,
|
||||||
|
@RequestParam(value = "type", defaultValue = "int") String type) {
|
||||||
|
return speakerService.Ras(first, second, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/reverse")
|
||||||
|
public String Pros(@RequestParam(value = "first", defaultValue = "1") Object first,
|
||||||
|
@RequestParam(value = "second", defaultValue = "1") Object second,
|
||||||
|
@RequestParam(value = "type", defaultValue = "int") String type) {
|
||||||
|
return speakerService.Rev(first, second, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/comparison")
|
||||||
|
public String Del(@RequestParam(value = "first", defaultValue = "1") Object first,
|
||||||
|
@RequestParam(value = "second", defaultValue = "1") Object second,
|
||||||
|
@RequestParam(value = "type", defaultValue = "int") String type) {
|
||||||
|
return speakerService.Com(first, second, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.domain;
|
||||||
|
|
||||||
|
public interface Calculator<T>{
|
||||||
|
public T Sum(T first, T second);
|
||||||
|
|
||||||
|
public T Minus(T first, T second);
|
||||||
|
|
||||||
|
public T Reverse(T first, T second);
|
||||||
|
|
||||||
|
public T Comparison(T first, T second);
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.domain;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
|
||||||
|
@Component(value="date")
|
||||||
|
public class DateCalculator implements Calculator<LocalDate> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate Sum(LocalDate first, LocalDate second) {
|
||||||
|
return first.plusYears(second.getYear()).
|
||||||
|
plusMonths(second.getMonthValue()).plusDays(second.getDayOfMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate Minus(LocalDate first, LocalDate second) {
|
||||||
|
return first.minusYears(second.getYear()).
|
||||||
|
minusMonths(second.getMonthValue()).minusDays(second.getDayOfMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate Reverse(LocalDate first, LocalDate second) {
|
||||||
|
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
|
||||||
|
String formattedFirst = first.format(formatter);
|
||||||
|
return LocalDate.parse(formattedFirst, formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate Comparison(LocalDate first, LocalDate second) {
|
||||||
|
int comparisonResult = first.compareTo(second);
|
||||||
|
|
||||||
|
if (comparisonResult < 0)
|
||||||
|
return second;
|
||||||
|
else return first;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.domain;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component(value="int")
|
||||||
|
public class IntCalculator implements Calculator<Integer>{
|
||||||
|
@Override
|
||||||
|
public Integer Sum(Integer x, Integer y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer Minus(Integer x, Integer y) {
|
||||||
|
return x - y;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Integer Reverse(Integer first, Integer second) {
|
||||||
|
return (first + second) * (-1);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Integer Comparison(Integer first, Integer second) {
|
||||||
|
if (first >= second)
|
||||||
|
return first;
|
||||||
|
else return second;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.domain;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component(value="string")
|
||||||
|
public class StringCalculator implements Calculator<String>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String Sum(String first, String second) {
|
||||||
|
return first.concat(second);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String Minus(String first, String second) {
|
||||||
|
String[] arr = first.split("");
|
||||||
|
for(int i = 0; i < first.length(); i++){
|
||||||
|
if (second.contains(arr[i])){
|
||||||
|
arr[i] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String.join("", arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String Reverse(String first, String second) {
|
||||||
|
String ourStr = first.concat(second);
|
||||||
|
StringBuilder newStr = new StringBuilder();
|
||||||
|
for(int i = ourStr.length() - 1; i >= 0; i--){
|
||||||
|
newStr.append(ourStr.charAt(i));
|
||||||
|
}
|
||||||
|
return newStr.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String Comparison(String first, String second) {
|
||||||
|
if (first.length() >= second.length())
|
||||||
|
return first;
|
||||||
|
else return second;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package ru.ulstu.is.sbapp.calculator.service;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.is.sbapp.calculator.domain.Calculator;
|
||||||
|
import ru.ulstu.is.sbapp.calculator.domain.DateCalculator;
|
||||||
|
import ru.ulstu.is.sbapp.calculator.domain.StringCalculator;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CalculatorService {
|
||||||
|
private final ApplicationContext _applicationContext;
|
||||||
|
|
||||||
|
public CalculatorService(ApplicationContext applicationContext) {
|
||||||
|
this._applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Sum(Object first, Object second, String type) {
|
||||||
|
final Calculator speaker = (Calculator) _applicationContext.getBean(type);
|
||||||
|
|
||||||
|
|
||||||
|
if (speaker instanceof StringCalculator)
|
||||||
|
return String.format("%s", speaker.Sum(first, second));
|
||||||
|
|
||||||
|
else if (speaker instanceof DateCalculator)
|
||||||
|
return String.format("%s", (speaker.Sum(LocalDate.parse(first.toString()), LocalDate.parse(second.toString()))));
|
||||||
|
|
||||||
|
else return String.format("%s", speaker.Sum(Integer.parseInt(first.toString()), Integer.parseInt(second.toString())));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Ras(Object first, Object second, String type) {
|
||||||
|
final Calculator speaker = (Calculator) _applicationContext.getBean(type);
|
||||||
|
if (speaker instanceof StringCalculator)
|
||||||
|
return String.format("%s", speaker.Minus(first,second));
|
||||||
|
|
||||||
|
else if (speaker instanceof DateCalculator)
|
||||||
|
return String.format("%s", (speaker.Minus(LocalDate.parse(first.toString()), LocalDate.parse(second.toString()))));
|
||||||
|
|
||||||
|
else
|
||||||
|
return String.format("%s", speaker.Minus(Integer.parseInt(first.toString()),Integer.parseInt(second.toString())));
|
||||||
|
}
|
||||||
|
public String Rev(Object first, Object second, String type) {
|
||||||
|
final Calculator speaker = (Calculator) _applicationContext.getBean(type);
|
||||||
|
if (speaker instanceof StringCalculator)
|
||||||
|
return String.format("%s", speaker.Reverse(first,second));
|
||||||
|
|
||||||
|
else if (speaker instanceof DateCalculator)
|
||||||
|
return String.format("%s", (speaker.Reverse(LocalDate.parse(first.toString()), LocalDate.parse(second.toString()))));
|
||||||
|
|
||||||
|
else return String.format("%s", speaker.Reverse(Integer.parseInt(first.toString()),Integer.parseInt(second.toString())));
|
||||||
|
|
||||||
|
}
|
||||||
|
public String Com(Object first, Object second, String type) {
|
||||||
|
final Calculator speaker = (Calculator) _applicationContext.getBean(type);
|
||||||
|
if (speaker instanceof StringCalculator)
|
||||||
|
return String.format("%s", speaker.Comparison(first,second));
|
||||||
|
|
||||||
|
else if (speaker instanceof DateCalculator)
|
||||||
|
return String.format("%s", (speaker.Comparison(LocalDate.parse(first.toString()), LocalDate.parse(second.toString()))));
|
||||||
|
|
||||||
|
else return String.format("%s", speaker.Comparison(Integer.parseInt(first.toString()), Integer.parseInt(second.toString())));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.dto.CommunityDTO;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.CommunityService;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/communities")
|
||||||
|
public class CommunityController {
|
||||||
|
private final CommunityService communityService;
|
||||||
|
|
||||||
|
public CommunityController(CommunityService communityService) {
|
||||||
|
this.communityService = communityService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public CommunityDTO getCommunity(@PathVariable Long id) {
|
||||||
|
return new CommunityDTO(communityService.findCommunity(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public List<CommunityDTO> getCommunities() {
|
||||||
|
return communityService.findAllCommunitys().stream().map(CommunityDTO::new).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public CommunityDTO createCommunity(@RequestBody @Valid CommunityDTO community) {
|
||||||
|
return new CommunityDTO(communityService.addCommunity(community.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("")
|
||||||
|
public CommunityDTO updateCommunity(@PathVariable Long id, @RequestBody @Valid CommunityDTO community) {
|
||||||
|
return new CommunityDTO(communityService.updateCommunity(id, community.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public CommunityDTO deleteCommunity(@PathVariable Long id) {
|
||||||
|
return new CommunityDTO(communityService.deleteCommunity(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.dto.MusicDTO;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.MusicService;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/musics")
|
||||||
|
public class MusicController {
|
||||||
|
private final MusicService musicService;
|
||||||
|
public MusicController(MusicService musicService){
|
||||||
|
this.musicService = musicService;
|
||||||
|
}
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public MusicDTO getMusic(@PathVariable Long id){
|
||||||
|
return new MusicDTO(musicService.findMusic(id));
|
||||||
|
}
|
||||||
|
@GetMapping("")
|
||||||
|
public List<MusicDTO> getMusics() {
|
||||||
|
return musicService.findAllMusics().stream().map(MusicDTO::new).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public MusicDTO createMusic(@RequestBody @Valid MusicDTO music) {
|
||||||
|
return new MusicDTO(musicService.addMusic(music.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/{id}")
|
||||||
|
public MusicDTO updateMusic(@PathVariable Long id,
|
||||||
|
@RequestBody @Valid MusicDTO music) {
|
||||||
|
return new MusicDTO(musicService.updateMusic(id, music.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public MusicDTO deleteMusic(@PathVariable Long id) {
|
||||||
|
return new MusicDTO(musicService.deleteMusic(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.dto.UserDTO;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.UserService;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/users")
|
||||||
|
public class UserController {
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public UserController(UserService userService){
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public UserDTO getUser(@PathVariable Long id) {
|
||||||
|
return new UserDTO(userService.findUser(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public List<UserDTO> getUsers() {
|
||||||
|
return userService.findAllUsers().stream().map(UserDTO::new).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.dto;
|
||||||
|
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommunityDTO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public CommunityDTO(){
|
||||||
|
}
|
||||||
|
public CommunityDTO(Community community){
|
||||||
|
this.id = community.getId();
|
||||||
|
this.name = community.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<UserModel> users;
|
||||||
|
|
||||||
|
public List<UserModel> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.dto;
|
||||||
|
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
|
||||||
|
public class MusicDTO {
|
||||||
|
private Long id;
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
public MusicDTO(){
|
||||||
|
}
|
||||||
|
public MusicDTO(Music music){
|
||||||
|
this.id = music.getId();
|
||||||
|
this.name = music.getName();
|
||||||
|
}
|
||||||
|
public Long getId() {return id;}
|
||||||
|
|
||||||
|
public String getName() {return name;}
|
||||||
|
public void setName(String name) {this.name = name;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "Music{" +
|
||||||
|
"id = " + id +
|
||||||
|
"name = " + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.dto;
|
||||||
|
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserDTO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
public UserDTO(){}
|
||||||
|
|
||||||
|
public UserDTO(UserModel user){
|
||||||
|
this.id = user.getId();
|
||||||
|
this.name = user.getName();
|
||||||
|
this.city = user.getCity();
|
||||||
|
}
|
||||||
|
private List<Music> musics;
|
||||||
|
private List<Community> communities;
|
||||||
|
|
||||||
|
public Long getId(){return id;}
|
||||||
|
|
||||||
|
public String getName(){return name;}
|
||||||
|
public void setName(String firstName){this.name = firstName;}
|
||||||
|
|
||||||
|
public void addMusic(Music g) {
|
||||||
|
musics.add(g);
|
||||||
|
}
|
||||||
|
public List<Music> getMusics() {
|
||||||
|
return musics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCommunity(Community g) {
|
||||||
|
communities.add(g);
|
||||||
|
}
|
||||||
|
public List<Community> getGroups() {
|
||||||
|
return communities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city){
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
public String getCity(){
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", city='" + city + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.models;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Community {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "communities")
|
||||||
|
private List<UserModel> users;
|
||||||
|
|
||||||
|
public Community() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Community(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public List<UserModel> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.models;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Music {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
|
||||||
|
public Music() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Music(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.models;
|
||||||
|
import org.hibernate.annotations.LazyCollection;
|
||||||
|
import org.hibernate.annotations.LazyCollectionOption;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class UserModel {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String city;
|
||||||
|
//поиск людей по городу
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@LazyCollection(LazyCollectionOption.FALSE)
|
||||||
|
@JoinTable(name="usermodels_musics",
|
||||||
|
joinColumns = @JoinColumn(name="usermodel_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name="music_id")
|
||||||
|
)
|
||||||
|
private List<Music> musics;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@LazyCollection(LazyCollectionOption.FALSE)
|
||||||
|
@JoinTable(name="usermodels_communities",
|
||||||
|
joinColumns = @JoinColumn(name="usermodel_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name="community_id")
|
||||||
|
)
|
||||||
|
private List<Community> communities;
|
||||||
|
|
||||||
|
public UserModel(){
|
||||||
|
}
|
||||||
|
public UserModel(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public UserModel(String name, String city){
|
||||||
|
this.name = name;
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
public void deleteMusics() {
|
||||||
|
musics = null;
|
||||||
|
}
|
||||||
|
public void deleteCommunities() {
|
||||||
|
communities = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId(){return id;}
|
||||||
|
|
||||||
|
public String getName(){return name;}
|
||||||
|
public void setName(String firstName){this.name = firstName;}
|
||||||
|
|
||||||
|
public void addMusic(Music g) {
|
||||||
|
musics.add(g);
|
||||||
|
}
|
||||||
|
public List<Music> getMusics() {
|
||||||
|
return musics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCommunity(Community g) {
|
||||||
|
communities.add(g);
|
||||||
|
}
|
||||||
|
public List<Community> getGroups() {
|
||||||
|
return communities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city){
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
public String getCity(){
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", city='" + city + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
|
||||||
|
public interface CommunityRepository extends JpaRepository<Community, Long> {
|
||||||
|
Community findByName(String name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
|
||||||
|
public interface MusicRepository extends JpaRepository<Music, Long> {
|
||||||
|
Music findByName(String name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<UserModel, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.services;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.repository.CommunityRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CommunityService {
|
||||||
|
|
||||||
|
private CommunityRepository repo;
|
||||||
|
|
||||||
|
public CommunityService(CommunityRepository repo){
|
||||||
|
this.repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Community addCommunity(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Community name is null or empty");
|
||||||
|
}
|
||||||
|
Community community = new Community(name);
|
||||||
|
return repo.save(community);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Community findCommunity(Long id) {
|
||||||
|
final Optional<Community> сommunity = repo.findById(id);
|
||||||
|
if (сommunity.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("Community with id [%s] is not found", id));
|
||||||
|
}
|
||||||
|
return сommunity.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<Community> findAllCommunitys() {
|
||||||
|
return repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Community updateCommunity(Long id, String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Music name is null or empty");
|
||||||
|
}
|
||||||
|
final Optional<Community> currentCommunityOpt = repo.findById(id);
|
||||||
|
|
||||||
|
if(currentCommunityOpt.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Community currentCommunity = currentCommunityOpt.get();
|
||||||
|
|
||||||
|
currentCommunity.setName(name);
|
||||||
|
return repo.save(currentCommunity);
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public Community findByName(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Genre name is null or empty");
|
||||||
|
}
|
||||||
|
return repo.findByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Community deleteCommunity(Long id) {
|
||||||
|
final Optional<Community> currentCommunity = repo.findById(id);
|
||||||
|
if(currentCommunity.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
repo.deleteById(id);
|
||||||
|
return currentCommunity.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteAllCommunitys() {
|
||||||
|
repo.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.repository.CommunityRepository;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.repository.MusicRepository;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MusicService {
|
||||||
|
|
||||||
|
private MusicRepository repo;
|
||||||
|
|
||||||
|
public MusicService(MusicRepository repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public Music addMusic(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Music name is null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Music music = new Music(name);
|
||||||
|
|
||||||
|
return repo.save(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Music findMusic(Long id) {
|
||||||
|
|
||||||
|
final Optional<Music> music = repo.findById(id);
|
||||||
|
if (music.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("Music with id [%s] is not found", id));
|
||||||
|
}
|
||||||
|
return music.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<Music> findAllMusics() {
|
||||||
|
return repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Music updateMusic(Long id, String name) {
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Music name is null or empty");
|
||||||
|
}
|
||||||
|
final Optional<Music> currentMusicOpt = repo.findById(id);
|
||||||
|
|
||||||
|
if(currentMusicOpt.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Music currentMusic = currentMusicOpt.get();
|
||||||
|
|
||||||
|
currentMusic.setName(name);
|
||||||
|
return repo.save(currentMusic);
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public Music findByName(String name) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("Music name is null or empty");
|
||||||
|
}
|
||||||
|
return repo.findByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Music deleteMusic(Long id) {
|
||||||
|
|
||||||
|
final Optional<Music> currentMusic = repo.findById(id);
|
||||||
|
if(currentMusic.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.deleteById(id);
|
||||||
|
return currentMusic.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteAllMusics() {
|
||||||
|
repo.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package ru.ulstu.is.sbapp.socialNetwork.services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.repository.UserRepository;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
private UserRepository repo;
|
||||||
|
|
||||||
|
private CommunityService communityService;
|
||||||
|
private MusicService musicService;
|
||||||
|
|
||||||
|
public UserService(UserRepository repo, MusicService musicService, CommunityService communityService) {
|
||||||
|
this.repo = repo;
|
||||||
|
this.musicService = musicService;
|
||||||
|
this.communityService = communityService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public UserModel addUser(String name, String city) {
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("User name is null or empty");
|
||||||
|
}
|
||||||
|
UserModel user = new UserModel(name, city);
|
||||||
|
return repo.save(user);
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public UserModel addMusic(Long userId, Long musicId) {
|
||||||
|
final Optional<UserModel> userOpt= repo.findById(userId);
|
||||||
|
|
||||||
|
if (userOpt.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", musicId));
|
||||||
|
}
|
||||||
|
|
||||||
|
UserModel user = userOpt.get();
|
||||||
|
|
||||||
|
final Music music = musicService.findMusic(musicId);
|
||||||
|
if (music == null) {
|
||||||
|
throw new EntityNotFoundException(String.format("Music with id [%s] is not found", musicId));
|
||||||
|
}
|
||||||
|
|
||||||
|
user.addMusic(music);
|
||||||
|
return repo.save(user);
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public UserModel addCommunity(Long userId, Long communityId) {
|
||||||
|
final Optional<UserModel> userOpt = repo.findById(userId);
|
||||||
|
|
||||||
|
if (userOpt.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("User with id [%s] is not found", userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
UserModel user = userOpt.get();
|
||||||
|
|
||||||
|
final Community community = communityService.findCommunity(communityId);
|
||||||
|
if (community == null) {
|
||||||
|
throw new EntityNotFoundException(String.format("Community with id [%s] is not found", communityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
user.addCommunity(community);
|
||||||
|
return repo.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public UserModel findUser(Long id) {
|
||||||
|
|
||||||
|
final Optional<UserModel> user = repo.findById(id);
|
||||||
|
if (user.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("UserModel with id [%s] is not found", id));
|
||||||
|
}
|
||||||
|
return user.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Transactional(readOnly = true)
|
||||||
|
// public List<UserModel> findUserByCity(String city){
|
||||||
|
// Query query = em.createQuery("select u from UserModel u where u.city = :city",
|
||||||
|
// UserModel.class).setParameter("city", city);
|
||||||
|
// List<UserModel> result = query.getResultList();
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<UserModel> findAllUsers() {
|
||||||
|
return repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public UserModel updateUser(Long id, String name) {
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
throw new IllegalArgumentException("User name is null or empty");
|
||||||
|
}
|
||||||
|
final Optional<UserModel> currentUserOpt = repo.findById(id);
|
||||||
|
|
||||||
|
if(currentUserOpt.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final UserModel currentUser = currentUserOpt.get();
|
||||||
|
|
||||||
|
currentUser.setName(name);
|
||||||
|
return repo.save(currentUser);
|
||||||
|
}
|
||||||
|
//update community, musics
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public UserModel updateCommunities(Long userId , List<String> communities) {
|
||||||
|
final Optional<UserModel> userOpt = repo.findById(userId);
|
||||||
|
|
||||||
|
if (userOpt.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("UserModel with id [%s] is not found", userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
UserModel user = userOpt.get();
|
||||||
|
|
||||||
|
user.deleteCommunities();
|
||||||
|
|
||||||
|
for(String c : communities) {
|
||||||
|
Community community = communityService.findByName(c);
|
||||||
|
user.addCommunity(community);
|
||||||
|
}
|
||||||
|
return repo.save(user);
|
||||||
|
}
|
||||||
|
@Transactional
|
||||||
|
public UserModel updateMusics(Long userId , List<String> musics) {
|
||||||
|
final Optional<UserModel> userOpt = repo.findById(userId);
|
||||||
|
|
||||||
|
if (userOpt.isEmpty()) {
|
||||||
|
throw new EntityNotFoundException(String.format("Music with id [%s] is not found", userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
UserModel user = userOpt.get();
|
||||||
|
|
||||||
|
user.deleteMusics();
|
||||||
|
|
||||||
|
for(String m : musics) {
|
||||||
|
Music music = musicService.findByName(m);
|
||||||
|
user.addMusic(music);
|
||||||
|
}
|
||||||
|
return repo.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public UserModel deleteUser(Long id) {
|
||||||
|
|
||||||
|
final Optional<UserModel> currentUser = repo.findById(id);
|
||||||
|
if(currentUser.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.deleteById(id);
|
||||||
|
return currentUser.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteAllUsers() {
|
||||||
|
repo.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1 +1,11 @@
|
|||||||
|
spring.main.banner-mode=off
|
||||||
|
#server.port=8080
|
||||||
|
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
|
||||||
|
|||||||
95
src/test/java/ru/ulstu/is/sbapp/JpaCommunityTest.java
Normal file
95
src/test/java/ru/ulstu/is/sbapp/JpaCommunityTest.java
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
package ru.ulstu.is.sbapp;
|
||||||
|
|
||||||
|
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 ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.CommunityService;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.UserService;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JpaCommunityTest {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JpaUserTest.class);
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CommunityService communityService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserCreate() {
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT");
|
||||||
|
log.info(community.toString());
|
||||||
|
Assertions.assertNotNull(community.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserReadNotFound() {
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> communityService.findCommunity(-1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findUser() {
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT");
|
||||||
|
log.info(community.toString());
|
||||||
|
final Community findCommunity = communityService.findCommunity(community.getId());
|
||||||
|
log.info(findCommunity.toString());
|
||||||
|
Assertions.assertEquals(community.toString(), findCommunity.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReadAll() {
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT");
|
||||||
|
log.info(community.toString());
|
||||||
|
final List<Community> communitys = communityService.findAllCommunitys();
|
||||||
|
Assertions.assertEquals(communitys.size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateCommunity() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT 2");
|
||||||
|
communityService.updateCommunity(community.getId(), "CodeGPT 3");
|
||||||
|
final Community findCommunity = communityService.findCommunity(community.getId());
|
||||||
|
log.info(findCommunity.toString());
|
||||||
|
Assertions.assertEquals(findCommunity.getName(), "CodeGPT 3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteCommunity() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT");
|
||||||
|
log.info(community.toString());
|
||||||
|
communityService.deleteCommunity(community.getId());
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> communityService.findCommunity(community.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addUser() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
communityService.deleteAllCommunitys();
|
||||||
|
userService.findAllUsers();
|
||||||
|
final Community community = communityService.addCommunity("CodeGPT");
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
userService.addCommunity(user.getId(), community.getId());
|
||||||
|
final Community findCommunity = communityService.findCommunity(community.getId());
|
||||||
|
Assertions.assertEquals(findCommunity.getUsers().get(0).getId(), user.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
77
src/test/java/ru/ulstu/is/sbapp/JpaMusicTest.java
Normal file
77
src/test/java/ru/ulstu/is/sbapp/JpaMusicTest.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package ru.ulstu.is.sbapp;
|
||||||
|
|
||||||
|
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 ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.MusicService;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.UserService;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JpaMusicTest {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JpaUserTest.class);
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MusicService musicService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMusicCreate() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
log.info(music.toString());
|
||||||
|
Assertions.assertNotNull(music.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMusicReadNotFound() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> musicService.findMusic(-1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findMusic() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
log.info(musicService.toString());
|
||||||
|
final Music findMusic = musicService.findMusic(music.getId());
|
||||||
|
log.info(findMusic.toString());
|
||||||
|
Assertions.assertEquals(music.toString(), findMusic.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReadAll() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
log.info(music.toString());
|
||||||
|
final List<Music> musics = musicService.findAllMusics();
|
||||||
|
Assertions.assertEquals(musics.size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateMusic() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
musicService.updateMusic(music.getId(), "Song 2");
|
||||||
|
final Music findMusic = musicService.findMusic(music.getId());
|
||||||
|
log.info(findMusic.toString());
|
||||||
|
Assertions.assertEquals(findMusic.getName(), "Song 2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteMusic() {
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
log.info(music.toString());
|
||||||
|
musicService.deleteMusic(music.getId());
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> userService.findUser(music.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
113
src/test/java/ru/ulstu/is/sbapp/JpaUserTest.java
Normal file
113
src/test/java/ru/ulstu/is/sbapp/JpaUserTest.java
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package ru.ulstu.is.sbapp;
|
||||||
|
|
||||||
|
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 ru.ulstu.is.sbapp.socialNetwork.models.Community;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.Music;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.models.UserModel;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.CommunityService;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.MusicService;
|
||||||
|
import ru.ulstu.is.sbapp.socialNetwork.services.UserService;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JpaUserTest {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JpaUserTest.class);
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MusicService musicService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CommunityService communityService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserCreate() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
log.info(user.toString());
|
||||||
|
Assertions.assertNotNull(user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUserReadNotFound() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> userService.findUser(-1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findUser() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
log.info(user.toString());
|
||||||
|
final UserModel findUser = userService.findUser(user.getId());
|
||||||
|
log.info(findUser.toString());
|
||||||
|
Assertions.assertEquals(user.toString(), findUser.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateUser() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
userService.updateUser(user.getId(), "its_mailov 2");
|
||||||
|
final UserModel findUser = userService.findUser(user.getId());
|
||||||
|
log.info(findUser.toString());
|
||||||
|
Assertions.assertEquals(findUser.getName(), "its_mailov 2");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReadAll() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
log.info(user.toString());
|
||||||
|
final List<UserModel> users = userService.findAllUsers();
|
||||||
|
Assertions.assertEquals(users.size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteUser() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
log.info(user.toString());
|
||||||
|
userService.deleteUser(user.getId());
|
||||||
|
Assertions.assertThrows(EntityNotFoundException.class, () -> userService.findUser(user.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addMusic() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
final Music music = musicService.addMusic("Song");
|
||||||
|
|
||||||
|
userService.addMusic(user.getId(), music.getId());
|
||||||
|
|
||||||
|
final UserModel findUser = userService.findUser(user.getId());
|
||||||
|
Assertions.assertEquals(findUser.getMusics().get(0).toString(), music.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addGroup() {
|
||||||
|
userService.deleteAllUsers();
|
||||||
|
musicService.deleteAllMusics();
|
||||||
|
final UserModel user = userService.addUser("its_mailov", "Moscow");
|
||||||
|
final Community community = communityService.addCommunity("GPT");
|
||||||
|
|
||||||
|
userService.addCommunity(user.getId(), community.getId());
|
||||||
|
|
||||||
|
final UserModel findUser = userService.findUser(user.getId());
|
||||||
|
Assertions.assertEquals(findUser.getGroups().get(0).getId(), community.getId());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,78 @@
|
|||||||
package ru.ulstu.is.sbapp;
|
package ru.ulstu.is.sbapp;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import ru.ulstu.is.sbapp.calculator.service.CalculatorService;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class SbappApplicationTests {
|
class SbappApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CalculatorService calculatorService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
void testPlusInt() {
|
||||||
|
final String res = calculatorService.Sum(10, 10, "int");
|
||||||
|
Assertions.assertEquals(20, Integer.parseInt(res));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testMinusInt() {
|
||||||
|
final String res = calculatorService.Ras(8, 4, "int");
|
||||||
|
Assertions.assertEquals(4, Integer.parseInt(res));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testReverseInt() {
|
||||||
|
final String res = calculatorService.Rev(10, 10, "int");
|
||||||
|
Assertions.assertEquals(-20, Integer.parseInt(res));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testComparisonInt() {
|
||||||
|
final String res = calculatorService.Com(8, 4, "int");
|
||||||
|
Assertions.assertEquals(8, Integer.parseInt(res));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testPlusStr() {
|
||||||
|
final String res = calculatorService.Sum("10", "10", "string");
|
||||||
|
Assertions.assertEquals("1010", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testMinusStr() {
|
||||||
|
final String res = calculatorService.Ras("846734", "4", "string");
|
||||||
|
Assertions.assertEquals("8673", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testReverseStr() {
|
||||||
|
final String res = calculatorService.Rev("846734", "312", "string");
|
||||||
|
Assertions.assertEquals("213437648", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testComparisonStr() {
|
||||||
|
final String res = calculatorService.Com("846734", "312", "string");
|
||||||
|
Assertions.assertEquals("846734", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testNumberFormatException() {
|
||||||
|
Assertions.assertThrows(NumberFormatException.class, () -> calculatorService.Sum("п", 3, "int"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testSumDate(){
|
||||||
|
final String res = calculatorService.Sum("2023-07-07", "0001-01-03", "date");
|
||||||
|
Assertions.assertEquals("2024-08-10", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testRasDate(){
|
||||||
|
final String res = calculatorService.Ras("2023-07-07", "2020-01-03", "date");
|
||||||
|
Assertions.assertEquals("0003-06-04", res);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void testComDate(){
|
||||||
|
final String res = calculatorService.Com("2023-07-07", "2020-01-03", "date");
|
||||||
|
Assertions.assertEquals("2023-07-07", res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user