Compare commits

...

21 Commits

Author SHA1 Message Date
d00660090f it working 2023-06-13 15:05:57 +04:00
3604cd3fe5 working company 2023-06-13 12:17:20 +04:00
4686c2a973 work with employee 2023-06-13 11:31:07 +04:00
2b8514b8e2 add create appointment 2023-06-13 09:42:54 +04:00
7e12068e8b add mvc structure 2023-06-12 20:53:10 +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
65 changed files with 15545 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,26 @@ 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'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'org.webjars:bootstrap:5.1.3'
implementation 'org.webjars:jquery:3.6.0'
implementation 'org.webjars:font-awesome:6.1.0'
}
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"
]
}
}

11664
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

48
frontend/package.json Normal file
View File

@ -0,0 +1,48 @@
{
"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",
"core-js": "^3.8.3",
"vue": "^3.2.13",
"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,17 @@
<!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">
<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>

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

@ -0,0 +1,30 @@
<template>
<nav>
<router-link to="/">Home</router-link> |
<router-link to="/about">About</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>

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

@ -0,0 +1,137 @@
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({ name: appointmentName })
return await axios.post(
baseUrl + "appointment/add",
{ name: appointmentName },
config
);
},
async getAppointmentList() {
console.log(baseUrl + "appointment/list")
return await axios.get(baseUrl + "appointment/list");
},
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
) {
return await axios.post(
baseUrl + "company",
{
nameCompany: 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/${id}`, 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
) {
return await axios.post(
baseUrl + "requests",
{
nameCompany: nameCompany,
comment: comment,
createDate: createDate,
approveDate: approveDate,
isActive: isActive,
sort: sort,
type: type,
},
config
);
},
async getRequestList() {
return await axios.get(baseUrl + "request/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",
{
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) {
return await axios.get(baseUrl + "employee/postId=" + postId);
},
async editEmployee(id, data) {
return await axios.put(baseUrl + `employee/${id}`, data, 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,48 @@
<template>
<div class="base">
<div class="create-apponiment">
<input type="text" v-model="appointmentName">
<button @click="createApponiment()">Создать</button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th>Название должности</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</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: ''
}
},
mounted() {
this.getApponiments()
},
methods: {
getApponiments() {
API.getAppointmentList().then(response => this.data = response.data)
},
createApponiment() {
API.createAppointment(this.appointmentName).then(() => this.getApponiments())
}
}
}
</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,25 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
// {
// 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,19 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<appointments-sheet></appointments-sheet>
</div>
</template>
<script>
import AppointmentsSheet from '@/components/AppointmentsSheet.vue';
// @ is an alias to /src
export default {
name: 'HomeView',
components: {
AppointmentsSheet
}
}
</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,21 @@
package com.example.demo;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.*;
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
public static final String REST_API = "/api";
@Override
public void addViewControllers(ViewControllerRegistry registry) {
WebMvcConfigurer.super.addViewControllers(registry);
registry.addViewController("appointment");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}

View File

@ -0,0 +1,56 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.controller.DTO.AppointmentDTO;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.service.AppointmentService;
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,53 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.controller.DTO.CompanyDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.service.CompanyService;
import org.springframework.web.bind.annotation.*;
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("/remove")
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,26 @@
package com.example.demo.speaker.controller.DTO;
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;
}
public void setName(String nameAppointment){
this.name = nameAppointment;
}
}

View File

@ -0,0 +1,61 @@
package com.example.demo.speaker.controller.DTO;
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 CompanyDTO(){}
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; }
public void setNameCompany(String name)
{
this.nameCompany = name;
}
public void setAdressCompany(String adressCompany) {
this.adressCompany = adressCompany;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public void setLegalAdressCompany(String legalAdressCompany) {
this.legalAdressCompany = legalAdressCompany;
}
}

View File

@ -0,0 +1,29 @@
package com.example.demo.speaker.controller.DTO;
import com.example.demo.speaker.model.Employee;
public class EmployeeDTO {
private Long id;
private String fio;
private Long appointmentId;
public EmployeeDTO(Employee employee)
{
this.id = employee.getId();
this.fio = employee.getFio();
this.appointmentId = employee.getPost().getId();
}
public EmployeeDTO(){}
public Long getId() { return id; }
public Long getAppointmentId() { return appointmentId; }
public String getFio() { return fio; }
public void setAppointmentId(Long appointment) { this.appointmentId = appointment; }
public void setFio(String fio) {
this.fio = fio;
}
}

View File

@ -0,0 +1,74 @@
package com.example.demo.speaker.controller.DTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.TypeOfRequestEnum;
import java.util.Date;
public class RequestForCooperationDTO {
private Long id;
private Long nameCompany;
private String comment;
private Date createDate;
private Date approveDate;
private Boolean isActive;
private Long sotr;
private TypeOfRequestEnum type;
public RequestForCooperationDTO(RequestForCooperation request)
{
this.id = request.getId();
this.nameCompany = request.getName().getId();
this.comment = request.getComment();
this.approveDate = request.getApproveDate();
this.sotr = request.getWorker().getId();
this.createDate = request.getCreateDate();
this.isActive = request.getActive();
this.type = request.getType();
}
public RequestForCooperationDTO(){}
public long getId() { return this.id; }
public String getComment() { return comment; }
public Boolean getActive() { return isActive; }
public Long getNameCompany() { return nameCompany; }
public Date getApproveDate() { return approveDate; }
public Date getCreateDate() { return createDate; }
public Long getSotr() { return sotr; }
public TypeOfRequestEnum getType() {return type; }
public void setActive(Boolean active) {
isActive = active;
}
public void setApproveDate(Date approveDate) {
this.approveDate = approveDate;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public void setNameCompany(Long nameCompany) {
this.nameCompany = nameCompany;
}
public void setSotr(Long sotr) {
this.sotr = sotr;
}
public void setType(TypeOfRequestEnum type) {
this.type = type;
}
}

View File

@ -0,0 +1,65 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.controller.DTO.EmployeeDTO;
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.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("/{id}")
public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) {
return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO));
}
@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={postId}")
public List<Employee> getListOfWorkers(@RequestParam("postId") Long id) {
final Appointment appointment = appointmentService.findAppointment(id);
return employeeService.findWorkerByPost(appointment);
}
}

View File

@ -0,0 +1,60 @@
package com.example.demo.speaker.controller.MVCController;
import com.example.demo.speaker.controller.DTO.AppointmentDTO;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.service.AppointmentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import java.util.Random;
@Controller
@RequestMapping("/appointment")
public class AppointmentMVCController
{
private final AppointmentService appointmentService;
public AppointmentMVCController(AppointmentService appointmentService) {
this.appointmentService = appointmentService;
}
@GetMapping
public String getAppointments(Model model) {
model.addAttribute("appointments",
appointmentService.findAllAppointments().stream()
.map(AppointmentDTO::new)
.toList());
model.addAttribute("appointmentDTO", new AppointmentDTO());
return "appointment";
}
@PostMapping("/create")
public String createAppointment(@ModelAttribute AppointmentDTO appointmentDTO, Model model){
Random r = new Random();
var app = new Appointment(r.nextLong(), appointmentDTO.getName());
appointmentService.addAppointment(new AppointmentDTO(app));
// model.addAttribute("appointmentName", name);
// model.addAttribute("appointmentDTO", new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(app))));
return "redirect:/appointment";
}
@PostMapping("edit/{id}")
public String updateMVCAppointment(@PathVariable Long id, @ModelAttribute("appointment") AppointmentDTO appointment,
Model model) {
//appointmentService.updateAppointment(id, appointment);
model.addAttribute("appointmentId", id);
model.addAttribute("appointmentDTO", new AppointmentDTO(appointmentService.updateAppointment(id,appointment)));
return "redirect:/appointment";
}
@PostMapping("delete/{id}")
public String deleteAppointment(@PathVariable Long id) {
appointmentService.deleteAppointment(id);
return "redirect:/appointment";
}
}

View File

@ -0,0 +1,48 @@
package com.example.demo.speaker.controller.MVCController;
import com.example.demo.speaker.controller.DTO.CompanyDTO;
import com.example.demo.speaker.controller.DTO.EmployeeDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.service.CompanyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import java.util.List;
@Controller
@RequestMapping("/company")
public class CompanyMVCController {
private final CompanyService companyService;
public CompanyMVCController(CompanyService _companyService) {
this.companyService = _companyService;
}
@PostMapping("/create")
public String addCompany(@ModelAttribute CompanyDTO companyDTO, Model model) {
companyService.addCompany(companyDTO);
return "redirect:company";
}
@PostMapping("/edit/{id}")
public String updateCompany(@PathVariable Long id, @ModelAttribute CompanyDTO companyDTO) {
companyService.updateCompany(id,companyDTO);
return "company";
}
@PostMapping("delete/{id}")
public String removeCompany(@PathVariable Long id) {
companyService.deleteCompany(id);
return "company";
}
@GetMapping
public String findAllCompanies(Model model) {
model.addAttribute("companies", companyService.findAllCompanies()
.stream()
.map(CompanyDTO::new)
.toList());
model.addAttribute("companyDTO", new CompanyDTO());
return "company";
}
}

View File

@ -0,0 +1,63 @@
package com.example.demo.speaker.controller.MVCController;
import com.example.demo.speaker.controller.DTO.AppointmentDTO;
import com.example.demo.speaker.controller.DTO.EmployeeDTO;
import com.example.demo.speaker.model.Appointment;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.EmployeeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import java.util.List;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/employee")
public class EmployeeMVCController {
private final EmployeeService employeeService;
private final AppointmentService appointmentService;
public List<Appointment> appointments;
public EmployeeMVCController(EmployeeService employeeService, AppointmentService appointmentService) {
this.employeeService = employeeService;
this.appointmentService = appointmentService;
this.appointments = appointmentService.findAllAppointments();
}
@GetMapping
public String getWorkers(Model model) {
model.addAttribute("employees",
employeeService.findAllWorkers().stream()
.map(EmployeeDTO::new)
.toList());
model.addAttribute("appointments",
appointmentService.findAllAppointments().stream().map(AppointmentDTO::new).toList());
model.addAttribute("employeeDTO", new EmployeeDTO());
return "employee";
}
@PostMapping("/create")
public String createWorker(@ModelAttribute EmployeeDTO employeeDTO, Model model) {
employeeService.addWorker(employeeDTO);
return "employee";
}
@PostMapping("/edit/{id}")
public String updateWorker(@PathVariable Long id,@ModelAttribute("employeeDTO") EmployeeDTO employeeDTO, Model model) {
employeeService.updateReportWorker(id, employeeDTO);
// model.addAttribute("employees", employeeService.findAllWorkers());
// model.addAttribute("appointments", appointmentService.findAllAppointments());
return "/employee";
}
@PostMapping("/delete/{id}")
public String deleteWorker(@PathVariable Long id) {
employeeService.deleteWorker(id);
return "redirect:/employee";
}
}

View File

@ -0,0 +1,82 @@
package com.example.demo.speaker.controller.MVCController;
import com.example.demo.speaker.controller.DTO.CompanyDTO;
import com.example.demo.speaker.controller.DTO.EmployeeDTO;
import com.example.demo.speaker.controller.DTO.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.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.h2.store.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/request")
public class RequestMVCController {
private final RequestForCooperationService requestForCooperationService;
private final CompanyService companyService;
private final EmployeeService employeeService;
List<TypeOfRequestEnum> types;
List<Employee> employees;
List<Company> companies;
public RequestMVCController(RequestForCooperationService requestForCooperationService, CompanyService companyService, EmployeeService employeeService) {
this.requestForCooperationService = requestForCooperationService;
this.companyService = companyService;
this.employeeService = employeeService;
this.types = List.of(TypeOfRequestEnum.TRACKING, TypeOfRequestEnum.DEVELOP);
employees = employeeService.findAllWorkers();
companies = companyService.findAllCompanies();
}
@GetMapping
public String getRequests(Model model) {
model.addAttribute("requestDTO", new RequestForCooperationDTO());
model.addAttribute("requests", requestForCooperationService.findAllRequests()
.stream().map(RequestForCooperationDTO::new).toList());
model.addAttribute("types", types);
model.addAttribute("employees", employees.stream()
.map(EmployeeDTO::new).toList());
model.addAttribute("companies", companies.stream()
.map(CompanyDTO::new).toList());
return "request";
}
@PostMapping("/create")
public String createRequest(@ModelAttribute("requestDTO") RequestForCooperationDTO requestDTO,
Model model
){
requestDTO.setCreateDate(new Date());
requestDTO.setApproveDate(new Date());
//@RequestBody RequestForCooperationDTO requestDTO) {
requestForCooperationService.addRequest(requestDTO);
return "request";
}
@PutMapping("/{id}")
public String updateRequest(@PathVariable Long id,
@ModelAttribute RequestForCooperationDTO request,
Model model) {
request.setApproveDate(new Date());
request.setCreateDate(requestForCooperationService.findRequest(id).getCreateDate());
requestForCooperationService.updateRequest(request);
return "redirect:request";
}
@PostMapping("/delete/{id}")
public String deleteRequest(@PathVariable Long id, Model model) {
requestForCooperationService.deleteRequest(id);
return "redirect:request";
}
}

View File

@ -0,0 +1,66 @@
package com.example.demo.speaker.controller;
import com.example.demo.speaker.controller.DTO.RequestForCooperationDTO;
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.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(@PathVariable Long nameCompany,
@PathVariable String comment,
@PathVariable Integer isActive,
@PathVariable Long sort,
@PathVariable Long type
){
//@RequestBody RequestForCooperationDTO requestDTO) {
var company = companyService.findCompany(nameCompany);
var emp = employeeService.findWorker(sort);
var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, 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,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(strategy = GenerationType.AUTO)
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, Employee employee) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = r.nextLong();
this.sotr = employee;
}
public RequestForCooperation(Long id, Company name, Date createDate,
TypeOfRequestEnum type, String text) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
}
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.fio 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,63 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.DTO.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;
@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.orElseThrow(()->new AppointmentNotFoundException(id));
}
@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,75 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.DTO.CompanyDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.repository.ICompanyRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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(companyDTO.getAdressCompany());
currentCompany.setLegalAdressCompany(companyDTO.getLegalAdressCompany());
currentCompany.setContactEmail(companyDTO.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.DTO.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.getAppointmentId());
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,83 @@
package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.DTO.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) {
var company = companyService.findCompany(requestDTO.getNameCompany());
var empl = employeeService.findWorker(requestDTO.getSotr());
final RequestForCooperation request = new RequestForCooperation(company,
requestDTO.getCreateDate(),
requestDTO.getType(),
requestDTO.getComment(),
empl);
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()));
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

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<form action="#" th:action="@{/appointment/create}" th:object="${appointmentDTO}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" th:field="${appointmentDTO.name}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-info">
<span >Добавить</span>
</button>
</div>
</form>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Имя</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="appointment, iterator: ${appointments}">
<td th:text="${appointment.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/appointment/edit/{id}(id=${appointment.id})}" th:object="${appointmentDTO}" th:method="post">
<input type="text" class="form-control" id="nameAppointment" th:field="${appointmentDTO.name}" th:placeholder="${appointment.name}" style="width: 60%; display: inline-block" >
<button class="btn btn-info"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-info" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${appointment.id}').click()|">
Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->
<td style="width: 10%">
<form th:action="@{/appointment/delete/{id}(id=${appointment.id})}" method="post">
<button th:id="'remove-' + ${appointment.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<form th:action="@{/company/create}" th:object="${companyDTO}" th:method="post">
<input type="text" class="form-control" id="nameCompanyNew" th:field="*{nameCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="legalAdressCompanyNew" th:field="*{legalAdressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="adressCompanyNew" th:field="*{adressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="contactEmailNew" th:field="*{contactEmail}" style="width: 15%; display: inline-block" >
<button class="btn btn-info"
type="submit" style="display: inline-block"> Создать
</button>
</form>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Компания</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="company, iterator: ${companies}">
<td th:text="${company.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/company/edit/{id}(id=${company.id})}" th:object="${companyDTO}" th:method="post">
<input type="text" class="form-control" id="nameCompany" th:placeholder="${company.nameCompany}" th:field="*{nameCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="legalAdressCompany" th:placeholder="${company.legalAdressCompany}" th:field="*{legalAdressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="adressCompany" th:placeholder="${company.adressCompany}" th:field="*{adressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="contactEmail" th:placeholder="${company.contactEmail}" th:field="*{contactEmail}" style="width: 15%; display: inline-block" >
<button class="btn btn-info"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-info" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${company.id}').click()|">
Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->
<td style="width: 10%">
<form th:action="@{/company/delete/{id}(id=${company.id})}" method="post">
<button th:id="'remove-' + ${company.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="ru"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<title>Site of Company</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="icon" href="/favicon.svg">
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
<link rel="stylesheet" href="/css/style.css"/>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">
<i class="fa-solid fa-font-awesome"></i>
Site of Company
</a>
<button class="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav"> <!--th:with="activeLink=${#request.requestURI}"-->
<a class="nav-link" href="/"
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная</a>
<a class="nav-link" href="/appointment"
th:classappend="${#strings.equals(activeLink, '/appointment')} ? 'active' : ''">Appointment</a>
<a class="nav-link" href="/company"
th:classappend="${#strings.equals(activeLink, '/company')} ? 'active' : ''">Company</a>
<a class="nav-link" href="/employee"
th:classappend="${#strings.equals(activeLink, '/employee')} ? 'active' : ''">Employee</a>
<a class="nav-link" href="/request"
th:classappend="${#strings.equals(activeLink, '/request')} ? 'active' : ''">Request</a>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="container container-padding" layout:fragment="content">
</div>
</div>
</body>
<th:block layout:fragment="scripts">
</th:block>
</html>

View File

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<form action="#" th:action="@{/employee/create}" th:object="${employeeDTO}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" th:field="${employeeDTO.fio}" required="true">
</div>
<select id="appointmentId" class="form-select" th:field="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<option th:each="app: ${appointments}" th:value="${app.id}">
<span th:text="${app.name}"></span>
</option>
</select>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span >Добавить</span>
</button>
</div>
</form>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Сотрудник</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="employee, iterator: ${employees}">
<td th:text="${employee.id}"/>
<td >
<form th:action="@{/employee/edit/{id}(id=${employee.id})}" th:object="${employeeDTO}" th:method="post">
<input type="text" class="form-control" id="fio" th:field="${employeeDTO.fio}" th:placeholder="${employee.fio}" style="width: 30%; display: inline-block" >
<select id="appointment" class="form-select" th:field="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<option th:each="app: ${appointments}" th:value="${app.id}" th:selected="${employee.appointmentId} == ${app.id}">
<span th:text="${app.name}"></span>
</option>
</select>
<button class="btn btn-warning button-fixed button-sm"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${employee.id}').click()|">
</i> Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->
<td style="width: 10%">
<form th:action="@{/employee/delete/{id}(id=${employee.id})}" method="post">
<button th:id="'remove-' + ${employee.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<p>It's works!</p>
</div>
</body>
</html>

View File

@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<form th:action="@{/request/create}" th:object="${requestDTO}" th:method="post">
<select id="companyNew" class="form-select" th:name="company" th:field="${requestDTO.nameCompany}" style="width: 15%; display: inline-block">
<option th:each="value: ${companies}" th:value="${value.id}">
<span th:text="${value.getNameCompany()}"></span>
</option>
</select>
<!-- <input type="date" class="form-control" id="createDateNew" th:field="${requestDTO.createDate}" style="width: 15%; display: inline-block" >-->
<!-- <input type="date" class="form-control" id="approveDateNew" th:field="${requestDTO.approveDate}" style="width: 15%; display: inline-block" >-->
<input type="text" class="form-control" id="commentNew" th:field="${requestDTO.comment}" style="width: 15%; display: inline-block" >
<select id="employeeNew" class="form-select" th:field="${requestDTO.sotr}" th:name="employee" style="width: 30%; display: inline-block">
<option th:each="value: ${employees}" th:value="${value.id}">
<span th:text="${value.getFio()}"></span>
</option>
</select>
<select id="typesNew" class="form-select" th:name="type" th:field="${requestDTO.type}" style="width: 30%; display: inline-block">
<option th:each="value: ${types}" th:value="${value}">
<span th:text="${value}"></span>
</option>
</select>
<button class="btn btn-warning button-fixed button-sm"
type="submit" style="display: inline-block"> Изменить
</button>
</form>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Заявка</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="request, iterator: ${requests}">
<td th:text="${request.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/request/edit/{id}(id=${request.id})}" th:object="${requestDTO}" th:method="post">
<select id="company" class="form-select" th:name="company" th:field="*{nameCompany}" style="width: 15%; display: inline-block">
<option th:each="value: ${companies}" th:value="${value.id}" th:selected="${request.getNameCompany()} == ${value.id}">
<span th:text="${value.getNameCompany()}"></span>
</option>
</select>
<!-- <input type="date" class="form-control" id="createDate" th:value="${request.createDate}" style="width: 15%; display: inline-block" readonly>-->
<!-- <input type="date" class="form-control" id="approveDate" th:value="${request.approveDate}" style="width: 15%; display: inline-block" readonly>-->
<input type="text" class="form-control" id="comment" th:placeholder="${request.comment}" th:field="${requestDTO.comment}" style="width: 15%; display: inline-block" >
<select id="employee" class="form-select" th:field="${requestDTO.sotr}" th:name="employee" style="width: 30%; display: inline-block">
<option th:each="value: ${employees}" th:value="${value.id}" th:selected="${request.getSotr()} == ${value.id}">
<span th:text="${value.getFio()}"></span>
</option>
</select>
<select id="types" class="form-select" th:field="${requestDTO.type}" th:name="type" style="width: 30%; display: inline-block">
<option th:each="value: ${types}" th:value="${value}" th:selected="${request.getType()} == ${value}">
<span th:text="${value}"></span>
</option>
</select>
<button class="btn btn-warning button-fixed button-sm"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${request.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->
<td style="width: 10%">
<form th:action="@{/request/delete/{id}(id=${request.id})}" method="post">
<button th:id="'remove-' + ${request.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

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,10 @@
package com.example.demo;
import org.springframework.boot.test.context.SpringBootTest;
@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