PMT-32: Define Get All Projects DTO, Endpoint and implement them
All checks were successful
Quality Check / Validate OAS (push) Successful in 35s
Quality Check / Testing (push) Successful in 1m38s
Quality Check / Linting (push) Successful in 1m48s
Quality Check / Static Analysis (push) Successful in 1m49s

This commit is contained in:
Dominik Säume 2024-09-25 11:18:36 +02:00
parent 13a8ee5d50
commit 1d4efc1f2b
No known key found for this signature in database
GPG key ID: F5211AA345CF6871
3 changed files with 37 additions and 25 deletions

View file

@ -1,18 +1,26 @@
package de.hmmh.pmt; package de.hmmh.pmt;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.db.ProjectRepository;
import de.hmmh.pmt.oas.DefaultApi; import de.hmmh.pmt.oas.DefaultApi;
import de.hmmh.pmt.oas.models.HelloOut; import de.hmmh.pmt.oas.dtos.GetAllProjectsDTO;
import de.hmmh.pmt.oas.dtos.ProjectInfo;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Controller @Controller
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}") @RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
public class ApiController implements DefaultApi { public class ApiController implements DefaultApi {
@Autowired
private ProjectRepository projectRepository;
@Override @Override
public Optional<ObjectMapper> getObjectMapper() { public Optional<ObjectMapper> getObjectMapper() {
@ -25,9 +33,16 @@ public class ApiController implements DefaultApi {
} }
@Override @Override
public ResponseEntity<HelloOut> getHello() { public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
HelloOut hello = new HelloOut(); GetAllProjectsDTO response = new GetAllProjectsDTO();
hello.setMsg("Hello World");
return ResponseEntity.ok(hello); for (Project project : this.projectRepository.findAll()){
ProjectInfo projectInfo = new ProjectInfo();
projectInfo.setId(project.getId());
projectInfo.setName(project.getName());
response.add(projectInfo);
}
return ResponseEntity.ok(response);
} }
} }

View file

@ -5,22 +5,21 @@ info:
version: 1.0.0 version: 1.0.0
servers: servers:
- url: /api/v1 - url: /api/v1
components: components:
schemas: schemas:
HelloOut: ProjectInfo:
description: "A Test Schema"
type: object type: object
properties: properties:
msg: id:
type: integer
format: int64
name:
type: string type: string
GetAllProjectsDTO:
type: array
items:
$ref: "#/components/schemas/ProjectInfo"
responses: responses:
OK:
description: "OK"
content:
text/plain:
schema:
type: string
InternalError: InternalError:
description: "Internal Server Error" description: "Internal Server Error"
content: content:
@ -28,16 +27,14 @@ components:
schema: schema:
type: string type: string
paths: paths:
/hello: /project:
get: get:
operationId: "GetHello" operationId: "getAllProjects"
description: "A Simple Hello World Endpoint" description: "Get a List of all Projects"
responses: responses:
200: 200:
description: "A Hello Response" description: ""
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/HelloOut" $ref: "#/components/schemas/GetAllProjectsDTO"
500:
$ref: "#/components/responses/InternalError"

View file

@ -1,5 +1,5 @@
{ {
"modelPackage": "de.hmmh.pmt.oas.models", "modelPackage": "de.hmmh.pmt.oas.dtos",
"apiPackage": "de.hmmh.pmt.oas", "apiPackage": "de.hmmh.pmt.oas",
"invokerPackage": "de.hmmh.pmt.oas", "invokerPackage": "de.hmmh.pmt.oas",
"java8": false, "java8": false,