Compare commits
2 commits
8574e32e34
...
967946bee2
Author | SHA1 | Date | |
---|---|---|---|
967946bee2 | |||
2f6222ff00 |
2 changed files with 63 additions and 4 deletions
36
api/pmt.yml
36
api/pmt.yml
|
@ -210,3 +210,39 @@ paths:
|
|||
type: string
|
||||
500:
|
||||
$ref: "#/components/responses/InternalError"
|
||||
|
||||
/project/{id}/employee/{employeeId}:
|
||||
delete:
|
||||
operationId: "removeEmployeeFromProject"
|
||||
description: "Removes an employee from a Project"
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
required: true
|
||||
- in: path
|
||||
name: employeeId
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
required: true
|
||||
responses:
|
||||
204:
|
||||
description: "Deletes the employee from the Project"
|
||||
401:
|
||||
$ref: "#/components/responses/Unauthorized"
|
||||
404:
|
||||
description: "Employee not found"
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
409:
|
||||
$ref: "#/components/responses/Conflict"
|
||||
500:
|
||||
$ref: "#/components/responses/InternalError"
|
||||
503:
|
||||
$ref: "#/components/responses/ServiceUnavailable"
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package de.hmmh.pmt;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.hmmh.pmt.db.Allocation;
|
||||
import de.hmmh.pmt.db.AllocationRepository;
|
||||
import de.hmmh.pmt.db.Project;
|
||||
import de.hmmh.pmt.db.ProjectRepository;
|
||||
|
||||
import de.hmmh.pmt.db.*;
|
||||
import de.hmmh.pmt.dtos.*;
|
||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||
import de.hmmh.pmt.employee.api.EmployeeControllerApi;
|
||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||
import de.hmmh.pmt.oas.DefaultApi;
|
||||
import de.hmmh.pmt.util.Mapper;
|
||||
|
@ -143,4 +142,28 @@ public class ApiController implements DefaultApi {
|
|||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
||||
if (!projectRepository.existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
EmployeeResponseDTO employee;
|
||||
try {
|
||||
employee = apiClientFactory.getEmployeeApi().findById(employeeId);
|
||||
} catch (HttpClientErrorException exception) {
|
||||
return new ResponseEntity<>(exception.getStatusCode().equals(HttpStatus.NOT_FOUND)
|
||||
? HttpStatus.NOT_FOUND
|
||||
: HttpStatus.SERVICE_UNAVAILABLE);
|
||||
} catch (RestClientException exception) {
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
Allocation allocation = allocationRepository.findById(id);
|
||||
if (allocation.getEmployeeId().equals(employeeId)) {
|
||||
allocationRepository.delete(allocation);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue