исправлено 0_о
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package com.example.nto.controller;
|
package com.example.nto.controller;
|
||||||
|
|
||||||
import com.example.nto.entity.Employee;
|
import com.example.nto.entity.Employee;
|
||||||
|
import com.example.nto.repository.EmployeeRepository;
|
||||||
import com.example.nto.service.EmployeeService;
|
import com.example.nto.service.EmployeeService;
|
||||||
import com.example.nto.service.impl.EmployeeServiceImpl;
|
import com.example.nto.service.impl.EmployeeServiceImpl;
|
||||||
|
import org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -28,13 +30,14 @@ public class EmployeeController {
|
|||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/auth")
|
@GetMapping("/{code}/auth")
|
||||||
public HttpStatus Isauth(@PathVariable long id){
|
public HttpStatus Isauth(@PathVariable String code){
|
||||||
if(employeeService.isIdValid(id)){
|
if(employeeService.isCodeValid(code)){
|
||||||
return HttpStatus.OK;
|
return HttpStatus.OK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return HttpStatus.NOT_FOUND;
|
return HttpStatus.UNAUTHORIZED;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ public class Employee {
|
|||||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private List<Booking> bookingList;
|
private List<Booking> bookingList;
|
||||||
|
|
||||||
public Employee(long id, String name) {
|
public Employee(long id, String name, String code, String photoUrl) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.code = code;
|
||||||
|
this.photoUrl = photoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import java.util.Optional;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Repository
|
@Repository
|
||||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
public interface EmployeeRepository extends JpaRepository<Employee, String> {
|
||||||
Optional<Employee> findById(Long id);
|
Optional<Employee> findByCode(String code);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import java.util.Optional;
|
|||||||
public interface EmployeeService {
|
public interface EmployeeService {
|
||||||
List<Employee> getAll();
|
List<Employee> getAll();
|
||||||
|
|
||||||
Optional<Employee> getById(long id);
|
Optional<Employee> getByCode(String code);
|
||||||
|
|
||||||
boolean isIdValid(long id);
|
|
||||||
|
boolean isCodeValid(String code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Employee> getById(long id) {
|
public Optional<Employee> getByCode(String code) {
|
||||||
return employeeRepository.findById(id);
|
return employeeRepository.findByCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIdValid(long id){
|
public boolean isCodeValid(String code){
|
||||||
return employeeRepository.findById(id).isPresent();
|
return employeeRepository.findByCode(code).isPresent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user