70 lines
2.7 KiB
Java
70 lines
2.7 KiB
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.dto.entity.employee.EmployeeDTO;
|
|
import com.example.nto.dto.entity.employee.EmployeeItemDTO;
|
|
import com.example.nto.service.EmployeeService;
|
|
import com.example.nto.service.PhotoService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("api/v1/employees")
|
|
public class EmployeeController {
|
|
private final EmployeeService employeeService;
|
|
private final PhotoService photoService;
|
|
|
|
@GetMapping
|
|
public ResponseEntity<List<EmployeeItemDTO>> getAll() {
|
|
return ResponseEntity.ok(employeeService.getAll());
|
|
}
|
|
|
|
@GetMapping("/working/{isWorking}")
|
|
public ResponseEntity<List<EmployeeItemDTO>> getAllWorking(@PathVariable boolean isWorking) {
|
|
return ResponseEntity.ok(employeeService.getWorkingEmployee(isWorking));
|
|
}
|
|
|
|
@GetMapping("/{employeeId}")
|
|
public ResponseEntity<EmployeeDTO> getEmployeeById(@PathVariable long employeeId) {
|
|
return ResponseEntity.ok(employeeService.getById(employeeId));
|
|
}
|
|
|
|
@GetMapping("/email/{email}")
|
|
public ResponseEntity<EmployeeDTO> getEmployeeByEmail(@PathVariable String email) {
|
|
return ResponseEntity.ok(employeeService.getByEmail(email));
|
|
}
|
|
|
|
@GetMapping("/telephone/{telephone}")
|
|
public ResponseEntity<EmployeeDTO> getEmployeeByTelephone(@PathVariable String telephone) {
|
|
return ResponseEntity.ok(employeeService.getByTelephone(telephone));
|
|
}
|
|
|
|
@PutMapping("/{employeeId}")
|
|
public ResponseEntity<EmployeeDTO> updateEmployee(@PathVariable long employeeId, @RequestBody EmployeeDTO employeeDTO) {
|
|
return ResponseEntity.ok(employeeService.update(employeeId, employeeDTO));
|
|
}
|
|
|
|
@DeleteMapping("/{employeeId}")
|
|
public ResponseEntity<EmployeeDTO> deleteEmployeeById(@PathVariable long employeeId) {
|
|
employeeService.delete(employeeId);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
|
|
@PatchMapping("/image/profile/{employeeId}")
|
|
public ResponseEntity<Void> patchImageProfile(@PathVariable long employeeId, @RequestBody byte[] photo) {
|
|
String imageUrl = photoService.uploadProfilePhoto(employeeId, photo);
|
|
employeeService.patchProfileImage(employeeId, imageUrl);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
|
|
@PatchMapping("/block/{employeeId}/{blockStatus}")
|
|
public ResponseEntity<Void> patchImageProfile(@PathVariable long employeeId, @PathVariable boolean blockStatus) {
|
|
employeeService.patchBlockEmployee(employeeId, blockStatus);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
|
|
}
|