Доработка

This commit is contained in:
Shilyaev_Dmitry 2025-02-20 14:22:06 +03:00
parent 5004222eba
commit 85606dabbb
3 changed files with 10 additions and 5 deletions

View File

@ -6,9 +6,12 @@ import com.example.nto.dto.EnterDTO;
import com.example.nto.entity.*; import com.example.nto.entity.*;
import com.example.nto.service.impl.EmployeeServiceImpl; import com.example.nto.service.impl.EmployeeServiceImpl;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.net.http.HttpClient;
import java.util.List; import java.util.List;
@RestController @RestController
@ -39,7 +42,7 @@ public class EmployeeController {
} }
@PatchMapping("/admin/authority/change/{login}") @PatchMapping("/admin/authority/change/{login}")
public ResponseEntity<EmployeeAuthority> authChange(@PathVariable("login") String username, @RequestBody Authority authority){ public ResponseEntity<HttpStatus> authChange(@PathVariable("login") String username, @RequestBody Authority authority){
return ResponseEntity.ok(employeeService.changeAuthority(username, authority)); return ResponseEntity.ok(employeeService.changeAuthority(username, authority));
} }
} }

View File

@ -4,6 +4,7 @@ import com.example.nto.dto.EmployeeDTO;
import com.example.nto.dto.EnterDTO; import com.example.nto.dto.EnterDTO;
import com.example.nto.entity.Authority; import com.example.nto.entity.Authority;
import com.example.nto.entity.EmployeeAuthority; import com.example.nto.entity.EmployeeAuthority;
import org.springframework.http.HttpStatus;
import java.util.List; import java.util.List;
@ -12,5 +13,5 @@ public interface EmployeeService {
EmployeeDTO getInfo(String username); EmployeeDTO getInfo(String username);
EnterDTO addEnter(String username, EnterDTO enterDTO); EnterDTO addEnter(String username, EnterDTO enterDTO);
List<EnterDTO> getAllEmployeeEnters(String username); List<EnterDTO> getAllEmployeeEnters(String username);
EmployeeAuthority changeAuthority(String username, Authority auth); HttpStatus changeAuthority(String username, Authority auth);
} }

View File

@ -12,6 +12,7 @@ import com.example.nto.service.EmployeeService;
import com.example.nto.util.EmployeeMapper; import com.example.nto.util.EmployeeMapper;
import com.example.nto.util.EnterMapper; import com.example.nto.util.EnterMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -81,7 +82,7 @@ public class EmployeeServiceImpl implements EmployeeService {
} }
@Override @Override
public EmployeeAuthority changeAuthority(String username, Authority auth) { public HttpStatus changeAuthority(String username, Authority auth) {
Optional<Employee> optionalEmployee = employeeRepository.findByUsername(username); Optional<Employee> optionalEmployee = employeeRepository.findByUsername(username);
if(optionalEmployee.isEmpty()) if(optionalEmployee.isEmpty())
throw new EmployeeNotFoundException("Employee with username: " + username + " not found"); 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 employeeAuthority = employeeAuthorityRepository.findByEmpId(optionalEmployee.get());
employeeAuthority.setAuthId(optionalAuthority.get()); employeeAuthority.setAuthId(optionalAuthority.get());
employeeAuthorityRepository.save(employeeAuthority);
return employeeAuthorityRepository.save(employeeAuthority); return HttpStatus.OK;
} }