You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.2 KiB
86 lines
3.2 KiB
package kr.re.etri.autoflow.controllers;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import kr.re.etri.autoflow.entity.ProjectEntity;
|
|
import kr.re.etri.autoflow.payload.request.BaseSearchRequest;
|
|
import kr.re.etri.autoflow.payload.request.ProjectRequest;
|
|
import kr.re.etri.autoflow.service.ProjectService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
import java.util.List;
|
|
|
|
@Tag(name = "프로젝트 API", description = "Project CRUD 기능 제공")
|
|
@RestController
|
|
@RequestMapping("/api/projects")
|
|
@RequiredArgsConstructor
|
|
public class ProjectController {
|
|
|
|
private final ProjectService projectService;
|
|
|
|
@Operation(summary = "전체 프로젝트 목록 조회")
|
|
@GetMapping
|
|
public ResponseEntity<List<ProjectEntity>> getAllProjects() {
|
|
return ResponseEntity.ok(projectService.findAll());
|
|
}
|
|
|
|
@Operation(summary = "ID로 프로젝트 조회")
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<ProjectEntity> getProjectById(
|
|
@Parameter(description = "조회할 프로젝트 ID", required = true, in = ParameterIn.PATH)
|
|
@PathVariable("id") Long id) {
|
|
|
|
return projectService.findById(id)
|
|
.map(ResponseEntity::ok)
|
|
.orElse(ResponseEntity.notFound().build());
|
|
}
|
|
|
|
@Operation(summary = "검색 및 페이지네이션 프로젝트 목록 조회")
|
|
@GetMapping("/search")
|
|
public ResponseEntity<Page<ProjectEntity>> searchProjects(
|
|
@ModelAttribute BaseSearchRequest request) {
|
|
Page<ProjectEntity> page = projectService.search(request);
|
|
return ResponseEntity.ok(page);
|
|
}
|
|
|
|
@Operation(summary = "프로젝트 생성")
|
|
@PostMapping
|
|
public ResponseEntity<?> createProject(@RequestBody ProjectEntity project) {
|
|
try {
|
|
ProjectEntity saved = projectService.create(project);
|
|
return ResponseEntity.ok(saved);
|
|
} catch (IllegalArgumentException e) {
|
|
return ResponseEntity.badRequest().body(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@Operation(summary = "프로젝트 수정")
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<ProjectEntity> updateProject(
|
|
@Parameter(description = "수정할 프로젝트 ID", required = true, in = ParameterIn.PATH)
|
|
@PathVariable("id") Long id,
|
|
@RequestBody ProjectRequest dto) {
|
|
|
|
return projectService.update(id, dto)
|
|
.map(ResponseEntity::ok)
|
|
.orElse(ResponseEntity.notFound().build());
|
|
}
|
|
|
|
@Operation(summary = "프로젝트 삭제")
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<Void> deleteProject(
|
|
@Parameter(description = "삭제할 프로젝트 ID", required = true, in = ParameterIn.PATH)
|
|
@PathVariable("id") Long id) {
|
|
if (projectService.delete(id)) {
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
return ResponseEntity.notFound().build();
|
|
}
|
|
}
|