diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java index ba39c0f..4d6b46e 100644 --- a/src/main/java/com/example/nto/controller/EmployeeController.java +++ b/src/main/java/com/example/nto/controller/EmployeeController.java @@ -6,9 +6,12 @@ import com.example.nto.dto.EnterDTO; import com.example.nto.entity.*; import com.example.nto.service.impl.EmployeeServiceImpl; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; + +import java.net.http.HttpClient; import java.util.List; @RestController @@ -39,7 +42,7 @@ public class EmployeeController { } @PatchMapping("/admin/authority/change/{login}") - public ResponseEntity authChange(@PathVariable("login") String username, @RequestBody Authority authority){ + public ResponseEntity authChange(@PathVariable("login") String username, @RequestBody Authority authority){ return ResponseEntity.ok(employeeService.changeAuthority(username, authority)); } } diff --git a/src/main/java/com/example/nto/service/EmployeeService.java b/src/main/java/com/example/nto/service/EmployeeService.java index 6a82a6e..08163c6 100644 --- a/src/main/java/com/example/nto/service/EmployeeService.java +++ b/src/main/java/com/example/nto/service/EmployeeService.java @@ -4,6 +4,7 @@ import com.example.nto.dto.EmployeeDTO; import com.example.nto.dto.EnterDTO; import com.example.nto.entity.Authority; import com.example.nto.entity.EmployeeAuthority; +import org.springframework.http.HttpStatus; import java.util.List; @@ -12,5 +13,5 @@ public interface EmployeeService { EmployeeDTO getInfo(String username); EnterDTO addEnter(String username, EnterDTO enterDTO); List getAllEmployeeEnters(String username); - EmployeeAuthority changeAuthority(String username, Authority auth); + HttpStatus changeAuthority(String username, Authority auth); } diff --git a/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java b/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java index d6ff5eb..a01b871 100644 --- a/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java +++ b/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java @@ -12,6 +12,7 @@ import com.example.nto.service.EmployeeService; import com.example.nto.util.EmployeeMapper; import com.example.nto.util.EnterMapper; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import java.util.List; @@ -81,7 +82,7 @@ public class EmployeeServiceImpl implements EmployeeService { } @Override - public EmployeeAuthority changeAuthority(String username, Authority auth) { + public HttpStatus changeAuthority(String username, Authority auth) { Optional optionalEmployee = employeeRepository.findByUsername(username); if(optionalEmployee.isEmpty()) throw new EmployeeNotFoundException("Employee with username: " + username + " not found"); @@ -91,8 +92,8 @@ public class EmployeeServiceImpl implements EmployeeService { EmployeeAuthority employeeAuthority = employeeAuthorityRepository.findByEmpId(optionalEmployee.get()); employeeAuthority.setAuthId(optionalAuthority.get()); - - return employeeAuthorityRepository.save(employeeAuthority); + employeeAuthorityRepository.save(employeeAuthority); + return HttpStatus.OK; }