PMT-43: Add Separate Endpoint for Completing Project, because of Spring and Generation limitation
This commit is contained in:
parent
8abec2433d
commit
65836b7772
4 changed files with 86 additions and 4 deletions
27
api/pmt.yml
27
api/pmt.yml
|
@ -65,9 +65,6 @@ components:
|
||||||
plannedEnd:
|
plannedEnd:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
end:
|
|
||||||
type: string
|
|
||||||
format: date-time
|
|
||||||
CreatedProjectDTO:
|
CreatedProjectDTO:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -299,6 +296,30 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
|
/project/{id}/completed:
|
||||||
|
post:
|
||||||
|
operationId: "completeProject"
|
||||||
|
description: "Complete a specific project"
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
204:
|
||||||
|
description: "Completed"
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Project not found"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
500:
|
||||||
|
$ref: "#/components/responses/InternalError"
|
||||||
|
|
||||||
/project/{id}/employee/{employeeId}:
|
/project/{id}/employee/{employeeId}:
|
||||||
delete:
|
delete:
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -176,6 +177,19 @@ public class ApiController implements DefaultApi {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> completeProject(Long id) {
|
||||||
|
Optional<Project> optionalProject = projectRepository.findById(id);
|
||||||
|
if (optionalProject.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
Project project = optionalProject.get();
|
||||||
|
|
||||||
|
project.setRealEnd(LocalDateTime.now());
|
||||||
|
projectRepository.save(project);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
||||||
Optional<Allocation> allocation = allocationRepository.findById(new AllocationId(id, employeeId));
|
Optional<Allocation> allocation = allocationRepository.findById(new AllocationId(id, employeeId));
|
||||||
|
|
|
@ -70,7 +70,6 @@ public class Mapper {
|
||||||
project.setAdministratorId(dto.getAdministratorId());
|
project.setAdministratorId(dto.getAdministratorId());
|
||||||
project.setStart(dto.getStart());
|
project.setStart(dto.getStart());
|
||||||
project.setPlannedEnd(dto.getPlannedEnd());
|
project.setPlannedEnd(dto.getPlannedEnd());
|
||||||
project.setRealEnd(dto.getEnd());
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
src/test/java/de/hmmh/pmt/project/EditTest.java
Normal file
48
src/test/java/de/hmmh/pmt/project/EditTest.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
|
import de.hmmh.pmt.dtos.UpdateProjectDTO;
|
||||||
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.RequestBuilder;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
public class EditTest extends IntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void successfullyRenamed() throws Exception {
|
||||||
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
|
.thenReturn(new EmployeeResponseDTO());
|
||||||
|
|
||||||
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
|
Project projectToEdit = allProjects.get("medical-research");
|
||||||
|
|
||||||
|
UpdateProjectDTO dto = new UpdateProjectDTO();
|
||||||
|
dto.setName("Mafia Drug Ring");
|
||||||
|
dto.setGoal(projectToEdit.getGoal());
|
||||||
|
dto.setCustomerId(projectToEdit.getCustomerId());
|
||||||
|
dto.setAdministratorId(projectToEdit.getAdministratorId());
|
||||||
|
dto.setStart(projectToEdit.getStart());
|
||||||
|
dto.setPlannedEnd(projectToEdit.getPlannedEnd());
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(getRequest(projectToEdit.getId(), dto))
|
||||||
|
.andExpect(status().isNoContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestBuilder getRequest(long id, UpdateProjectDTO dto) throws Exception {
|
||||||
|
return MockMvcRequestBuilders
|
||||||
|
.put(baseUri + "/project/" + id)
|
||||||
|
.content(this.objectMapper.writeValueAsString(dto))
|
||||||
|
.contentType(MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue