feat(project): update project DTO and controller mapping
All checks were successful
Quality Check / Tests (pull_request) Successful in 51s
Quality Check / Checkstyle Main (pull_request) Successful in 54s

This commit is contained in:
Jan Gleytenhoover 2024-09-25 13:27:28 +02:00
parent bee9d307fa
commit 5ae5aca076
Signed by: jank
GPG Key ID: B267751B8AE29EFE
6 changed files with 9 additions and 34 deletions

@ -1,7 +1,6 @@
package de.szut.lf8_starter.project; package de.szut.lf8_starter.project;
import de.szut.lf8_starter.project.dto.GetProjectDto; import de.szut.lf8_starter.project.dto.GetProjectDto;
import de.szut.lf8_starter.project.dto.ProjectGetDto;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -25,7 +24,7 @@ public class ProjectController {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "all projects", @ApiResponse(responseCode = "200", description = "all projects",
content = {@Content(mediaType = "application/json", content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = ProjectGetDto.class))}), schema = @Schema(implementation = GetProjectDto.class))}),
@ApiResponse(responseCode = "401", description = "not authorized", @ApiResponse(responseCode = "401", description = "not authorized",
content = @Content)}) content = @Content)})
@GetMapping @GetMapping

@ -25,6 +25,7 @@ public class ProjectMapper {
public GetProjectDto mapToGetDto(ProjectEntity projectEntity) { public GetProjectDto mapToGetDto(ProjectEntity projectEntity) {
GetProjectDto getProjectDto = new GetProjectDto(); GetProjectDto getProjectDto = new GetProjectDto();
getProjectDto.setId(projectEntity.getId());
getProjectDto.setName(projectEntity.getName()); getProjectDto.setName(projectEntity.getName());
getProjectDto.setComment(projectEntity.getComment()); getProjectDto.setComment(projectEntity.getComment());
getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee()); getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee());

@ -12,6 +12,8 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class GetProjectDto { public class GetProjectDto {
private long id;
@NotBlank @NotBlank
private String name; private String name;

@ -1,29 +0,0 @@
package de.szut.lf8_starter.project.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDate;
import java.util.List;
@Data
@AllArgsConstructor
public class ProjectGetDto {
private long id;
private String name;
private long leadingEmployee;
private List<Long> employees;
private long contractor;
private String contractorName;
private String comment;
private LocalDate startDate;
private LocalDate endDate;
}

@ -5,6 +5,7 @@ import java.util.stream.Collectors;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer; import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;

@ -5,6 +5,7 @@ import de.szut.lf8_starter.project.ProjectRepository;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
@ -18,7 +19,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc(addFilters = false)
public class ProjectFindAll { public class ProjectFindAll {
@Autowired @Autowired
private ProjectRepository projectRepository; private ProjectRepository projectRepository;
@ -50,10 +51,10 @@ public class ProjectFindAll {
.andExpect(jsonPath("$[0].comment").value("comment")) .andExpect(jsonPath("$[0].comment").value("comment"))
.andExpect(jsonPath("$[0].contractor").value(1)) .andExpect(jsonPath("$[0].contractor").value(1))
.andExpect(jsonPath("$[0].contractorName").value("contractorName")) .andExpect(jsonPath("$[0].contractorName").value("contractorName"))
.andExpect(jsonPath("$[0].endDate").value("2024-01-01")) .andExpect(jsonPath("$[0].endDate").value("01.01.2024"))
.andExpect(jsonPath("$[0].leadingEmployee").value(1)) .andExpect(jsonPath("$[0].leadingEmployee").value(1))
.andExpect(jsonPath("$[0].name").value("name")) .andExpect(jsonPath("$[0].name").value("name"))
.andExpect(jsonPath("$[0].startDate").value("2021-01-01")) .andExpect(jsonPath("$[0].startDate").value("01.01.2021"))
.andExpect(jsonPath("$[0].employees").isArray()) .andExpect(jsonPath("$[0].employees").isArray())
.andExpect(jsonPath("$[0].employees", hasSize(3))); .andExpect(jsonPath("$[0].employees", hasSize(3)));
} }