2024-10-02 08:21:10 +02:00
|
|
|
package de.szut.lf8_starter.project;
|
|
|
|
|
|
|
|
import de.szut.lf8_starter.project.dto.CreateProjectDto;
|
|
|
|
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
|
|
|
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 jakarta.validation.Valid;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(value = "/projects")
|
|
|
|
public class CreateProjectAction {
|
|
|
|
private final ProjectService projectService;
|
|
|
|
private final ProjectMapper projectMapper;
|
|
|
|
|
|
|
|
public CreateProjectAction(ProjectService projectService, ProjectMapper mappingService) {
|
|
|
|
this.projectService = projectService;
|
|
|
|
this.projectMapper = mappingService;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Creates a new Project")
|
|
|
|
@ApiResponses(value = {
|
|
|
|
@ApiResponse(responseCode = "201", description = "created project", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = GetProjectDto.class))}),
|
|
|
|
@ApiResponse(responseCode = "400", description = "invalid JSON posted", content = @Content),
|
|
|
|
@ApiResponse(responseCode = "401", description = "not authorized", content = @Content)})
|
|
|
|
@PostMapping
|
|
|
|
@ResponseStatus(code = HttpStatus.CREATED)
|
|
|
|
public GetProjectDto create(@RequestBody @Valid CreateProjectDto createProjectDto) {
|
|
|
|
ProjectEntity projectEntity = this.projectMapper.mapCreateDtoToEntity(createProjectDto);
|
|
|
|
|
|
|
|
projectEntity = this.projectService.create(projectEntity);
|
|
|
|
|
|
|
|
return this.projectMapper.mapToGetDto(projectEntity);
|
|
|
|
}
|
|
|
|
}
|