From ce038dc72511b7d46e0b0ee2fc1811ccadbad60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20K=C3=BCck?= Date: Thu, 24 Oct 2024 09:50:16 +0200 Subject: [PATCH 1/3] PMT-37: define Endpoint --- api/pmt.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/api/pmt.yml b/api/pmt.yml index 0a6419a..4df472f 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -27,6 +27,31 @@ components: type: array items: $ref: "#/components/schemas/ProjectInfo" + GetAllProjectInfoDTO: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + goal: + type: string + customerId: + type: integer + format: int64 + administratorId: + type: integer + format: int64 + start: + type: string + format: date-time + plannedEnd: + type: string + format: date-time + realEnd: + type: string + format: date-time CreateProjectDTO: type: object properties: @@ -213,6 +238,31 @@ paths: $ref: "#/components/responses/ServiceUnavailable" /project/{id}: + get: + operationId: "getProjectInfo" + description: "Get a list of all Project Informations" + parameters: + - in: path + name: id + schema: + type: integer + format: int64 + required: true + responses: + 200: + description: "Project Info recieved" + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllProjectInfoDTO" + 401: + $ref: "#/components/responses/Unauthorized" + 404: + $ref: "#/components/responses/NotFound" + 500: + $ref: "#/components/responses/InternalError" + 503: + $ref: "#/components/responses/ServiceUnavailable" post: operationId: "addEmployee" description: "Adds an employee to a specific Project" -- 2.45.2 From 3dd06fbf0c4108d6ddf67c9b1fa75dafca0f9ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20K=C3=BCck?= Date: Thu, 24 Oct 2024 09:50:42 +0200 Subject: [PATCH 2/3] PMT-37: implement Endpoint --- src/main/java/de/hmmh/pmt/ApiController.java | 12 ++++++++++++ src/main/java/de/hmmh/pmt/util/Mapper.java | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index c29c60b..4d35d4f 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -72,6 +72,18 @@ public class ApiController implements DefaultApi { return ResponseEntity.ok(response); } + @Override + public ResponseEntity getProjectInfo(Long id){ + Optional optionalProject = projectRepository.findById(id); + if (optionalProject.isEmpty()) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + Project project = optionalProject.get(); + + return ResponseEntity.ok(mapper.mapToGet(project)); + } + + @Override public ResponseEntity updateProject(Long id, UpdateProjectDTO body) { Optional optionalProject = projectRepository.findById(id); diff --git a/src/main/java/de/hmmh/pmt/util/Mapper.java b/src/main/java/de/hmmh/pmt/util/Mapper.java index 6c13bb7..63c22c4 100644 --- a/src/main/java/de/hmmh/pmt/util/Mapper.java +++ b/src/main/java/de/hmmh/pmt/util/Mapper.java @@ -1,13 +1,10 @@ package de.hmmh.pmt.util; import de.hmmh.pmt.db.Project; -import de.hmmh.pmt.dtos.CreateProjectDTO; -import de.hmmh.pmt.dtos.CreatedProjectDTO; -import de.hmmh.pmt.dtos.Employee; -import de.hmmh.pmt.dtos.Qualification ; +import de.hmmh.pmt.dtos.*; import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO; import de.hmmh.pmt.employee.dtos.QualificationGetDTO; -import de.hmmh.pmt.dtos.UpdateProjectDTO; + import org.springframework.stereotype.Component; import java.util.List; @@ -37,6 +34,19 @@ public class Mapper { return dto; } + public GetAllProjectInfoDTO mapToGet(Project project) { + GetAllProjectInfoDTO dto = new GetAllProjectInfoDTO(); + dto.setId(project.getId()); + dto.setName(project.getName()); + dto.setGoal(project.getGoal()); + dto.setCustomerId(project.getCustomerId()); + dto.setAdministratorId(project.getAdministratorId()); + dto.setStart(project.getStart()); + dto.setPlannedEnd(project.getPlannedEnd()); + dto.setRealEnd(project.getRealEnd()); + return dto; + } + public Employee map(EmployeeResponseDTO employeeResponseDTO) { Employee dto = new Employee(); dto.setId(employeeResponseDTO.getId()); -- 2.45.2 From 7fc105308af62186ca1696ee017d588d6da22d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20K=C3=BCck?= Date: Thu, 24 Oct 2024 09:52:07 +0200 Subject: [PATCH 3/3] PMT-37: implement endpoint testing --- .../hmmh/pmt/project/GetProjectInfoTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java diff --git a/src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java b/src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java new file mode 100644 index 0000000..b03f09d --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java @@ -0,0 +1,37 @@ +package de.hmmh.pmt.project; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import de.hmmh.pmt.IntegrationTest; +import de.hmmh.pmt.db.Project; + +public class GetProjectInfoTest extends IntegrationTest { + + @Test + void noProject() throws Exception { + mvc + .perform(get(baseUri + "/project/1")) + .andExpect(status().isNotFound()); + } + + @Test + void getProjectInfo() throws Exception { + Map allProjects = createTestProjectData(); + Project spaceStation = allProjects.get("space-station"); + mvc + .perform(get(baseUri + "/project/" +spaceStation.getId())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value(spaceStation.getId())) + .andExpect(jsonPath("$.name").value(spaceStation.getName())) + .andExpect(jsonPath("$.goal").value(spaceStation.getGoal())) + .andExpect(jsonPath("$.customerId").value(spaceStation.getCustomerId())) + .andExpect(jsonPath("$.administratorId").value(spaceStation.getAdministratorId())) + ; + + } + +} -- 2.45.2