RELEASE
This commit is contained in:
parent
feb08bcc9f
commit
1e604a6ecc
11
pom.xml
11
pom.xml
@ -3,10 +3,19 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>NTO-2024</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
|
@ -2,33 +2,41 @@ package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.EmployeeWithCode;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import javassist.tools.web.BadHttpRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@AllArgsConstructor
|
||||
public class EmployeeController {
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@PostMapping("/auth")
|
||||
@GetMapping("/auth")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void auth(@RequestBody String login, @RequestBody String password) {
|
||||
employeeService.checkEmployee(login, password);
|
||||
public void auth(@RequestBody Employee employee) {
|
||||
employeeService.checkEmployee(employee);
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Employee info(@RequestBody String login) {
|
||||
return employeeService.getEmployee(login);
|
||||
public Employee info(@RequestBody Employee employee) {
|
||||
return employeeService.getEmployee(employee);
|
||||
}
|
||||
|
||||
@PatchMapping("/open")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void open(@RequestBody String login, @RequestBody Code code) {
|
||||
employeeService.open(login, code);
|
||||
public void open(@RequestBody EmployeeWithCode Data) {
|
||||
Employee employee = Data.getEmployee();
|
||||
Code code = (Code) Data.getCode();
|
||||
employeeService.open(employee, code);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -15,21 +16,28 @@ import java.time.LocalDateTime;
|
||||
@Entity
|
||||
@Table(name = "employee")
|
||||
public class Employee {
|
||||
@JsonProperty(required = false)
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
@Column(name = "login")
|
||||
private String login;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "role")
|
||||
private String role;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "photo")
|
||||
private String photo;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "position")
|
||||
private String position;
|
||||
@JsonProperty(required = false)
|
||||
@Column(name = "lastVisit")
|
||||
private LocalDateTime lastVisit;
|
||||
}
|
||||
|
15
src/main/java/com/example/nto/entity/EmployeeWithCode.java
Normal file
15
src/main/java/com/example/nto/entity/EmployeeWithCode.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class EmployeeWithCode {
|
||||
private Employee employee;
|
||||
private Code code;
|
||||
}
|
@ -5,7 +5,7 @@ import com.example.nto.entity.Employee;
|
||||
import javassist.tools.web.BadHttpRequest;
|
||||
|
||||
public interface EmployeeService {
|
||||
Employee getEmployee(String login);
|
||||
void checkEmployee(String login, String password);
|
||||
void open(String login, Code code);
|
||||
Employee getEmployee(Employee employee);
|
||||
void checkEmployee(Employee employee);
|
||||
void open(Employee employee, Code code);
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Override
|
||||
public Employee getEmployee(String login) throws NoSuchEmployeeException {
|
||||
List<Employee> employee = employeeRepository.findByLogin(login);
|
||||
public Employee getEmployee(Employee employee_r) throws NoSuchEmployeeException {
|
||||
List<Employee> employee = employeeRepository.findByLogin(employee_r.getLogin());
|
||||
if (employee.isEmpty()) {
|
||||
throw new NoSuchEmployeeException("Неверный логин или пароль");
|
||||
} else {
|
||||
@ -35,16 +35,16 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkEmployee(String login, String password) throws NoSuchEmployeeException{
|
||||
Employee employee = this.getEmployee(login);
|
||||
if(!(bCryptPasswordEncoder.matches(password, employee.getPassword()))) {
|
||||
public void checkEmployee(Employee employee_r) throws NoSuchEmployeeException{
|
||||
Employee employee = getEmployee(employee_r);
|
||||
if(!(bCryptPasswordEncoder.matches(employee_r.getPassword(), employee.getPassword()))) {
|
||||
throw new NoSuchEmployeeException("Неверный логин или пароль");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(String login, Code code) {
|
||||
getEmployee(login);
|
||||
public void open(Employee employee_r, Code code) {
|
||||
getEmployee(employee_r);
|
||||
List<Code> codeList = codeRepository.findByCode(code.getValue());
|
||||
|
||||
if (codeList.isEmpty()) {
|
||||
|
@ -3,7 +3,7 @@ VALUES
|
||||
(1, 'pivanov', '$2a$13$XIDSGI7yCy8w4U2UlMVoQeTbQ18EQR.Pm1PExrGq4JkW5wDwdnu26', 'Иванов Петр Федорович', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-12T08:30', 'Employee'),
|
||||
(2, 'ipetrov', '$2a$13$Fpi5mPSNgz.PAeKXmHYBEuutZBgmNdM4fHJFGJbh2AtpLrSmsm2yO', 'Петров Иван Константинович', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Аналитик', '2024-02-13T02:35', 'Employee'),
|
||||
(3, 'asemenov', '$2a$13$qjWp94aryBy4nJwYZkgN5uwj6VlU76f1OjezyeVunkwVMAVvvtUGG', 'Семенов Анатолий Анатольевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-13T08:31', 'Employee'),
|
||||
(4, 'afedorov', '$2a$13$sKN9jIo/xvGo37YuUUpHkO03yrmODw1PvFRytxu.i.QxLqLR7O7q6', 'Федоров Александр Сергеевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Тестировщик', '2024-02-12T08:36', 'Admin'),
|
||||
(4, 'afedorov', '$2y$13$QK7p.S0H2sNSiUPs0VhdbuohYkQDtrXERwl54Ftr65hBsw/fFsI7.', 'Федоров Александр Сергеевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Тестировщик', '2024-02-12T08:36', 'Admin'),
|
||||
(5, 'dfrolov', '$2y$13$R.c0njPlR9ZvpsU.2uHA0enJEUoXgE2Y838XaMFSewXCfkyhkxMuK', 'Фролов Данила Сергеевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Программист', '2024-02-12T08:50', 'Employee'),
|
||||
(6, 'emalakhova', '$$2y$13$QZMJ3cSJKSjCiJVttlQQ4ud2.RM..gKjUM8X4GEHPxgoM1E7w6sNW', 'Малахова Елена Алексеевна', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Аналитик', '2024-02-13T18:45', 'Employee'),
|
||||
(7, 'kplazinich', '$2y$13$u6EVJQMUzTrt.bf3RbuTkOjHt6jHBshnX.sKlCAz3VVog/Dhm2GpK', 'Плазинич Катарина Митрофановна', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-13T08:31', 'Admin'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user