Compare commits
2 commits
45d6b51967
...
1d4efc1f2b
Author | SHA1 | Date | |
---|---|---|---|
1d4efc1f2b | |||
13a8ee5d50 |
5 changed files with 80 additions and 25 deletions
|
@ -1,18 +1,26 @@
|
|||
package de.hmmh.pmt;
|
||||
|
||||
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.models.HelloOut;
|
||||
import de.hmmh.pmt.oas.dtos.GetAllProjectsDTO;
|
||||
import de.hmmh.pmt.oas.dtos.ProjectInfo;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||
public class ApiController implements DefaultApi {
|
||||
@Autowired
|
||||
private ProjectRepository projectRepository;
|
||||
|
||||
@Override
|
||||
public Optional<ObjectMapper> getObjectMapper() {
|
||||
|
@ -25,9 +33,16 @@ public class ApiController implements DefaultApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<HelloOut> getHello() {
|
||||
HelloOut hello = new HelloOut();
|
||||
hello.setMsg("Hello World");
|
||||
return ResponseEntity.ok(hello);
|
||||
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
||||
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
37
src/main/java/de/hmmh/pmt/db/Project.java
Normal file
37
src/main/java/de/hmmh/pmt/db/Project.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package de.hmmh.pmt.db;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "project")
|
||||
public final class Project {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
private LocalDateTime start;
|
||||
|
||||
@NotNull
|
||||
private LocalDateTime plannedEnd;
|
||||
|
||||
private LocalDateTime end;
|
||||
}
|
||||
|
6
src/main/java/de/hmmh/pmt/db/ProjectRepository.java
Normal file
6
src/main/java/de/hmmh/pmt/db/ProjectRepository.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package de.hmmh.pmt.db;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
||||
}
|
|
@ -5,22 +5,21 @@ info:
|
|||
version: 1.0.0
|
||||
servers:
|
||||
- url: /api/v1
|
||||
|
||||
components:
|
||||
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:
|
||||
|
@ -28,16 +27,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"
|
||||
$ref: "#/components/schemas/GetAllProjectsDTO"
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"modelPackage": "de.hmmh.pmt.oas.models",
|
||||
"modelPackage": "de.hmmh.pmt.oas.dtos",
|
||||
"apiPackage": "de.hmmh.pmt.oas",
|
||||
"invokerPackage": "de.hmmh.pmt.oas",
|
||||
"java8": false,
|
||||
|
|
Loading…
Reference in a new issue