main #10
@@ -1,8 +1,10 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
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.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -28,13 +30,14 @@ public class EmployeeController {
|
||||
this.employeeService = employeeService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/auth")
|
||||
public HttpStatus Isauth(@PathVariable long id){
|
||||
if(employeeService.isIdValid(id)){
|
||||
@GetMapping("/{code}/auth")
|
||||
public HttpStatus Isauth(@PathVariable String code){
|
||||
if(employeeService.isCodeValid(code)){
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
else
|
||||
return HttpStatus.NOT_FOUND;
|
||||
return HttpStatus.UNAUTHORIZED;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,9 +35,11 @@ public class Employee {
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private List<Booking> bookingList;
|
||||
|
||||
public Employee(long id, String name) {
|
||||
public Employee(long id, String name, String code, String photoUrl) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.photoUrl = photoUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
Optional<Employee> findById(Long id);
|
||||
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, String> {
|
||||
Optional<Employee> findByCode(String code);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ import java.util.Optional;
|
||||
public interface EmployeeService {
|
||||
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
|
||||
public Optional<Employee> getById(long id) {
|
||||
return employeeRepository.findById(id);
|
||||
public Optional<Employee> getByCode(String code) {
|
||||
return employeeRepository.findByCode(code);
|
||||
}
|
||||
|
||||
public boolean isIdValid(long id){
|
||||
return employeeRepository.findById(id).isPresent();
|
||||
public boolean isCodeValid(String code){
|
||||
return employeeRepository.findByCode(code).isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user