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

View File

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

View File

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

View File

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

View File

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