PMT-43: Add Separate Endpoint for Completing Project, because of Spring and Generation limitation
All checks were successful
Quality Check / Validate OAS (push) Successful in 54s
Quality Check / Validate OAS (pull_request) Successful in 1m7s
Quality Check / Linting (push) Successful in 2m7s
Quality Check / Linting (pull_request) Successful in 2m10s
Quality Check / Testing (push) Successful in 2m24s
Quality Check / Static Analysis (push) Successful in 2m28s
Quality Check / Testing (pull_request) Successful in 2m18s
Quality Check / Static Analysis (pull_request) Successful in 2m22s

This commit is contained in:
Dominik Säume 2024-10-23 11:20:52 +02:00
parent c2a93e5a75
commit 5c4bfdacbe
4 changed files with 86 additions and 4 deletions

View file

@ -65,9 +65,6 @@ components:
plannedEnd:
type: string
format: date-time
end:
type: string
format: date-time
CreatedProjectDTO:
type: object
properties:
@ -260,3 +257,27 @@ paths:
type: string
500:
$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"

View file

@ -19,6 +19,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDateTime;
import java.util.Optional;
@Controller
@ -172,4 +173,17 @@ public class ApiController implements DefaultApi {
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);
}
}

View file

@ -38,7 +38,6 @@ public class Mapper {
project.setAdministratorId(dto.getAdministratorId());
project.setStart(dto.getStart());
project.setPlannedEnd(dto.getPlannedEnd());
project.setRealEnd(dto.getEnd());
return project;
}
}

View 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);
}
}