feat(project): Delete project (SCRUM-35) #29
@ -30,4 +30,8 @@ public class ProjectService {
|
|||||||
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(Long id) {
|
||||||
|
this.projectRepository.deleteById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package de.szut.lf8_starter.project.action;
|
||||||
|
|
||||||
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
|
import de.szut.lf8_starter.project.ProjectMapper;
|
||||||
|
import de.szut.lf8_starter.project.ProjectService;
|
||||||
|
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 org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "projects")
|
||||||
|
public class RemoveProjectAction {
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
public RemoveProjectAction(ProjectService projectService, ProjectMapper projectMapper) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.projectMapper = projectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Remove project by ID")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "Project deleted", content = {}),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Project not found", content = @Content)
|
||||||
|
})
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<GetProjectDto> findArticleById(@PathVariable Long id) {
|
||||||
|
Optional<ProjectEntity> project = this.projectService.findById(id);
|
||||||
|
|
||||||
|
if (project.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.projectService.delete(id);
|
||||||
|
return new ResponseEntity<>(this.projectMapper.mapToGetDto(project.get()), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user