init: SR System — Helpdesk & ITAM Portal
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.srsystem.controller;
|
||||
|
||||
import com.srsystem.config.jwt.CurrentUser;
|
||||
import com.srsystem.dto.ApiResponse;
|
||||
import com.srsystem.dto.CreateProjectRequest;
|
||||
import com.srsystem.entity.Employee;
|
||||
import com.srsystem.entity.Project;
|
||||
import com.srsystem.entity.enums.ProjectStatus;
|
||||
import com.srsystem.service.ProjectService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "Project", description = "프로젝트 관리 API")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/projects")
|
||||
@RequiredArgsConstructor
|
||||
@SecurityRequirement(name = "bearerAuth")
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
@Operation(summary = "내 프로젝트 목록 조회", description = "로그인한 사용자가 참여 중인 프로젝트 목록을 조회합니다")
|
||||
@PreAuthorize("hasAnyRole('EMPLOYEE', 'MANAGER', 'ADMIN')")
|
||||
@GetMapping("/my")
|
||||
public ResponseEntity<ApiResponse<List<Project>>> getMyProjects(@CurrentUser Employee currentUser) {
|
||||
List<Project> projects = projectService.getMyProjects(currentUser.getEmpId());
|
||||
return ResponseEntity.ok(ApiResponse.ok(projects));
|
||||
}
|
||||
|
||||
@Operation(summary = "프로젝트 단건 조회", description = "프로젝트 ID 로 단일 프로젝트 정보를 조회합니다")
|
||||
@PreAuthorize("hasAnyRole('EMPLOYEE', 'MANAGER', 'ADMIN')")
|
||||
@GetMapping("/{projectId}")
|
||||
public ResponseEntity<ApiResponse<Project>> getProject(@PathVariable Long projectId) {
|
||||
Project project = projectService.getProject(projectId);
|
||||
return ResponseEntity.ok(ApiResponse.ok(project));
|
||||
}
|
||||
|
||||
@Operation(summary = "프로젝트 목록 조회", description = "전체 프로젝트 목록을 조회합니다. 상태 필터 옵션 포함")
|
||||
@PreAuthorize("hasAnyRole('MANAGER', 'ADMIN')")
|
||||
@Transactional(readOnly = true)
|
||||
@GetMapping
|
||||
public ResponseEntity<ApiResponse<List<Project>>> findAll(
|
||||
@RequestParam(required = false) ProjectStatus status) {
|
||||
List<Project> projects = projectService.findAll(status);
|
||||
return ResponseEntity.ok(ApiResponse.ok(projects));
|
||||
}
|
||||
|
||||
@Operation(summary = "프로젝트 생성", description = "새로운 프로젝트를 등록합니다")
|
||||
@PreAuthorize("hasAnyRole('MANAGER', 'ADMIN')")
|
||||
@PostMapping
|
||||
public ResponseEntity<ApiResponse<Project>> create(
|
||||
@RequestBody @Valid CreateProjectRequest request) {
|
||||
Project project = projectService.create(request);
|
||||
return ResponseEntity.ok(ApiResponse.ok("프로젝트가 등록되었습니다", project));
|
||||
}
|
||||
|
||||
@Operation(summary = "프로젝트 수정", description = "프로젝트 정보를 수정합니다")
|
||||
@PreAuthorize("hasAnyRole('MANAGER', 'ADMIN')")
|
||||
@PutMapping("/{projectId}")
|
||||
public ResponseEntity<ApiResponse<Project>> update(
|
||||
@PathVariable Long projectId,
|
||||
@RequestBody @Valid CreateProjectRequest request) {
|
||||
Project project = projectService.update(projectId, request);
|
||||
return ResponseEntity.ok(ApiResponse.ok("프로젝트가 수정되었습니다", project));
|
||||
}
|
||||
|
||||
@Operation(summary = "프로젝트 삭제", description = "프로젝트를 삭제합니다 (Soft Delete)")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@DeleteMapping("/{projectId}")
|
||||
public ResponseEntity<ApiResponse<Void>> delete(
|
||||
@PathVariable Long projectId) {
|
||||
projectService.delete(projectId);
|
||||
return ResponseEntity.ok(ApiResponse.ok("프로젝트가 삭제되었습니다", null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user