main #9

Closed
student-20690 wants to merge 26 commits from (deleted):main into main
5 changed files with 19 additions and 14 deletions
Showing only changes of commit 94a8cddd51 - Show all commits

View File

@@ -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;
} }

View File

@@ -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;
} }
} }

View File

@@ -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);
} }

View File

@@ -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);
} }

View File

@@ -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();
} }
} }