Контроллер Employee и сервисы Employee и Visit обновлены
This commit is contained in:
parent
e086567a26
commit
b20455cb7b
@ -12,7 +12,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/employee")
|
||||||
public class EmployeeController {
|
public class EmployeeController {
|
||||||
private final VisitService visitService;
|
private final VisitService visitService;
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
@ -22,11 +22,6 @@ public class EmployeeController {
|
|||||||
this.visitService = visitService;
|
this.visitService = visitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/hello")
|
|
||||||
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
|
|
||||||
return String.format("Hello %s!", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<Employee> createEmployee(@RequestBody EmployeeDTO employeeDTO) {
|
public ResponseEntity<Employee> createEmployee(@RequestBody EmployeeDTO employeeDTO) {
|
||||||
return ResponseEntity.ok(employeeService.createEmployee(employeeDTO));
|
return ResponseEntity.ok(employeeService.createEmployee(employeeDTO));
|
||||||
@ -43,8 +38,8 @@ public class EmployeeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{username}/open")
|
@PatchMapping("/{username}/open")
|
||||||
public ResponseEntity<Visit> open(@PathVariable String username, VisitDTO visitDTO) {
|
public ResponseEntity<Visit> open(@PathVariable String username, @RequestBody VisitDTO visitDTO) {
|
||||||
visitService.open(username, visitDTO.getValue());
|
visitService.open(username, visitDTO);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.example.onomatopoeiaback.domain.employee.EmployeeDTO;
|
|||||||
import com.example.onomatopoeiaback.repository.EmployeeRepository;
|
import com.example.onomatopoeiaback.repository.EmployeeRepository;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -20,10 +21,16 @@ public class EmployeeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Employee createEmployee(EmployeeDTO employeeDTO) {
|
public Employee createEmployee(EmployeeDTO employeeDTO) {
|
||||||
// TODO
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
|
|
||||||
Employee employee = new Employee();
|
Employee employee = new Employee();
|
||||||
employee.setLogin(employeeDTO.getLogin());
|
employee.setLogin(employeeDTO.getLogin());
|
||||||
employee.setPassword(employeeDTO.getPassword());
|
employee.setPassword(passwordEncoder.encode(employeeDTO.getPassword()));
|
||||||
|
employee.setName(employeeDTO.getName());
|
||||||
|
employee.setPhoto(employeeDTO.getPhoto());
|
||||||
|
employee.setPosition(employeeDTO.getPosition());
|
||||||
|
|
||||||
|
employee = employeeRepository.saveAndFlush(employee);
|
||||||
return employee;
|
return employee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.example.onomatopoeiaback.service;
|
package com.example.onomatopoeiaback.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.onomatopoeiaback.domain.employee.Employee;
|
||||||
import com.example.onomatopoeiaback.domain.visit.Visit;
|
import com.example.onomatopoeiaback.domain.visit.Visit;
|
||||||
|
import com.example.onomatopoeiaback.domain.visit.VisitDTO;
|
||||||
import com.example.onomatopoeiaback.exceptions.BadRequestException;
|
import com.example.onomatopoeiaback.exceptions.BadRequestException;
|
||||||
import com.example.onomatopoeiaback.exceptions.UnauthorizedException;
|
import com.example.onomatopoeiaback.exceptions.UnauthorizedException;
|
||||||
import com.example.onomatopoeiaback.repository.EmployeeRepository;
|
import com.example.onomatopoeiaback.repository.EmployeeRepository;
|
||||||
|
import com.example.onomatopoeiaback.repository.QrCodeRepository;
|
||||||
import com.example.onomatopoeiaback.repository.VisitRepository;
|
import com.example.onomatopoeiaback.repository.VisitRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -15,14 +18,25 @@ import java.time.temporal.ChronoUnit;
|
|||||||
public class VisitService {
|
public class VisitService {
|
||||||
private final VisitRepository visitRepository;
|
private final VisitRepository visitRepository;
|
||||||
private final EmployeeRepository employeeRepository;
|
private final EmployeeRepository employeeRepository;
|
||||||
|
final
|
||||||
|
QrCodeRepository qrCodeRepository;
|
||||||
|
|
||||||
public VisitService(VisitRepository visitRepository, EmployeeRepository employeeRepository) {
|
public VisitService(VisitRepository visitRepository, EmployeeRepository employeeRepository, QrCodeRepository qrCodeRepository) {
|
||||||
this.visitRepository = visitRepository;
|
this.visitRepository = visitRepository;
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
|
this.qrCodeRepository = qrCodeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(String login, Long value) {
|
// TDDO: удалить это. и оставить open и доработать его. После этого объект Visit добавить пользователю в массив посещений. Реализовать получение посещений с offset и limit. Реализовать авторизацию и разделение методов на роли.
|
||||||
Visit visit = visitRepository.getVisitByValue(value);
|
public Visit create(VisitDTO visitDTO) {
|
||||||
|
Visit visit = new Visit();
|
||||||
|
visit.setQrCode(qrCodeRepository.getReferenceById(visitDTO.getQrCodeId()));
|
||||||
|
visit.setVisitType(visitDTO.getVisitType());
|
||||||
|
return visitRepository.saveAndFlush(visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void open(String login, VisitDTO visitDTO) {
|
||||||
|
Visit visit = visitRepository.getVisitByValue(visitDTO.getValue());
|
||||||
Employee employee = employeeRepository.getEmployeesByLogin(login);
|
Employee employee = employeeRepository.getEmployeesByLogin(login);
|
||||||
|
|
||||||
if (employee == null) {
|
if (employee == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user