feat(project): Get all projects (SCRUM-15) #10

Merged
jank merged 13 commits from feature/get-all-projects into main 2024-09-25 11:38:31 +00:00
4 changed files with 109 additions and 0 deletions
Showing only changes of commit ee90ff7a5e - Show all commits

@ -0,0 +1,38 @@
package de.szut.lf8_starter.project;
import de.szut.lf8_starter.project.dto.ProjectGetDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "projects")
public class ProjectController {
private final ProjectService service;
private final ProjectMapper projectMapper;
public ProjectController(ProjectService service, ProjectMapper projectMapper) {
this.service = service;
this.projectMapper = projectMapper;
}
@Operation(summary = "returns all projects")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "all projects",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = ProjectGetDto.class))}),
@ApiResponse(responseCode = "401", description = "not authorized",
content = @Content)})
@GetMapping
public List<ProjectGetDto> findAll() {
return this.service
.readAll()
.stream()
.map(this.projectMapper::mapToGetDto)
.toList();
}
}

@ -0,0 +1,21 @@
package de.szut.lf8_starter.project;
import de.szut.lf8_starter.project.dto.ProjectGetDto;
import org.springframework.stereotype.Service;
@Service
public class ProjectMapper {
public ProjectGetDto mapToGetDto(ProjectEntity entity) {
return new ProjectGetDto(
entity.getId(),
entity.getName(),
entity.getLeadingEmployee(),
entity.getEmployees(),
entity.getContractor(),
entity.getContractorName(),
entity.getComment(),
entity.getStartDate(),
entity.getEndDate()
);
}
}

@ -0,0 +1,21 @@
package de.szut.lf8_starter.project;
import de.szut.lf8_starter.hello.HelloEntity;
import de.szut.lf8_starter.hello.HelloRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class ProjectService {
private final ProjectRepository repository;
public ProjectService(ProjectRepository repository) {
this.repository = repository;
}
public List<ProjectEntity> readAll() {
return this.repository.findAll();
}
}

@ -0,0 +1,29 @@
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;
}