diff --git a/api/pmt.yml b/api/pmt.yml index 06e99b1..159e6a5 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -14,20 +14,20 @@ components: type: http scheme: bearer bearerFormat: JWT - schemas: - HelloOut: - description: "A Test Schema" + schemas: + ProjectInfo: type: object - properties: - msg: + properties: + id: + type: integer + format: int64 + name: type: string + GetAllProjectsDTO: + type: array + items: + $ref: "#/components/schemas/ProjectInfo" responses: - OK: - description: "OK" - content: - text/plain: - schema: - type: string InternalError: description: "Internal Server Error" content: @@ -35,16 +35,14 @@ components: schema: type: string paths: - /hello: + /project: get: - operationId: "GetHello" - description: "A Simple Hello World Endpoint" + operationId: "getAllProjects" + description: "Get a List of all Projects" responses: 200: - description: "A Hello Response" + description: "" content: application/json: schema: - $ref: "#/components/schemas/HelloOut" - 500: - $ref: "#/components/responses/InternalError" \ No newline at end of file + $ref: "#/components/schemas/GetAllProjectsDTO" \ No newline at end of file diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 8b56898..5031841 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -2,9 +2,11 @@ package de.hmmh.pmt; import com.fasterxml.jackson.databind.ObjectMapper; import de.hmmh.pmt.employee.ApiClientFactory; -import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO; +import de.hmmh.pmt.db.Project; +import de.hmmh.pmt.db.ProjectRepository; import de.hmmh.pmt.oas.DefaultApi; -import de.hmmh.pmt.dtos.HelloOut; +import de.hmmh.pmt.dtos.GetAllProjectsDTO; +import de.hmmh.pmt.dtos.ProjectInfo; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -18,6 +20,10 @@ import java.util.Optional; public class ApiController implements DefaultApi { @Autowired private ApiClientFactory apiClientFactory; + @Autowired + private ProjectRepository projectRepository; + + // apiClientFactory.getEmployeeApi().findAll1() @Override public Optional getObjectMapper() { @@ -30,15 +36,16 @@ public class ApiController implements DefaultApi { } @Override - public ResponseEntity getHello() { + public ResponseEntity getAllProjects() { + GetAllProjectsDTO response = new GetAllProjectsDTO(); - StringBuilder employees = new StringBuilder(); - for (EmployeeResponseDTO employeeResponseDTO : apiClientFactory.getEmployeeApi().findAll1()) { - employees.append(employeeResponseDTO.toString()); + for (Project project : this.projectRepository.findAll()){ + ProjectInfo projectInfo = new ProjectInfo(); + projectInfo.setId(project.getId()); + projectInfo.setName(project.getName()); + response.add(projectInfo); } - - HelloOut hello = new HelloOut(); - hello.setMsg(employees.toString()); - return ResponseEntity.ok(hello); + + return ResponseEntity.ok(response); } }