Compare commits

...

19 Commits

Author SHA1 Message Date
33b58d7833 + 2023-06-13 20:38:22 +04:00
a89a7e0b87 Add front 2023-06-13 19:54:06 +04:00
353639c22f add report 2023-06-13 19:46:18 +04:00
c96cf40dee fix front 2023-06-11 11:03:28 +04:00
4b69a4ff4b add front 2023-05-25 15:06:02 +04:00
17f2a1e768 return 2023-05-16 12:44:18 +04:00
0962373581 try to fix 2023-05-16 12:09:24 +04:00
cb32409374 first part of front 2023-05-13 21:18:04 +04:00
95f1c8f46c fix 2023-05-09 19:18:27 +04:00
69fef2a6c7 add controllers 2023-05-09 18:39:37 +04:00
50b50ebe0d add service and dto 2023-05-09 17:22:39 +04:00
a48605b616 add repository 2023-05-09 16:05:51 +04:00
7021f82f56 add connection one-to-many 2023-04-15 10:30:54 +04:00
8fca73e0a4 add entity company 2023-04-02 17:32:05 +04:00
3823e88121 thirdLabWork 2023-03-06 15:49:54 +04:00
d60fbbe32f add tests 2023-03-06 13:21:05 +04:00
f9143fb60b add tests 2023-02-27 23:47:21 +04:00
92b0a14a00 second lab work 2023-02-27 23:32:16 +04:00
8f133c177d clear 2023-02-20 14:20:58 +04:00
59 changed files with 15562 additions and 66 deletions

2
.gitignore vendored
View File

@ -4,7 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
node_modules
### STS ###
.apt_generated
.classpath

Binary file not shown.

View File

@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\C:\\Users\\Alena\\Source\\Repos\\IP_PIbd-21_Yakhontov_OU",
"PreviewInSolutionExplorer": false
}

View File

@ -4,7 +4,7 @@ plugins {
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'LabWork'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
@ -14,9 +14,18 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.1.210'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
}
jar {
manifest {
attributes(
'Main-Class': 'com.example.demo'
)
}
}
tasks.named('test') {
useJUnitPlatform()
}

BIN
data.mv.db Normal file

Binary file not shown.

1564
data.trace.db Normal file

File diff suppressed because it is too large Load Diff

23
frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

24
frontend/README.md Normal file
View File

@ -0,0 +1,24 @@
# project
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

5
frontend/babel.config.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

19
frontend/jsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es6",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}

11857
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

50
frontend/package.json Normal file
View File

@ -0,0 +1,50 @@
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"bootstrap-vue": "^2.23.1",
"core-js": "^3.8.3",
"vue": "^3.3.4",
"vue-router": "^4.0.3"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"sass": "^1.32.7",
"sass-loader": "^12.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}

BIN
frontend/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="">
<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="icon" href="<%= BASE_URL %>favicon.ico">
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

34
frontend/src/App.vue Normal file
View File

@ -0,0 +1,34 @@
<template>
<nav>
<router-link to="/">Home</router-link> |
<router-link to="/employee">employee</router-link> |
<router-link to="/appointment">appointment</router-link> |
<router-link to="/company">company</router-link> |
<!--<router-link to="/requests">requests</router-link> |-->
<router-link to="/report">report</router-link>
</nav>
<router-view/>
</template>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>

151
frontend/src/api/api.js Normal file
View File

@ -0,0 +1,151 @@
import axios from "axios";
const baseUrl = "http://localhost:8080/";
const config = {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
};
const appointmentCRUD = {
async createAppointment(appointmentName) {
console.log(baseUrl + "appointment/add?name=",
appointmentName )
return await axios.post(
baseUrl + "appointment/add?name="+appointmentName
);
},
async getAppointmentList() {
console.log(baseUrl + "appointment/list")
return await axios.get(baseUrl + "appointment/list");
},
async getAppointmentListSort(id) {
console.log(baseUrl + "appointment/postId=")
return await axios.get(baseUrl + "appointment/postId="+id);
},
async editAppointment(id, data) {
return await axios.put(baseUrl + `appointment/${id}`, data, config);
},
async deleteAppointment(id) {
return await axios.delete(baseUrl + `appointment/${id}`, config);
},
};
const companyCRUD = {
async createCompany(
nameCompany,
legalAdressCompany,
adressCompany,
contactEmail
) {
console.log(baseUrl + "company/add",
{
id:77777,
nameCompany: nameCompany,
legalAdressCompany: legalAdressCompany,
adressCompany: adressCompany,
contactEmail: contactEmail,
})
return await axios.post(
baseUrl + "company/add?name="+nameCompany+"&legalAdressCompany="+legalAdressCompany
+"&adressCompany="+adressCompany+"&contactEmail="+contactEmail,
config
);
},
async getCompanyList() {
return await axios.get(baseUrl + "company/list");
},
async editCompany(id, data) {
return await axios.put(baseUrl + `company/update?id=${id}?name=${data.companyName}`, data, config);
},
async deleteCompany(id) {
return await axios.delete(baseUrl + `company/${id}`, config);
},
async deleteAllCompanys() {
return await axios.delete(baseUrl + "company", config);
},
};
const requestCRUD = {
async createRequeset(
nameCompany,
comment,
createDate,
approveDate,
isActive,
sort,
type
) {
console.log( baseUrl + "requests/add?nameCompany="+nameCompany.id+"&comment="+comment +
+"&sort="+
+sort.id+"&type="+type.id
)
return await axios.post(
baseUrl + "requests/add?nameCompany="+nameCompany.id+"&comment="+comment,
// {
// nameCompany: nameCompany,
// comment: comment,
// createDate: createDate,
// approveDate: approveDate,
// isActive: isActive,
// sort: sort,
// type: type,
// },
config
);
},
async getRequestList() {
return await axios.get(baseUrl + "requests/all");
},
async getRequestByCompanyId() {
return await axios.get(baseUrl + "requests/Company={id}");
},
async editRequest(id, data) {
return await axios.put(baseUrl + `requests/${id}`, data, config);
},
async deleteRequest(id) {
return await axios.delete(baseUrl + `request/${id}`, config);
},
};
const employeeCRUD = {
async createEmployee(fio, appointment) {
return await axios.post(
baseUrl + "employee/add?name="+fio+"&appointmentId="+appointment,
{
fio: fio,
appointment: appointment,
},
config
);
},
async getEmployeeById(id) {
return await axios.get(baseUrl + `employee/${id}`);
},
async getEmployeeList() {
return await axios.get(baseUrl + "employee/all");
},
async getEmployeeWorks(id) {
return await axios.get(baseUrl + "employee/id=" + id);
},
async getEmployeeByPostId(postId) {
console.log("postId="+postId)
return await axios.get(baseUrl + "employee/postid=" + postId);
},
async editEmployee(id, data) {
console.log(data)
return await axios.put(baseUrl + `employee/update?id=${id}&name=`+data.fio, config);
},
async deleteEmployee(id) {
return await axios.delete(baseUrl + `employee/${id}`, config);
},
};
const API = {
...appointmentCRUD,
...companyCRUD,
...employeeCRUD,
...requestCRUD,
};
export default API;

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,68 @@
<template>
<div class="base">
<div class="create-apponiment">
<input type="text" v-model="appointmentName">
<button @click="createApponiment()" class="btn btn-primary mr-2">Создать</button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th>Название должности</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td><input :id="'row_'+item.id" :value="item.name" :disabled="isEdditable!==item.id"/></td>
<td>
<button @click="(isEdditable = item.id)" v-if="isEdditable!=item.id" class="btn btn-info">edit</button>
<button class="btn btn-info" @click="editAppoint(item.id)" v-else >save</button>
<button class="btn btn-info" @click="deleteAppoint(item.id)">del</button>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import API from '@/api/api';
// @ is an alias to /src
export default {
name: 'AppointmentsSheet',
data() {
return {
data: [],
appointmentName: '',
isEdditable:-1,
}
},
mounted() {
this.getApponiments()
},
methods: {
editAppoint(id){
console.log(id)
const $input = document.querySelector(`#row_${id}`)
const data = {
'id':id,
'name':$input.value
}
this.isEdditable = -1;
API.editAppointment(id, data)
},
deleteAppoint(id){
API.deleteAppointment(id)
this.getApponiments()
},
getApponiments() {
API.getAppointmentList().then(response => this.data = response.data)
},
createApponiment() {
API.createAppointment(this.appointmentName).then(() => this.getApponiments())
}
}
}
</script>

View File

@ -0,0 +1,90 @@
<template>
<div class="base">
<div class="create-company">
<input type="text" v-model="companyName" placeholder="compName">
<input type="text" v-model="legalAdressCompany" placeholder="legalAdressCompany">
<input type="text" v-model="address" placeholder="address">
<input type="email" v-model="email" placeholder="email">
<button @click="createCompany()">Создать</button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th>Название Компании</th>
<th>Юридический адрес</th>
<th>Адрес</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td><input :id="'arow_'+item.id" :value="item.nameCompany" :disabled="isEdditable!==item.id"/></td>
<td><input :id="'brow_'+item.id" :value="item.legalAdressCompany" :disabled="isEdditable!==item.id"/></td>
<td><input :id="'crow_'+item.id" :value="item.adressCompany" :disabled="isEdditable!==item.id"/></td>
<td><input :id="'drow_'+item.id" :value="item.contactEmail" :disabled="isEdditable!==item.id"/></td>
<td>
<button class="btn btn-info" @click="(isEdditable = item.id)" v-if="isEdditable!=item.id">edit</button>
<button class="btn btn-info" @click="editCompany(item.id)" v-else>save</button>
<button class="btn btn-info" @click="deleteCompany(item.id)">del</button>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import API from '@/api/api';
// @ is an alias to /src
export default {
name: 'CompanySheet',
data() {
return {
data: [],
companyName: '',
legalAdressCompany:'',
address: '',
email: '',
isEdditable:-1,
}
},
mounted() {
this.getCompanies()
},
methods: {
editCompany(id){
console.log(id)
const $input1 = document.querySelector(`#arow_${id}`)
const $input2 = document.querySelector(`#brow_${id}`)
const $input3 = document.querySelector(`#crow_${id}`)
const $input4 = document.querySelector(`#drow_${id}`)
const data = {
'id':id,
'companyName': $input1.value,
'legalAdressCompany': $input2.value,
'address': $input3.value,
'email': $input4.value,
}
this.isEdditable = -1;
API.editCompany(id, data)
},
deleteCompany(id){
API.deleteCompany(id)
this.getCompanies()
},
getCompanies() {
API.getCompanyList().then(response => {
this.data = response.data
console.log(response.data)
})
},
createCompany() {
API.createCompany(this.companyName, this.legalAdressCompany, this.address, this.email).then(() => this.getCompanies())
}
}
}
</script>

View File

@ -0,0 +1,100 @@
<template>
<div class="base">
<div class="create-employee">
<input type="text" v-model="name">
<select>
<option v-for="item in appointments" :key="item.id" :value="item.id" ref="optionAppoint" :id="item.id">{{item?.name}}</option>
</select>
<button class="btn btn-info" @click="createEmployee()">Создать</button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th>ФИО</th>
<th>Должность</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td><input :id="'arow_'+item.id" :value="item.fio" :disabled="isEdditable!==item.id"/></td>
<td>
<select>
<option v-for="appoint in appointments" :key="appoint.id" :value="appoint.id" ref="optionAppoint" :id="appoint.id" :selected="appoint.id==item.post.id">{{appoint?.name}}</option>
</select>
</td>
<td>
<button class="btn btn-info" @click="(isEdditable = item.id)" v-if="isEdditable!=item.id">edit</button>
<button class="btn btn-info" @click="editEmployee(item.id)" v-else>save</button>
<button class="btn btn-info" @click="deleteEmployee(item.id)">del</button>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import API from '@/api/api';
import appointmentsSheet from "@/components/AppointmentsSheet.vue";
// @ is an alias to /src
export default {
name: 'EmployeeSheet',
data() {
return {
data: [],
name: '',
appointments:[],
isEdditable:-1,
}
},
mounted() {
this.getEmployees()
this.getAppoint()
},
methods: {
editEmployee(id){
console.log(id)
const $input1 = document.querySelector(`#arow_${id}`)
const data = {
'id':id,
'fio': $input1.value
}
this.isEdditable = -1;
API.editEmployee(id, data)
},
deleteEmployee(id){
API.deleteEmployee(id)
this.getEmployees()
},
getEmployees() {
API.getEmployeeList().then(response => {
this.data = response.data
console.log(response)
})
},
getAppoint(){
console.log(this.data)
API.getAppointmentList().then((res)=> {
this.appointments = res.data
console.log(res.data)
})
},
createEmployee() {
const $selector = this.$refs.optionAppoint
const $selected = $selector.find(el=>el.selected)
API.createEmployee(this.name, $selected.id).then(() => this.getEmployees())
}
},
computed: {
appointmentsSheet() {
return appointmentsSheet
}
},
}
</script>

View File

@ -0,0 +1,62 @@
<template>
<select>
<option v-for="appoint in appointments" :key="appoint.id" :value="appoint.id" ref="optionAppoint" :id="appoint.id" >{{appoint?.name}}</option>
</select>
<button @click=getEmployees()>Select</button>
<table>
<thead>
<tr>
<th>id</th>
<th>ФИО</th>
<th>Должность</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td><input :value="item.fio"/></td>
</tr>
</tbody>
</table>
</template>
<script>
import API from "@/api/api";
export default {
name: "ReportSheet",
data() {
return {
data: [],
appointments: [],
id: 1
}
},
mounted() {
//this.getEmployees()
this.getAppoint()
},
methods: {
getEmployees() {
const $selector = this.$refs.optionAppoint
const $selected = $selector.find(el=>el.selected).id
API.getEmployeeByPostId($selected).then(response => {
this.data = response.data
console.log(response)
})
},
getAppoint() {
console.log(this.data)
API.getAppointmentList().then((res) => {
this.appointments = res.data
console.log(res.data)
})
},
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,126 @@
<template>
<div class="base">
<div class="create-request">
<select>
<option v-for="item in companies" :key="item.id" :value="item.id" ref="optionCompany" :id="item.id">{{item?.nameCompany}}</option>
</select>
<input type="text" v-model="comment">
<select>
<option v-for="item in types" :key="item" :value="item" ref="optionType" :id="item">{{item == 0 ? 'DEVELOP':'TRACKING'}}</option>
</select>
<select>
<option v-for="item in employes" :key="item.id" :value="item.id" ref="optionEmployee" :id="item.id">{{item?.fio}}</option>
</select>
<button @click="createRequest()">Создать</button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th>Компания</th>
<th>Ответственный</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>
<select>
<option v-for="company in companies" :key="company.id" :value="company.nameCompany" ref="optionCompany" :id="company.id" :selected="company.id==item.nameCompany">{{company?.name}}</option>
</select>
</td>
<!-- <td>{{ item.createDate }}</td>-->
<!-- <td>{{ item.approveDate }}</td>-->
<!-- <td>{{ item.isActive }}</td>-->
<select>
<option v-for="emp in employes" :key="emp.id" :value="emp.fio" ref="optionEmployee" :id="emp.id" :selected="emp.id==item.sort.id">{{emp?.name}}</option>
</select>
<td>{{ item.type }}</td>
<td>
<button @click="(isEdditable = item.id)" v-if="isEdditable!=item.id">edit</button>
<button @click="editRequest(item.id)" v-else>save</button>
<button @click="deleteRequest(item.id)">del</button>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import API from '@/api/api';
// @ is an alias to /src
export default {
name: 'RequestSheet',
data() {
return {
data: [],
name: '',
companies:[],
employes:[],
isEdditable:-1,
types:{
DEVELOP: 0,
TRACKING: 1
}
}
},
mounted() {
this.getEmployees()
this.getCompany()
this.getRequest()
},
methods: {
editRequest(id){
console.log(id)
const $input1 = document.querySelector(`#arow_${id}`)
const data = {
'id':id,
'fio': $input1.value
}
this.isEdditable = -1;
API.editRequest(id, data)
},
deleteRequest(id){
API.deleteRequest(id)
this.getRequest()
},
getEmployees() {
API.getEmployeeList().then(response => {
this.employes = response.data
console.log(response)
})
},
getCompany(){
console.log(this.data)
API.getCompanyList().then((res)=> {
this.companies = res.data
console.log(res.data)
})
},
getRequest(){
console.log(this.data)
API.getRequestList().then((res)=> {
this.data = res.data
console.log(res.data)
})
},
createRequest() {
const $selector = this.$refs.optionCompany
const $selected = $selector.find(el=>el.selected)
const $selector1 = this.$refs.optionEmployee
const $selected1 = $selector1.find(el=>el.selected)
const $selector2 = this.$refs.optionType
const $selected2 = $selector2.find(el=>el.selected)
API.createRequeset($selected, this.comment, new Date(), new Date(), true, $selected1, $selected2).then(() => this.getEmployees())
}
},
computed: {
requestsSheet() {
return this.requestsSheet()
}
},
}
</script>

5
frontend/src/main.js Normal file
View File

@ -0,0 +1,5 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
createApp(App).use(router).mount('#app')

View File

@ -0,0 +1,55 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import EmployeeSheet from "@/components/EmployeeSheet.vue";
import RequestSheet from "@/components/RequestSheet.vue";
import appointmentsSheet from "@/components/AppointmentsSheet.vue";
import CompanySheet from "@/components/CompanySheet.vue";
import Report from "@/components/Report.vue";
const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/employee',
name: 'employee',
component: EmployeeSheet
},
{
path: '/report',
name: 'report',
component: Report
},
{
path: '/company',
name: 'company',
component: CompanySheet
},
{
path: '/appointment',
name: 'appointment',
component: appointmentsSheet
},
{
path: '/requests',
name: 'requests',
component: RequestSheet
},
// {
// path: '/about',
// name: 'about',
// // route level code-splitting
// // this generates a separate chunk (about.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
// }
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router

View File

@ -0,0 +1,17 @@
<template>
<div class="home">
Hello
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: 'HomeView',
components: {
}
}
</script>

4
frontend/vue.config.js Normal file
View File

@ -0,0 +1,4 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})

View File

@ -1 +1 @@
rootProject.name = 'DozorovaLabWork'
rootProject.name = 'demo'

View File

@ -1,48 +0,0 @@
package LabWork.DozorovaLabWork;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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 DozorovaLabWorkApplication {
public static void main(String[] args) {
SpringApplication.run(DozorovaLabWorkApplication.class, args);
}
@GetMapping("/")
public String Hello() {
return "Hello, user";
}
@GetMapping("/sum")
public String Sum(@RequestParam(required = false, defaultValue = "0") float first,
@RequestParam(required = false, defaultValue = "0") float second) {
return Float.toString(first + second);
}
@GetMapping("/ras")
public String Ras(@RequestParam(required = false, defaultValue = "0") float first,
@RequestParam(required = false, defaultValue = "0") float second) {
return Float.toString(first - second);
}
@GetMapping("/pros")
public String Pros(@RequestParam(required = false, defaultValue = "1") float first,
@RequestParam(required = false, defaultValue = "1") float second) {
return Float.toString(first * second);
}
@GetMapping("/del")
public String Del(@RequestParam(required = false, defaultValue = "1") float first,
@RequestParam(required = false, defaultValue = "1") float second) {
if(second == 0)
{
return null;
}
return Float.toString(first/second);
}
}

View File

@ -0,0 +1,16 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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

@ -0,0 +1,22 @@
package com.example.demo;
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 {
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**").allowedMethods("*");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
ViewControllerRegistration registration = registry.addViewController("/notFound");
registration.setViewName("forward:/index.html");
registration.setStatusCode(HttpStatus.OK);
}
}

View File

@ -0,0 +1,57 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.*;
//import javax.validation.Valid;
import java.util.*;
@RestController
@RequestMapping("/appointment")
public class AppointmentController {
private final AppointmentService appointmentService;
public AppointmentController(AppointmentService appointmentService) {
this.appointmentService = appointmentService;
}
@PostMapping("/add")
public AppointmentDTO addAppointment(String name){
Random r = new Random();
var app = new Appointment(r.nextLong(), name);
return new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(app)));
}
@PutMapping("/{id}")
public AppointmentDTO updateAppointment(@PathVariable Long id,@RequestBody AppointmentDTO appointmentDTO) {
return new AppointmentDTO(appointmentService.updateAppointment(id,appointmentDTO));
}
@DeleteMapping("/{id}")
public AppointmentDTO removeAppointment(@PathVariable Long id) {
return new AppointmentDTO(appointmentService.deleteAppointment(id));
}
@DeleteMapping
public void removeAllAppointments() {
appointmentService.deleteAllAppointments();
}
@GetMapping("/{id}")
public AppointmentDTO findAppointment(@PathVariable Long id) {
return new AppointmentDTO(appointmentService.findAppointment(id));
}
@GetMapping("/list")
public List<AppointmentDTO> findAllAppointments() {
return appointmentService.findAllAppointments()
.stream()
.map(AppointmentDTO::new)
.toList();
}
}

View File

@ -0,0 +1,22 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Appointment;
public class AppointmentDTO {
private long id;
private String name;
public AppointmentDTO(Appointment appointment)
{
this.id = appointment.getId();
this.name = appointment.getName();;
}
public AppointmentDTO(){}
public long getId() {
return id;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,59 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.CompanyService;
import com.example.demo.speaker.service.EmployeeService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/company")
public class CompanyController {
private final CompanyService companyService;
public CompanyController(CompanyService _companyService) {
this.companyService = _companyService;
}
@PostMapping("/add")
public CompanyDTO addCompany(@RequestParam("name") String name, @RequestParam("legalAdressCompany") String legalAdressCompany,
@RequestParam("adressCompany") String adressCompany,
@RequestParam("contactEmail") String contactEmail) {
var company = new Company(name, legalAdressCompany, adressCompany, contactEmail);
return new CompanyDTO(companyService.addCompany(new CompanyDTO(company)));
}
@PutMapping("/update/{id}")
public CompanyDTO updateCompany(@PathVariable Long id,@RequestBody CompanyDTO companyDTO) {
return new CompanyDTO(companyService.updateCompany(id,companyDTO));
}
@DeleteMapping("/{id}")
public CompanyDTO removeCompany(@PathVariable Long id) {
return new CompanyDTO(companyService.deleteCompany(id));
}
@DeleteMapping
public void removeAllCompanies() {
companyService.deleteAllCompanies();
}
@GetMapping("/{id}")
public CompanyDTO findCompany(@PathVariable Long id) {
return new CompanyDTO(companyService.findCompany(id));
}
@GetMapping("/list")
public List<CompanyDTO> findAllCompanies() {
return companyService.findAllCompanies()
.stream()
.map(CompanyDTO::new)
.toList();
}
}

View File

@ -0,0 +1,42 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.RequestForCooperation;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
public class CompanyDTO {
private long id;
private String nameCompany;
private String legalAdressCompany;
private String adressCompany;
private String contactEmail;
// private List<RequestForCooperationDTO> requests = new ArrayList<>();
public CompanyDTO(Company company)
{
this.id = company.getId();
this.nameCompany = company.getNameCompany();
this.legalAdressCompany = company.getLegalAdressCompany();
this.adressCompany = company.getAdressCompany();
this.contactEmail = company.getContactEmail();
}
public long getId() {
return id;
}
public String getAdressCompany() { return adressCompany; }
public String getNameCompany() { return nameCompany; }
public String getContactEmail() { return contactEmail; }
public String getLegalAdressCompany() { return legalAdressCompany; }
}

View File

@ -0,0 +1,69 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.RequestForCooperationService;
import com.example.demo.speaker.service.EmployeeService;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/employee")
public class EmployeeController {
private final EmployeeService employeeService;
private final RequestForCooperationService requestForCooperationService;
private final AppointmentService appointmentService;
public EmployeeController(EmployeeService employeeService, RequestForCooperationService requestForCooperationService, AppointmentService appointmentService) {
this.employeeService = employeeService;
this.requestForCooperationService = requestForCooperationService;
this.appointmentService = appointmentService;
}
@GetMapping("/{id}")
public Employee getWorker(@PathVariable Long id) {
return employeeService.findWorker(id);
}
@GetMapping("/all")
public List<Employee> getWorkers() {
return employeeService.findAllWorkers();
}
@PostMapping("/add")
public EmployeeDTO createWorker(@RequestParam("name") String name, @RequestParam("appointmentId") Long appointmentId) {
var Employee = new Employee(name, appointmentService.findAppointment(appointmentId));
return new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee)));
}
@PutMapping("/update")
public EmployeeDTO updateWorker(@RequestParam("id") Long id, @RequestParam("name") String name) {
var emp = employeeService.findWorker(id);
emp.setFio(name);
return new EmployeeDTO(employeeService.updateReportWorker(id, new EmployeeDTO(emp)));
}
@DeleteMapping("/{id}")
public EmployeeDTO deleteWorker(@PathVariable Long id) {
return new EmployeeDTO(employeeService.deleteWorker(id));
}
@GetMapping("/id={id}")
public List<RequestForCooperation> getListOfReports(@PathVariable Long id) {
var employee = employeeService.findWorker(id);
return employeeService.findAllRequestsOfEmployee(employee);
}
@GetMapping("/postid={id}")
public List<Employee> getListOfWorkers(@PathVariable Long id) {
final Appointment appointment = appointmentService.findAppointment(id);
var res = employeeService.findWorkerByPost(appointment);
return res;
//return new ArrayList<Employee>();
}
}

View File

@ -0,0 +1,26 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.Employee;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToOne;
public class EmployeeDTO {
private Long id;
private String fio;
private AppointmentDTO appointment;
public EmployeeDTO(Employee employee)
{
this.id = employee.getId();
this.fio = employee.getFio();
this.appointment = new AppointmentDTO(employee.getPost());
}
public Long getId() { return id; }
public AppointmentDTO getAppointment() { return appointment; }
public String getFio() { return fio; }
}

View File

@ -0,0 +1,66 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.TypeOfRequestEnum;
import com.example.demo.speaker.service.CompanyService;
import com.example.demo.speaker.service.EmployeeService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.web.bind.annotation.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/requests")
public class RequestForCooperationController {
private final RequestForCooperationService requestForCooperationService;
private final CompanyService companyService;
private final EmployeeService employeeService;
public RequestForCooperationController(RequestForCooperationService requestForCooperationService, CompanyService companyService, EmployeeService employeeService) {
this.requestForCooperationService = requestForCooperationService;
this.companyService = companyService;
this.employeeService = employeeService;
}
@GetMapping("/{id}")
public RequestForCooperation getRequest(@PathVariable Long id) {
return requestForCooperationService.findRequest(id);
}
@GetMapping("/all")
public List<RequestForCooperation> getRequests() {
return requestForCooperationService.findAllRequests();
}
@PostMapping("/add")
public RequestForCooperation createRequest(@RequestParam Long nameCompany,
@RequestParam String comment
) throws ParseException {
//@RequestBody RequestForCooperationDTO requestDTO) {
var company = companyService.findCompany(nameCompany);
var emp = employeeService.findWorker(1L);
DateFormat form = new SimpleDateFormat("yyyy-MM-dd");
var request = new RequestForCooperation(656656L, company, form.parse("2023-06-13"), TypeOfRequestEnum.DEVELOP, comment, emp);
return requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
}
@PutMapping("/{id}")
public RequestForCooperationDTO updateRequest(@PathVariable Long id, @RequestBody RequestForCooperationDTO requestDTO) {
return new RequestForCooperationDTO(requestForCooperationService.updateRequest(requestDTO));
}
@DeleteMapping("/{id}")
public RequestForCooperation deleteRequest(@PathVariable Long id) {
return requestForCooperationService.deleteRequest(id);
}
@GetMapping("/Company={id}")
public List<RequestForCooperation> ListOfRequest(@PathVariable Long id) {
return requestForCooperationService.getRequestsOfCompany(companyService.findCompany(id));
}
}

View File

@ -0,0 +1,50 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.TypeOfRequestEnum;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToOne;
import java.util.Date;
public class RequestForCooperationDTO {
private Long id;
private Company nameCompany;
private String comment;
private Date createDate;
private Date approveDate;
private Boolean isActive;
private EmployeeDTO sotr;
private TypeOfRequestEnum type;
public RequestForCooperationDTO(RequestForCooperation request)
{
this.id = request.getId();
this.nameCompany = request.getName();
this.comment = request.getComment();
this.approveDate = request.getApproveDate();
this.sotr = new EmployeeDTO(request.getWorker());
this.createDate = request.getCreateDate();
this.isActive = request.getActive();
this.type = request.getType();
}
public long getId() { return this.id; }
public String getComment() { return comment; }
public Boolean getActive() { return isActive; }
public Company getNameCompany() { return nameCompany; }
public Date getApproveDate() { return approveDate; }
public Date getCreateDate() { return createDate; }
public EmployeeDTO getSotr() { return sotr; }
public TypeOfRequestEnum getType() {return type; }
}

View File

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

View File

@ -0,0 +1,111 @@
package com.example.demo.speaker.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
@Entity
public class Company {
@Column(nullable = false)
private String nameCompany;
@Column(nullable = false)
private String legalAdressCompany;
@Column(nullable = false)
private String adressCompany;
@Column(nullable = false)
private String contactEmail;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<RequestForCooperation> requests = new ArrayList<>();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Company(){}
Random r = new Random();
public Company(String nameCompany, String legalAdressCompany, String adressCompany,
String contactEmail)
{
this.id = r.nextLong();
this.nameCompany = nameCompany;
this.adressCompany = adressCompany;
this.legalAdressCompany = legalAdressCompany;
this.contactEmail = contactEmail;
}
public Company(Long id, String nameCompany, String legalAdressCompany, String adressCompany,
String contactEmail)
{
this.id = id;
this.nameCompany = nameCompany;
this.adressCompany = adressCompany;
this.legalAdressCompany = legalAdressCompany;
this.contactEmail = contactEmail;
}
public Long getId()
{
return this.id;
}
public String getNameCompany()
{
return this.nameCompany;
}
public String getLegalAdressCompany()
{
return this.legalAdressCompany;
}
public String getAdressCompany()
{
return this.adressCompany;
}
public String getContactEmail()
{
return this.contactEmail;
}
public void setNameCompany(String name)
{
this.nameCompany = name;
}
public void setLegalAdressCompany(String adressCompany)
{
this.legalAdressCompany = adressCompany;
}
public void setAdressCompany(String adressCompany)
{
this.adressCompany = adressCompany;
}
public void setContactEmail(String contactEmail)
{
this.contactEmail = contactEmail;
}
public void setList(RequestForCooperation req) {
this.requests.add(req);
}
public List<RequestForCooperation> getList()
{
return requests;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Company company = (Company) o;
return Objects.equals(id, company.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Company{" +
"id=" + id +
",Name='" + nameCompany + '\'' +
'}';
}
}

View File

@ -0,0 +1,85 @@
package com.example.demo.speaker.model;
import jakarta.persistence.*;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
@Entity
public class Employee {
@Id
@GeneratedValue
private Long id;
@Column(nullable = false)
private String fio;
//@OneToOne(fetch = FetchType.EAGER)
@OneToOne(cascade = {CascadeType.MERGE})
@JoinColumn(name = "appointment_id")
private Appointment appointment;
Random r = new Random();
public Employee(String fio, Appointment appointment) {
this.id = r.nextLong();
this.fio = fio;
this.appointment = appointment;
}
public Employee(Long id, String fio, Appointment appointment) {
this.id = id;
this.fio = fio;
this.appointment = appointment;
}
public Employee() {
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public String getFio()
{
return this.fio;
}
public Appointment getPost()
{
return this.appointment;
}
public void setFio(String fio)
{
this.fio = fio;
}
public void setPost(Appointment appointment)
{
this.appointment = appointment;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
return Objects.equals(id, employee.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Worker{" +
"id=" + id +
", Name='" + fio + '\'' +
", Post='" + appointment.getName() + '\'' +
'}';
}
}

View File

@ -0,0 +1,130 @@
package com.example.demo.speaker.model;
import jakarta.persistence.*;
import java.util.Date;
import java.util.Objects;
import java.util.Random;
@Entity
public class RequestForCooperation {
@jakarta.persistence.Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne(fetch = FetchType.LAZY)
private Company nameCompany;
@Column(nullable = false)
private String comment;
@Column(nullable = false)
private Date createDate;
private Date approveDate;
private Boolean isActive;
@OneToOne(fetch = FetchType.LAZY)
private Employee sotr;
@Enumerated(EnumType.STRING)
private TypeOfRequestEnum typeSotr;
public RequestForCooperation() {
}
Random r = new Random();
public RequestForCooperation(Company name, Date createDate, TypeOfRequestEnum type, String text) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = r.nextLong();
}
public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text, Employee emp) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = id;
this.sotr = emp;
}
public Company getName()
{
return this.nameCompany;
}
public TypeOfRequestEnum getType()
{
return this.typeSotr;
}
public Date getCreateDate()
{
return this.createDate;
}
public Date getApproveDate()
{
return this.approveDate;
}
public Employee getWorker()
{
return this.sotr;
}
public String getComment() { return this.comment; }
public void setWorker(Employee sotr)
{
this.sotr = sotr;
}
public Boolean getActive()
{
return this.isActive;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RequestForCooperation report = (RequestForCooperation) o;
return Objects.equals(id, report.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Report{" +
"id=" + id +
", NameCompany='" + nameCompany.toString() + '\'' +
", Type='" + typeSotr + '\'' +
", IsActive='" + isActive + '\'' +
'}';
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setApproveDate(Date date)
{
this.approveDate = date;
}
public void setUser(Employee sotr)
{
this.sotr = sotr;
}
public void setActive(Boolean active)
{
this.isActive = active;
}
public void setType(TypeOfRequestEnum type)
{
this.typeSotr = type;
}
}

View File

@ -0,0 +1,6 @@
package com.example.demo.speaker.model;
public enum TypeOfRequestEnum {
TRACKING,
DEVELOP
}

View File

@ -0,0 +1,11 @@
package com.example.demo.speaker.repository;
import com.example.demo.speaker.model.Appointment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface IAppointmentRepository extends JpaRepository<Appointment, Long> {
}

View File

@ -0,0 +1,14 @@
package com.example.demo.speaker.repository;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.RequestForCooperation;
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 ICompanyRepository extends JpaRepository<Company, Long> {
@Query("SELECT DISTINCT p.requests FROM Company p where :company = p.id")
List<RequestForCooperation> getRequestsOfCompany(@Param("company") Long id);
}

View File

@ -0,0 +1,18 @@
package com.example.demo.speaker.repository;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
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 IEmployeeRepository extends JpaRepository<Employee, Long> {
@Query("SELECT DISTINCT p FROM Employee p where :appointment = p.appointment")
List<Employee> getEmployeeByAppointment(@Param("appointment") Appointment appointment);
@Query("SELECT DISTINCT p FROM RequestForCooperation p where :employee = p.sotr")
List<RequestForCooperation> getRequestsOfEmployee(@Param("employee") Employee employee);
}

View File

@ -0,0 +1,18 @@
package com.example.demo.speaker.repository;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
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 IRequestForCooperationRepository extends JpaRepository<RequestForCooperation, Long> {
@Query("SELECT p.sotr FROM RequestForCooperation p where :id = p.id")
Employee findWorkerByRequest(@Param("id") RequestForCooperation request);
@Query("SELECT p.nameCompany FROM RequestForCooperation p where :company = p.nameCompany")
List<RequestForCooperation> findRequestByCompany(@Param("company") Company company);
}

View File

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

View File

@ -0,0 +1,64 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.AppointmentDTO;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.repository.IAppointmentRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.Random;
@Service
public class AppointmentService {
private final IAppointmentRepository appointmentRepository;
public AppointmentService(IAppointmentRepository appointmentRepository) {
this.appointmentRepository = appointmentRepository;
}
@Transactional
public Appointment addAppointment(AppointmentDTO appointmentDTO) {
try
{
Appointment appointment = new Appointment(appointmentDTO.getName());
appointmentRepository.save(appointment);
return appointment;
}
catch(Exception e)
{
return null;
}
}
@Transactional(readOnly = true)
public Appointment findAppointment(Long id) {
final Optional<Appointment> appointment = appointmentRepository.findById(id);
return appointment.get();
}
@Transactional(readOnly = true)
public List<Appointment> findAllAppointments() {
return appointmentRepository.findAll();
}
@Transactional
public Appointment updateAppointment(Long id, AppointmentDTO appointmentDTO) {
final Appointment currentAppointment = findAppointment(id);
currentAppointment.setName(appointmentDTO.getName());
appointmentRepository.save(currentAppointment);
return currentAppointment;
}
@Transactional
public Appointment deleteAppointment(Long id) {
final Appointment currentAppointment = findAppointment(id);
appointmentRepository.delete(currentAppointment);
return currentAppointment;
}
@Transactional
public void deleteAllAppointments() {
appointmentRepository.deleteAll();
}
}

View File

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

View File

@ -0,0 +1,78 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.CompanyDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.TypeOfRequestEnum;
import com.example.demo.speaker.repository.ICompanyRepository;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Optional;
@Service
public class CompanyService {
private final ICompanyRepository companyRepository;
public CompanyService(ICompanyRepository companyRepository) {
this.companyRepository = companyRepository;
}
@Transactional
public Company addCompany(CompanyDTO companyDTO) {
final Company company = new Company(companyDTO.getNameCompany(),
companyDTO.getLegalAdressCompany(),
companyDTO.getAdressCompany(),
companyDTO.getContactEmail());
companyRepository.save(company);
return company;
}
@Transactional
public Company addRequest(CompanyDTO companyDTO, List<RequestForCooperation> requests){
final Company currentCompany = findCompany(companyDTO.getId());
currentCompany.setList((RequestForCooperation) requests);
return currentCompany;
}
@Transactional
public Company updateCompany(Long id, CompanyDTO companyDTO) {
final Company currentCompany = findCompany(id);
currentCompany.setNameCompany(companyDTO.getNameCompany());
currentCompany.setAdressCompany(currentCompany.getAdressCompany());
currentCompany.setLegalAdressCompany(currentCompany.getLegalAdressCompany());
currentCompany.setContactEmail(currentCompany.getContactEmail());
companyRepository.save(currentCompany);
return currentCompany;
}
@Transactional(readOnly = true)
public Company findCompany(Long id) {
final Optional<Company> company = companyRepository.findById(id);
return company.orElseThrow(()->new CompanyNotFoundException(id));
}
@Transactional(readOnly = true)
public List<Company> findAllCompanies() {
return companyRepository.findAll();
}
@Transactional
public Company deleteCompany(Long id) {
final Company currentCompany = findCompany(id);
companyRepository.delete(currentCompany);
return currentCompany;
}
@Transactional
public void deleteAllCompanies() {
companyRepository.deleteAll();
}
@Transactional
public List<RequestForCooperation> getTypesRequests(Long id)
{
return companyRepository.getRequestsOfCompany(id);
}
}

View File

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

View File

@ -0,0 +1,81 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.EmployeeDTO;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.repository.IEmployeeRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@Service
public class EmployeeService {
private final IEmployeeRepository employeeRepository;
private final AppointmentService appointmentService;
public EmployeeService(IEmployeeRepository employeeRepository, AppointmentService appointmentService) {
this.employeeRepository = employeeRepository;
this.appointmentService = appointmentService;
}
@Transactional
public Employee addWorker(EmployeeDTO employee) {
var appontment = appointmentService.findAppointment(employee.getAppointment().getId());
Employee employeeNew = new Employee(employee.getFio(), appontment);
employeeRepository.save(employeeNew);
return employeeNew;
}
@Transactional(readOnly = true)
public Employee findWorker(Long id) {
final Optional<Employee> employee = employeeRepository.findById(id);
return employee.orElseThrow(()->new EmployeeNotFoundException(id));
}
@Transactional(readOnly = true)
public List<Employee> findAllWorkers() {
return employeeRepository.findAll();
}
@Transactional
public Employee updateReportWorker(Long id, EmployeeDTO employeeDTO) {
final Employee currentEmployee = findWorker(id);
currentEmployee.setFio(currentEmployee.getFio());
currentEmployee.setPost(currentEmployee.getPost());
employeeRepository.save(currentEmployee);
return currentEmployee;
}
@Transactional
public List<Employee> findWorkerByPost(Appointment appointment) {
if (appointment == null) {
throw new IllegalArgumentException("Post is null or empty");
}
List<Employee> list = employeeRepository.getEmployeeByAppointment(appointment);
return list;
}
@Transactional
public List<RequestForCooperation> findAllRequestsOfEmployee(Employee employee)
{
List<RequestForCooperation> list = employeeRepository.getRequestsOfEmployee(employee);
return list;
}
@Transactional
public Employee deleteWorker(Long id) {
final Employee currentEmployee = findWorker(id);
employeeRepository.delete(currentEmployee);
return currentEmployee;
}
@Transactional
public void deleteAllWorkers() {
employeeRepository.deleteAll();
}
}

View File

@ -0,0 +1,81 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.CompanyDTO;
import com.example.demo.speaker.controller.RequestForCooperationDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.repository.IRequestForCooperationRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@Service
public class RequestForCooperationService {
private final IRequestForCooperationRepository requestForCooperationRepository;
private final EmployeeService employeeService;
private final CompanyService companyService;
public RequestForCooperationService(IRequestForCooperationRepository requestForCooperationRepository, EmployeeService employeeRepository, CompanyService companyService) {
this.requestForCooperationRepository = requestForCooperationRepository;
this.employeeService = employeeRepository;
this.companyService = companyService;
}
@Transactional
public RequestForCooperation addRequest(RequestForCooperationDTO requestDTO) {
final RequestForCooperation request = new RequestForCooperation(requestDTO.getNameCompany(),
requestDTO.getCreateDate(),
requestDTO.getType(),
requestDTO.getComment());
requestForCooperationRepository.save(request);
return request;
}
@Transactional(readOnly = true)
public RequestForCooperation findRequest(Long id) {
final Optional<RequestForCooperation> report = requestForCooperationRepository.findById(id);
return report.orElseThrow(() -> new RequestNotFoundException(id));
}
@Transactional(readOnly = true)
public List<RequestForCooperation> findAllRequests() {
return requestForCooperationRepository.findAll();
}
@Transactional
public RequestForCooperation updateRequest(RequestForCooperationDTO requestDTO) {
final RequestForCooperation currentReport = findRequest(requestDTO.getId());
currentReport.setApproveDate(requestDTO.getApproveDate());
currentReport.setActive(requestDTO.getActive());
currentReport.setUser(employeeService.findWorker(requestDTO.getSotr().getId()));
requestForCooperationRepository.save(currentReport);
return currentReport;
}
@Transactional
public RequestForCooperation deleteRequest(Long id) {
final RequestForCooperation currentReport = findRequest(id);
requestForCooperationRepository.delete(currentReport);
return currentReport;
}
@Transactional
public void deleteAllRequests() {
requestForCooperationRepository.deleteAll();
}
@Transactional
public Employee getEmployeeOfRequest(Long id)
{
return requestForCooperationRepository.findWorkerByRequest(findRequest(id));
}
@Transactional
public List<RequestForCooperation> getRequestsOfCompany(Company companyDTO)
{
Company company = companyService.findCompany(companyDTO.getId());
return requestForCooperationRepository.findRequestByCompany(company);
}
}

View File

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

View File

@ -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

View File

@ -1,13 +0,0 @@
package LabWork.DozorovaLabWork;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DozorovaLabWorkApplicationTests {
@Test
void contextLoads() {
}
}

View File

@ -0,0 +1,29 @@
package com.example.demo;
import com.example.demo.speaker.controller.AppointmentDTO;
import com.example.demo.speaker.model.*;
import com.example.demo.speaker.service.CompanyService;
import com.example.demo.speaker.service.RequestForCooperationService;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.EmployeeService;
import jakarta.persistence.EntityNotFoundException;
import jakarta.transaction.Transactional;
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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
@SpringBootTest
public class JPATests {
}

View File

@ -0,0 +1,6 @@
spring.datasource.url=jdbc:h2:mem:testdb
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=create-drop