Compare commits

...

1 commit

Author SHA1 Message Date
da7905a3a8 PMT-32: NEEDS SPLITTING AND CURRENT PR #6
Some checks failed
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m9s
Quality Check / Testing (push) Failing after 1m8s
Quality Check / Static Analysis (push) Successful in 1m13s
2024-10-02 08:24:07 +02:00
5 changed files with 118 additions and 26 deletions

View file

@ -15,19 +15,19 @@ components:
scheme: bearer scheme: bearer
bearerFormat: JWT bearerFormat: JWT
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:
@ -35,16 +35,16 @@ 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: 500:
$ref: "#/components/responses/InternalError" $ref: "#/components/responses/InternalError"

View file

@ -2,9 +2,11 @@ package de.hmmh.pmt;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import de.hmmh.pmt.employee.ApiClientFactory; 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.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 jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -18,6 +20,10 @@ import java.util.Optional;
public class ApiController implements DefaultApi { public class ApiController implements DefaultApi {
@Autowired @Autowired
private ApiClientFactory apiClientFactory; private ApiClientFactory apiClientFactory;
@Autowired
private ProjectRepository projectRepository;
// apiClientFactory.getEmployeeApi().findAll1()
@Override @Override
public Optional<ObjectMapper> getObjectMapper() { public Optional<ObjectMapper> getObjectMapper() {
@ -30,15 +36,16 @@ public class ApiController implements DefaultApi {
} }
@Override @Override
public ResponseEntity<HelloOut> getHello() { public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
GetAllProjectsDTO response = new GetAllProjectsDTO();
StringBuilder employees = new StringBuilder(); for (Project project : this.projectRepository.findAll()){
for (EmployeeResponseDTO employeeResponseDTO : apiClientFactory.getEmployeeApi().findAll1()) { ProjectInfo projectInfo = new ProjectInfo();
employees.append(employeeResponseDTO.toString()); projectInfo.setId(project.getId());
projectInfo.setName(project.getName());
response.add(projectInfo);
} }
HelloOut hello = new HelloOut(); return ResponseEntity.ok(response);
hello.setMsg(employees.toString());
return ResponseEntity.ok(hello);
} }
} }

View file

@ -0,0 +1,47 @@
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 class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
@Size(min = 3, max = 64)
private String name;
@NotBlank
@Size(min = 10)
private String goal;
@NotNull
private Long customerId;
@NotNull
private Long administratorId; // Is an Employee
@NotNull
private LocalDateTime start;
@NotNull
private LocalDateTime plannedEnd;
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
}

View file

@ -0,0 +1,6 @@
package de.hmmh.pmt.db;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProjectRepository extends JpaRepository<Project, Long> {
}

View file

@ -0,0 +1,32 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
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;
public class GetAllTest extends IntegrationTest {
@Test
void noProjects() throws Exception {
mvc
.perform(get(baseUri + "/project"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", empty()));
}
@Test
void multipleProjects() throws Exception {
createTestData();
mvc
.perform(get(baseUri + "/project"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(3)));
}
}