From 5b296bef03e43cd3f924701735fb795947d6f597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 14:37:41 +0900 Subject: [PATCH 1/7] =?UTF-8?q?Feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 39 ++++++++++++++++ .../domain/category/entity/LabelCategory.java | 45 +++++++++++++++++++ .../category/entity/dto/CategoryRequest.java | 16 +++++++ .../category/entity/dto/CategoryResponse.java | 22 +++++++++ .../repository/CategoryRepository.java | 9 ++++ .../category/service/CategoryService.java | 42 +++++++++++++++++ .../image/controller/ImageController.java | 6 +-- .../domain/image/service/ImageService.java | 5 +-- .../domain/label/service/LabelService.java | 3 +- .../service/ParticipantService.java | 36 +++++++++++++++ .../project/controller/ProjectController.java | 6 +-- .../domain/project/entity/Project.java | 10 +++++ .../project/service/ProjectService.java | 22 ++++----- .../workspace/service/WorkspaceService.java | 2 +- .../global/config/CustomWebSocketConfig1.java | 4 -- .../worlabel/global/exception/ErrorCode.java | 4 +- .../image/service/ImageServiceUnitTest.java | 2 +- .../service/ProjectServiceUnitTest.java | 5 +-- 18 files changed, 246 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java create mode 100644 backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java create mode 100644 backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java create mode 100644 backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java create mode 100644 backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java create mode 100644 backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java create mode 100644 backend/src/main/java/com/worlabel/domain/participant/service/ParticipantService.java delete mode 100644 backend/src/main/java/com/worlabel/global/config/CustomWebSocketConfig1.java diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java new file mode 100644 index 0000000..faca1a2 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java @@ -0,0 +1,39 @@ +package com.worlabel.domain.category.controller; + +import com.worlabel.domain.category.entity.dto.CategoryRequest; +import com.worlabel.domain.category.entity.dto.CategoryResponse; +import com.worlabel.domain.category.service.CategoryService; +import com.worlabel.domain.folder.entity.dto.FolderRequest; +import com.worlabel.domain.folder.entity.dto.FolderResponse; +import com.worlabel.global.annotation.CurrentUser; +import com.worlabel.global.config.swagger.SwaggerApiError; +import com.worlabel.global.config.swagger.SwaggerApiSuccess; +import com.worlabel.global.exception.ErrorCode; +import com.worlabel.global.response.BaseResponse; +import com.worlabel.global.response.SuccessResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "레이블 카테고리 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/projects/{project_id}/categories") +public class LabelCategoryController { + + private final CategoryService categoryService; + + @Operation(summary = "레이블 카테고리 생성", description = "프로젝트에 카테고리를 생성합니다.") + @SwaggerApiSuccess(description = "카테고리 성공적으로 생성합니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @PostMapping + public BaseResponse createFolder( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId, + @RequestBody final CategoryRequest categoryRequest) { +// return SuccessResponse.of(folderResponse); + CategoryResponse response = categoryService.createCategory(memberId, projectId, categoryRequest); + return SuccessResponse.empty(); + } +} diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java b/backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java new file mode 100644 index 0000000..7a0caf8 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java @@ -0,0 +1,45 @@ +package com.worlabel.domain.category.entity; + + +import com.worlabel.domain.project.entity.Project; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "label_category") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class LabelCategory { + + /** + * 레이블 카테고리 PK + */ + @Id + @Column(name = "label_category_id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + /** + * 레이블 카테고리 이름 + */ + @Column(name = "name", nullable = false) + private String name; + + /** + * 속한 프로젝트 + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "project_id", nullable = false) + private Project project; + + private LabelCategory(final String name,final Project project) { + this.name = name; + this.project = project; + } + + public static LabelCategory of(final String title, final Project project) { + return new LabelCategory(title, project); + } +} diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java b/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java new file mode 100644 index 0000000..291f202 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java @@ -0,0 +1,16 @@ +package com.worlabel.domain.category.entity.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Schema(name = "카테고리 요청 DTO", description = "카테고리 생성 및 수정을 위한 요청 DTO") +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class CategoryRequest { + + @Schema(description = "카테고리 이름", example = "Car") + private String categoryName; +} diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java b/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java new file mode 100644 index 0000000..53e3f4a --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java @@ -0,0 +1,22 @@ +package com.worlabel.domain.category.entity.dto; + +import com.worlabel.domain.category.entity.LabelCategory; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@Schema(name = "카테고리 응답 DTO", description = "카테고리 조회 응답 DTO") +public class CategoryResponse { + + @Schema(description = "카테고리 ID", example = "1") + private Integer id; + + @Schema(description = "카테고리 이름", example = "Car") + private String name; + + public static CategoryResponse from(LabelCategory labelCategory) { + return new CategoryResponse(labelCategory.getId(), labelCategory.getName()); + } +} diff --git a/backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java b/backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java new file mode 100644 index 0000000..c38ab39 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java @@ -0,0 +1,9 @@ +package com.worlabel.domain.category.repository; + +import com.worlabel.domain.category.entity.LabelCategory; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CategoryRepository extends JpaRepository { + + boolean existsByName(String name); +} diff --git a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java new file mode 100644 index 0000000..42e6153 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java @@ -0,0 +1,42 @@ +package com.worlabel.domain.category.service; + +import com.worlabel.domain.category.entity.LabelCategory; +import com.worlabel.domain.category.entity.dto.CategoryRequest; +import com.worlabel.domain.category.entity.dto.CategoryResponse; +import com.worlabel.domain.category.repository.CategoryRepository; +import com.worlabel.domain.participant.repository.ParticipantRepository; +import com.worlabel.domain.participant.service.ParticipantService; +import com.worlabel.domain.project.entity.Project; +import com.worlabel.domain.project.repository.ProjectRepository; +import com.worlabel.domain.project.service.ProjectService; +import com.worlabel.global.exception.CustomException; +import com.worlabel.global.exception.ErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class CategoryService { + + private final CategoryRepository categoryRepository; + private final ParticipantService participantService; + private final ProjectService projectService; + + public CategoryResponse createCategory(final Integer memberId, final Integer projectId, final CategoryRequest categoryRequest) { + participantService.checkEditorUnauthorized(memberId, projectId); + + // 이미 존재하는지 확인 있다면 예외 + if(categoryRepository.existsByName(categoryRequest.getCategoryName())){ + throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); + } + + Project project = projectService.getProject(projectId); + + LabelCategory labelCategory = LabelCategory.of(categoryRequest.getCategoryName(), project); + categoryRepository.save(labelCategory); + + return CategoryResponse.from(labelCategory); + } +} diff --git a/backend/src/main/java/com/worlabel/domain/image/controller/ImageController.java b/backend/src/main/java/com/worlabel/domain/image/controller/ImageController.java index a668802..a0e1d64 100644 --- a/backend/src/main/java/com/worlabel/domain/image/controller/ImageController.java +++ b/backend/src/main/java/com/worlabel/domain/image/controller/ImageController.java @@ -62,7 +62,7 @@ public class ImageController { @PutMapping("/{image_id}") @SwaggerApiSuccess(description = "이미지 폴더 이동.") @Operation(summary = "이미지 폴더 이동", description = "이미지가 위치한 폴더를 변경합니다.") - @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) + @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) public BaseResponse moveFolderImage( @CurrentUser final Integer memberId, @PathVariable("folder_id") final Integer folderId, @@ -78,7 +78,7 @@ public class ImageController { @DeleteMapping("/{image_id}") @SwaggerApiSuccess(description = "이미지 삭제.") @Operation(summary = "이미지 삭제", description = "폴더에서 해당 이미지를 제거합니다.") - @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) + @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) public BaseResponse deleteImage( @CurrentUser final Integer memberId, @PathVariable("folder_id") final Integer folderId, @@ -93,7 +93,7 @@ public class ImageController { @PutMapping("/{image_id}/status") @SwaggerApiSuccess(description = "이미지 상태 변경.") @Operation(summary = "이미지 상태 변경", description = "특정 이미지의 상태를 변경합니다.") - @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) + @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) public BaseResponse changeImageStatus( @CurrentUser final Integer memberId, @PathVariable("folder_id") final Integer folderId, diff --git a/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java b/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java index 4d30233..a6bfd31 100644 --- a/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java +++ b/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java @@ -7,7 +7,6 @@ import com.worlabel.domain.image.entity.dto.ImageResponse; import com.worlabel.domain.image.entity.dto.ImageStatusRequest; import com.worlabel.domain.image.repository.ImageRepository; import com.worlabel.domain.participant.entity.Participant; -import com.worlabel.domain.participant.entity.PrivilegeType; import com.worlabel.domain.participant.repository.ParticipantRepository; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; @@ -121,10 +120,10 @@ public class ImageService { // 편집자 이상의 권한을 확인하는 메서드 private void checkEditorParticipant(final Integer memberId, final Integer projectId) { Participant participant = participantRepository.findByMemberIdAndProjectId(memberId, projectId) - .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED)); + .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED)); if (!participant.getPrivilege().isEditeAuth()) { - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } diff --git a/backend/src/main/java/com/worlabel/domain/label/service/LabelService.java b/backend/src/main/java/com/worlabel/domain/label/service/LabelService.java index c41ff1b..90d49c1 100644 --- a/backend/src/main/java/com/worlabel/domain/label/service/LabelService.java +++ b/backend/src/main/java/com/worlabel/domain/label/service/LabelService.java @@ -17,7 +17,6 @@ import com.worlabel.global.service.S3UploadService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -152,7 +151,7 @@ public class LabelService { */ private void checkEditorExistParticipant(final Integer memberId, final Integer projectId) { if (participantRepository.doesParticipantUnauthorizedExistByMemberIdAndProjectId(memberId, projectId)) { - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } diff --git a/backend/src/main/java/com/worlabel/domain/participant/service/ParticipantService.java b/backend/src/main/java/com/worlabel/domain/participant/service/ParticipantService.java new file mode 100644 index 0000000..632658d --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/participant/service/ParticipantService.java @@ -0,0 +1,36 @@ +package com.worlabel.domain.participant.service; + +import com.worlabel.domain.participant.repository.ParticipantRepository; +import com.worlabel.global.exception.CustomException; +import com.worlabel.global.exception.ErrorCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class ParticipantService { + + private final ParticipantRepository participantRepository; + + /** + * 프로젝트 수정 권한이 없으면 예외 + * @param memberId 사용자 ID + * @param projectId 프로젝트 ID + */ + public void checkEditorUnauthorized(final Integer memberId, final Integer projectId){ + if (participantRepository.doesParticipantUnauthorizedExistByMemberIdAndProjectId(memberId, projectId)) { + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); + } + } + + /** + * 프로젝트 View 권한이 없으면 예외 + */ + public void checkViewerUnauthorized(final Integer memberId, final Integer projectId){ + if (participantRepository.doesParticipantUnauthorizedExistByMemberIdAndProjectId(memberId, projectId)) { + throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + } + } +} diff --git a/backend/src/main/java/com/worlabel/domain/project/controller/ProjectController.java b/backend/src/main/java/com/worlabel/domain/project/controller/ProjectController.java index 5affa25..bef2493 100644 --- a/backend/src/main/java/com/worlabel/domain/project/controller/ProjectController.java +++ b/backend/src/main/java/com/worlabel/domain/project/controller/ProjectController.java @@ -44,7 +44,7 @@ public class ProjectController { @Operation(summary = "프로젝트 조회", description = "프로젝트를 조회합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 조회합니다.") - @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) + @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @GetMapping("/projects/{project_id}") public BaseResponse getProject(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId) { ProjectResponse project = projectService.getProjectById(memberId, projectId); @@ -66,7 +66,7 @@ public class ProjectController { @Operation(summary = "프로젝트 수정", description = "프로젝트를 수정합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 수정합니다.") - @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) + @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @PutMapping("/projects/{project_id}") public BaseResponse updateProject( @CurrentUser final Integer memberId, @@ -89,7 +89,7 @@ public class ProjectController { @Operation(summary = "프로젝트 삭제", description = "프로젝트를 삭제합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 삭제합니다.") - @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) + @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @DeleteMapping("/projects/{project_id}") public BaseResponse deleteProject(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId) { diff --git a/backend/src/main/java/com/worlabel/domain/project/entity/Project.java b/backend/src/main/java/com/worlabel/domain/project/entity/Project.java index e9d6d6d..1739ca4 100644 --- a/backend/src/main/java/com/worlabel/domain/project/entity/Project.java +++ b/backend/src/main/java/com/worlabel/domain/project/entity/Project.java @@ -1,6 +1,7 @@ package com.worlabel.domain.project.entity; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.worlabel.domain.category.entity.LabelCategory; import com.worlabel.domain.workspace.entity.Workspace; import com.worlabel.global.common.BaseEntity; import jakarta.persistence.*; @@ -8,6 +9,9 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Getter @Entity @Table(name = "project") @@ -43,6 +47,12 @@ public class Project extends BaseEntity { @Enumerated(EnumType.STRING) private ProjectType projectType; + /** + * 프로젝트에 속한 카테고리 + */ + @OneToMany(mappedBy = "project", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private List category = new ArrayList<>(); + private Project(final String title, final Workspace workspace, final ProjectType projectType) { this.title = title; this.workspace = workspace; diff --git a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java index 3cb564e..2ad79c3 100644 --- a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java +++ b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java @@ -108,7 +108,7 @@ public class ProjectService { checkNotAdminParticipant(participantRequest.getMemberId(), projectId); Participant participant = participantRepository.findByMemberIdAndProjectId(participantRequest.getMemberId(), projectId) - .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED)); + .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED)); participant.updatePrivilege(participantRequest.getPrivilegeType()); } @@ -118,7 +118,7 @@ public class ProjectService { checkNotAdminParticipant(removeMemberId, projectId); Participant participant = participantRepository.findByMemberIdAndProjectId(removeMemberId, projectId) - .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED)); + .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED)); participantRepository.delete(participant); } @@ -150,6 +150,11 @@ public class ProjectService { } } + public Project getProject(final Integer projectId) { + return projectRepository.findById(projectId) + .orElseThrow(() -> new CustomException(ErrorCode.PROJECT_NOT_FOUND)); + } + private Workspace getWorkspace(final Integer memberId, final Integer workspaceId) { return workspaceRepository.findByMemberIdAndId(memberId, workspaceId) .orElseThrow(() -> new CustomException(ErrorCode.WORKSPACE_NOT_FOUND)); @@ -160,32 +165,27 @@ public class ProjectService { .orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)); } - private Project getProject(final Integer projectId) { - return projectRepository.findById(projectId) - .orElseThrow(() -> new CustomException(ErrorCode.PROJECT_NOT_FOUND)); - } - private void checkEditorParticipant(final Integer memberId, final Integer projectId) { if(participantRepository.doesParticipantUnauthorizedExistByMemberIdAndProjectId(memberId,projectId)){ - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } private void checkExistParticipant(final Integer memberId, final Integer projectId) { if (!participantRepository.existsByMemberIdAndProjectId(memberId, projectId)) { - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } private void checkAdminParticipant(final Integer memberId, final Integer projectId) { if (!participantRepository.existsByProjectIdAndMemberIdAndPrivilege(projectId, memberId, PrivilegeType.ADMIN)) { - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } private void checkNotAdminParticipant(final Integer memberId, final Integer projectId) { if (participantRepository.existsByProjectIdAndMemberIdAndPrivilege(projectId, memberId, PrivilegeType.ADMIN)) { - throw new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED); + throw new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED); } } diff --git a/backend/src/main/java/com/worlabel/domain/workspace/service/WorkspaceService.java b/backend/src/main/java/com/worlabel/domain/workspace/service/WorkspaceService.java index 99cdc87..e667150 100644 --- a/backend/src/main/java/com/worlabel/domain/workspace/service/WorkspaceService.java +++ b/backend/src/main/java/com/worlabel/domain/workspace/service/WorkspaceService.java @@ -127,6 +127,6 @@ public class WorkspaceService { private WorkspaceParticipant getWorkspaceParticipant(final Integer newMemberId, final Workspace workspace) { return workspaceParticipantRepository.findByMemberIdAndWorkspace(newMemberId, workspace) - .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_UNAUTHORIZED)); + .orElseThrow(() -> new CustomException(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED)); } } \ No newline at end of file diff --git a/backend/src/main/java/com/worlabel/global/config/CustomWebSocketConfig1.java b/backend/src/main/java/com/worlabel/global/config/CustomWebSocketConfig1.java deleted file mode 100644 index 456d455..0000000 --- a/backend/src/main/java/com/worlabel/global/config/CustomWebSocketConfig1.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.worlabel.global.config; - -public class CustomWebSocketConfig1 { -} diff --git a/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java b/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java index 5e473cf..d0c32be 100644 --- a/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java +++ b/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java @@ -37,10 +37,12 @@ public enum ErrorCode { // Project - 4000 PROJECT_NOT_FOUND(HttpStatus.NOT_FOUND, 4000, "프로젝트를 찾을 수 없습니다"), PROJECT_IMAGE_MISMATCH(HttpStatus.BAD_REQUEST, 4001, "해당 프로젝트에는 존재하지 않는 이미지입니다."), + PROJECT_CATEGORY_EXIST(HttpStatus.BAD_REQUEST,4002, "이미 존재하는 카테고리입니다."), // Participant - 5000, - PARTICIPANT_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 5000, "해당 프로젝트에 접근 권한이 없습니다."), + PARTICIPANT_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 5000, "해당 프로젝트에 참여하고 있지않습니다."), PARTICIPANT_BAD_REQUEST(HttpStatus.UNAUTHORIZED, 5001, "자기 자신의 권한을 바꿀 수 없습니다."), + PARTICIPANT_EDITOR_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 5002, "해당 프로젝트에 수정 권한이 없습니다."), // Folder - 6000, FOLDER_NOT_FOUND(HttpStatus.NOT_FOUND, 6000, "해당 폴더를 찾을 수 없습니다."), diff --git a/backend/src/test/java/com/worlabel/domain/image/service/ImageServiceUnitTest.java b/backend/src/test/java/com/worlabel/domain/image/service/ImageServiceUnitTest.java index 6bafa02..aaa6a3c 100644 --- a/backend/src/test/java/com/worlabel/domain/image/service/ImageServiceUnitTest.java +++ b/backend/src/test/java/com/worlabel/domain/image/service/ImageServiceUnitTest.java @@ -85,7 +85,7 @@ class ImageServiceUnitTest { // when & then assertThatThrownBy(() -> imageService.uploadImageList(List.of(mock(MultipartFile.class)), 1, 1, 1)) .isInstanceOf(CustomException.class) - .hasMessageContaining(ErrorCode.PARTICIPANT_UNAUTHORIZED.getMessage()); + .hasMessageContaining(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED.getMessage()); } @DisplayName("이미지 업로드 성공") diff --git a/backend/src/test/java/com/worlabel/domain/project/service/ProjectServiceUnitTest.java b/backend/src/test/java/com/worlabel/domain/project/service/ProjectServiceUnitTest.java index 71313c2..b535d0b 100644 --- a/backend/src/test/java/com/worlabel/domain/project/service/ProjectServiceUnitTest.java +++ b/backend/src/test/java/com/worlabel/domain/project/service/ProjectServiceUnitTest.java @@ -2,7 +2,6 @@ package com.worlabel.domain.project.service; import com.worlabel.domain.member.entity.Member; import com.worlabel.domain.member.repository.MemberRepository; -import com.worlabel.domain.participant.entity.Participant; import com.worlabel.domain.participant.entity.PrivilegeType; import com.worlabel.domain.participant.repository.ParticipantRepository; import com.worlabel.domain.project.entity.Project; @@ -142,7 +141,7 @@ class ProjectServiceUnitTest { // when & then assertThatThrownBy(() -> projectService.updateProject(1, 1, request)) .isInstanceOf(CustomException.class) - .hasMessageContaining(ErrorCode.PARTICIPANT_UNAUTHORIZED.getMessage()); + .hasMessageContaining(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED.getMessage()); } @DisplayName("프로젝트 수정에 성공하면 수정된 프로젝트가 반환된다.") @@ -172,7 +171,7 @@ class ProjectServiceUnitTest { // when & then assertThatThrownBy(() -> projectService.deleteProject(1, 1)) .isInstanceOf(CustomException.class) - .hasMessageContaining(ErrorCode.PARTICIPANT_UNAUTHORIZED.getMessage()); + .hasMessageContaining(ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED.getMessage()); } @DisplayName("프로젝트 삭제에 성공하면 예외 없이 수행된다.") From a4c669336a031cd4576a48adfefbf09b7eff9d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 14:47:12 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Feat:=20Category=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 13 ++++++++++++- .../category/service/CategoryService.java | 19 +++++++++++++++---- .../worlabel/global/exception/ErrorCode.java | 4 +++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java index faca1a2..44495e2 100644 --- a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java @@ -32,8 +32,19 @@ public class LabelCategoryController { @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @RequestBody final CategoryRequest categoryRequest) { -// return SuccessResponse.of(folderResponse); CategoryResponse response = categoryService.createCategory(memberId, projectId, categoryRequest); + return SuccessResponse.of(response); + } + + @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") + @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @DeleteMapping("/{category_id}") + public BaseResponse deleteFolder( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId, + @PathVariable("category_id") final Integer categoryId) { + categoryService.deleteCategory(memberId, projectId, categoryId); return SuccessResponse.empty(); } } diff --git a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java index 42e6153..480c2fd 100644 --- a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java +++ b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java @@ -4,10 +4,8 @@ import com.worlabel.domain.category.entity.LabelCategory; import com.worlabel.domain.category.entity.dto.CategoryRequest; import com.worlabel.domain.category.entity.dto.CategoryResponse; import com.worlabel.domain.category.repository.CategoryRepository; -import com.worlabel.domain.participant.repository.ParticipantRepository; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; -import com.worlabel.domain.project.repository.ProjectRepository; import com.worlabel.domain.project.service.ProjectService; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; @@ -15,6 +13,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @Service @Transactional @RequiredArgsConstructor @@ -28,8 +28,8 @@ public class CategoryService { participantService.checkEditorUnauthorized(memberId, projectId); // 이미 존재하는지 확인 있다면 예외 - if(categoryRepository.existsByName(categoryRequest.getCategoryName())){ - throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); + if (categoryRepository.existsByName(categoryRequest.getCategoryName())) { + throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); } Project project = projectService.getProject(projectId); @@ -39,4 +39,15 @@ public class CategoryService { return CategoryResponse.from(labelCategory); } + + public void deleteCategory(Integer memberId, Integer projectId, Integer categoryId) { + participantService.checkEditorUnauthorized(memberId, projectId); + LabelCategory category = getCategory(categoryId); + categoryRepository.delete(category); + } + + private LabelCategory getCategory(Integer categoryId) { + return categoryRepository.findById(categoryId).orElseThrow(() ->new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); + } + } diff --git a/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java b/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java index d0c32be..afa7f9a 100644 --- a/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java +++ b/backend/src/main/java/com/worlabel/global/exception/ErrorCode.java @@ -38,6 +38,7 @@ public enum ErrorCode { PROJECT_NOT_FOUND(HttpStatus.NOT_FOUND, 4000, "프로젝트를 찾을 수 없습니다"), PROJECT_IMAGE_MISMATCH(HttpStatus.BAD_REQUEST, 4001, "해당 프로젝트에는 존재하지 않는 이미지입니다."), PROJECT_CATEGORY_EXIST(HttpStatus.BAD_REQUEST,4002, "이미 존재하는 카테고리입니다."), + PROJECT_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, 4003, "해당 카테고리를 찾을 수 없습니다."), // Participant - 5000, PARTICIPANT_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 5000, "해당 프로젝트에 참여하고 있지않습니다."), @@ -55,8 +56,9 @@ public enum ErrorCode { AI_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 8000, "AI 서버 오류 입니다."), // Comment - 9000, - COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, 9000, "해당 댓글을 찾을 수 없습니다."); + COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, 9000, "해당 댓글을 찾을 수 없습니다."), + ; private final HttpStatus status; private final int code; private final String message; From bb5a303d7730c31554fd24757c6aebe03bf252af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 16:00:00 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java index 44495e2..503580c 100644 --- a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java @@ -28,14 +28,25 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 성공적으로 생성합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @PostMapping - public BaseResponse createFolder( + public CategoryResponse createFolder( @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @RequestBody final CategoryRequest categoryRequest) { - CategoryResponse response = categoryService.createCategory(memberId, projectId, categoryRequest); - return SuccessResponse.of(response); + return categoryService.createCategory(memberId, projectId, categoryRequest); } +// @Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다..") +// @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") +// @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) +// @GetMapping("/{category_id}") +// public CategoryResponse getCategory( +// @CurrentUser final Integer memberId, +// @PathVariable("project_id") final Integer projectId, +// @RequestBody final CategoryRequest categoryRequest) { +// return categoryService.get(memberId, projectId, categoryRequest); +// } + + @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) From fa7acc5cd5c8f837218617e8fcb9b357a53c9fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 17:17:23 +0900 Subject: [PATCH 4/7] =?UTF-8?q?Feat:=20=EB=A0=88=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EB=8B=A8=EC=9D=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 25 +++++++++---------- .../category/service/CategoryService.java | 9 +++++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java index 503580c..eed7222 100644 --- a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java @@ -3,8 +3,6 @@ package com.worlabel.domain.category.controller; import com.worlabel.domain.category.entity.dto.CategoryRequest; import com.worlabel.domain.category.entity.dto.CategoryResponse; import com.worlabel.domain.category.service.CategoryService; -import com.worlabel.domain.folder.entity.dto.FolderRequest; -import com.worlabel.domain.folder.entity.dto.FolderResponse; import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; @@ -35,21 +33,22 @@ public class LabelCategoryController { return categoryService.createCategory(memberId, projectId, categoryRequest); } -// @Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다..") -// @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") -// @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) -// @GetMapping("/{category_id}") -// public CategoryResponse getCategory( -// @CurrentUser final Integer memberId, -// @PathVariable("project_id") final Integer projectId, -// @RequestBody final CategoryRequest categoryRequest) { -// return categoryService.get(memberId, projectId, categoryRequest); -// } + @Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다..") + @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @GetMapping("/{category_id}") + public CategoryResponse getCategory( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId, + @PathVariable("category_id") final Integer categoryId + ) { + return categoryService.getCategoryById(memberId, projectId, categoryId); + } @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") - @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") @DeleteMapping("/{category_id}") public BaseResponse deleteFolder( @CurrentUser final Integer memberId, diff --git a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java index 480c2fd..f0a8f60 100644 --- a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java +++ b/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java @@ -40,13 +40,18 @@ public class CategoryService { return CategoryResponse.from(labelCategory); } - public void deleteCategory(Integer memberId, Integer projectId, Integer categoryId) { + public void deleteCategory(final int memberId, final int projectId, final int categoryId) { participantService.checkEditorUnauthorized(memberId, projectId); LabelCategory category = getCategory(categoryId); categoryRepository.delete(category); } - private LabelCategory getCategory(Integer categoryId) { + public CategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId){ + participantService.checkViewerUnauthorized(memberId,projectId); + return CategoryResponse.from(getCategory(categoryId)); + } + + private LabelCategory getCategory(final Integer categoryId) { return categoryRepository.findById(categoryId).orElseThrow(() ->new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); } From c451ea606b2ed5c5ceb3438557f2d28fad2a6357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 17:26:56 +0900 Subject: [PATCH 5/7] =?UTF-8?q?Feat:=20=EB=A0=88=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 27 ++++++++++---- ...Request.java => LabelCategoryRequest.java} | 2 +- ...sponse.java => LabelCategoryResponse.java} | 6 ++-- ...tory.java => LabelCategoryRepository.java} | 6 +++- ...Service.java => LabelCategoryService.java} | 35 +++++++++++-------- 5 files changed, 50 insertions(+), 26 deletions(-) rename backend/src/main/java/com/worlabel/domain/category/entity/dto/{CategoryRequest.java => LabelCategoryRequest.java} (92%) rename backend/src/main/java/com/worlabel/domain/category/entity/dto/{CategoryResponse.java => LabelCategoryResponse.java} (71%) rename backend/src/main/java/com/worlabel/domain/category/repository/{CategoryRepository.java => LabelCategoryRepository.java} (54%) rename backend/src/main/java/com/worlabel/domain/category/service/{CategoryService.java => LabelCategoryService.java} (51%) diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java index eed7222..9a599c8 100644 --- a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java @@ -1,8 +1,8 @@ package com.worlabel.domain.category.controller; -import com.worlabel.domain.category.entity.dto.CategoryRequest; -import com.worlabel.domain.category.entity.dto.CategoryResponse; -import com.worlabel.domain.category.service.CategoryService; +import com.worlabel.domain.category.entity.dto.LabelCategoryRequest; +import com.worlabel.domain.category.entity.dto.LabelCategoryResponse; +import com.worlabel.domain.category.service.LabelCategoryService; import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; @@ -14,22 +14,24 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "레이블 카테고리 관련 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/projects/{project_id}/categories") public class LabelCategoryController { - private final CategoryService categoryService; + private final LabelCategoryService categoryService; @Operation(summary = "레이블 카테고리 생성", description = "프로젝트에 카테고리를 생성합니다.") @SwaggerApiSuccess(description = "카테고리 성공적으로 생성합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @PostMapping - public CategoryResponse createFolder( + public LabelCategoryResponse createFolder( @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, - @RequestBody final CategoryRequest categoryRequest) { + @RequestBody final LabelCategoryRequest categoryRequest) { return categoryService.createCategory(memberId, projectId, categoryRequest); } @@ -37,13 +39,24 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @GetMapping("/{category_id}") - public CategoryResponse getCategory( + public LabelCategoryResponse getCategoryById( @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @PathVariable("category_id") final Integer categoryId ) { return categoryService.getCategoryById(memberId, projectId, categoryId); } + + @Operation(summary = "레이블 카테고리 리스트 조회", description = "레이블 카테고리 리스트를 조회합니다..") + @SwaggerApiSuccess(description = "카테고리 리스트를 성공적으로 조회합니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @GetMapping + public List getCategoryList( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId + ) { + return categoryService.getCategoryList(memberId, projectId); + } @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java b/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java similarity index 92% rename from backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java rename to backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java index 291f202..b0037d9 100644 --- a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryRequest.java +++ b/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java @@ -9,7 +9,7 @@ import lombok.NoArgsConstructor; @Getter @NoArgsConstructor @AllArgsConstructor -public class CategoryRequest { +public class LabelCategoryRequest { @Schema(description = "카테고리 이름", example = "Car") private String categoryName; diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java b/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java similarity index 71% rename from backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java rename to backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java index 53e3f4a..0b9869f 100644 --- a/backend/src/main/java/com/worlabel/domain/category/entity/dto/CategoryResponse.java +++ b/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java @@ -8,7 +8,7 @@ import lombok.Getter; @Getter @AllArgsConstructor @Schema(name = "카테고리 응답 DTO", description = "카테고리 조회 응답 DTO") -public class CategoryResponse { +public class LabelCategoryResponse { @Schema(description = "카테고리 ID", example = "1") private Integer id; @@ -16,7 +16,7 @@ public class CategoryResponse { @Schema(description = "카테고리 이름", example = "Car") private String name; - public static CategoryResponse from(LabelCategory labelCategory) { - return new CategoryResponse(labelCategory.getId(), labelCategory.getName()); + public static LabelCategoryResponse from(LabelCategory labelCategory) { + return new LabelCategoryResponse(labelCategory.getId(), labelCategory.getName()); } } diff --git a/backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java b/backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java similarity index 54% rename from backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java rename to backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java index c38ab39..d1bfe44 100644 --- a/backend/src/main/java/com/worlabel/domain/category/repository/CategoryRepository.java +++ b/backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java @@ -3,7 +3,11 @@ package com.worlabel.domain.category.repository; import com.worlabel.domain.category.entity.LabelCategory; import org.springframework.data.jpa.repository.JpaRepository; -public interface CategoryRepository extends JpaRepository { +import java.util.List; + +public interface LabelCategoryRepository extends JpaRepository { boolean existsByName(String name); + + List findAllByProjectId(Integer projectId); } diff --git a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java b/backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java similarity index 51% rename from backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java rename to backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java index f0a8f60..3fcbd12 100644 --- a/backend/src/main/java/com/worlabel/domain/category/service/CategoryService.java +++ b/backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java @@ -1,9 +1,9 @@ package com.worlabel.domain.category.service; import com.worlabel.domain.category.entity.LabelCategory; -import com.worlabel.domain.category.entity.dto.CategoryRequest; -import com.worlabel.domain.category.entity.dto.CategoryResponse; -import com.worlabel.domain.category.repository.CategoryRepository; +import com.worlabel.domain.category.entity.dto.LabelCategoryRequest; +import com.worlabel.domain.category.entity.dto.LabelCategoryResponse; +import com.worlabel.domain.category.repository.LabelCategoryRepository; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; import com.worlabel.domain.project.service.ProjectService; @@ -13,46 +13,53 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; +import java.util.List; @Service @Transactional @RequiredArgsConstructor -public class CategoryService { +public class LabelCategoryService { - private final CategoryRepository categoryRepository; + private final LabelCategoryRepository labelCategoryRepository; private final ParticipantService participantService; private final ProjectService projectService; - public CategoryResponse createCategory(final Integer memberId, final Integer projectId, final CategoryRequest categoryRequest) { + public LabelCategoryResponse createCategory(final Integer memberId, final Integer projectId, final LabelCategoryRequest categoryRequest) { participantService.checkEditorUnauthorized(memberId, projectId); // 이미 존재하는지 확인 있다면 예외 - if (categoryRepository.existsByName(categoryRequest.getCategoryName())) { + if (labelCategoryRepository.existsByName(categoryRequest.getCategoryName())) { throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); } Project project = projectService.getProject(projectId); LabelCategory labelCategory = LabelCategory.of(categoryRequest.getCategoryName(), project); - categoryRepository.save(labelCategory); + labelCategoryRepository.save(labelCategory); - return CategoryResponse.from(labelCategory); + return LabelCategoryResponse.from(labelCategory); } public void deleteCategory(final int memberId, final int projectId, final int categoryId) { participantService.checkEditorUnauthorized(memberId, projectId); LabelCategory category = getCategory(categoryId); - categoryRepository.delete(category); + labelCategoryRepository.delete(category); } - public CategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId){ + public LabelCategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId){ participantService.checkViewerUnauthorized(memberId,projectId); - return CategoryResponse.from(getCategory(categoryId)); + return LabelCategoryResponse.from(getCategory(categoryId)); + } + + + public List getCategoryList(final Integer memberId, final Integer projectId) { + participantService.checkViewerUnauthorized(memberId,projectId); + List labelCategoryList = labelCategoryRepository.findAllByProjectId(projectId); + return labelCategoryList.stream().map(LabelCategoryResponse::from).toList(); } private LabelCategory getCategory(final Integer categoryId) { - return categoryRepository.findById(categoryId).orElseThrow(() ->new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); + return labelCategoryRepository.findById(categoryId).orElseThrow(() ->new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); } } From a108096ebab3c1ff517560e1bde95880ea5ebc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 17:36:21 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 30 ++++++++++++++----- .../entity/LabelCategory.java | 2 +- .../entity/dto/LabelCategoryRequest.java | 2 +- .../entity/dto/LabelCategoryResponse.java | 4 +-- .../repository/LabelCategoryRepository.java | 8 ++--- .../service/LabelCategoryService.java | 26 +++++++++------- .../domain/project/entity/Project.java | 2 +- 7 files changed, 47 insertions(+), 27 deletions(-) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/controller/LabelCategoryController.java (73%) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/entity/LabelCategory.java (95%) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/entity/dto/LabelCategoryRequest.java (89%) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/entity/dto/LabelCategoryResponse.java (84%) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/repository/LabelCategoryRepository.java (55%) rename backend/src/main/java/com/worlabel/domain/{category => labelcategory}/service/LabelCategoryService.java (66%) diff --git a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java similarity index 73% rename from backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java index 9a599c8..b1eba79 100644 --- a/backend/src/main/java/com/worlabel/domain/category/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java @@ -1,8 +1,8 @@ -package com.worlabel.domain.category.controller; +package com.worlabel.domain.labelcategory.controller; -import com.worlabel.domain.category.entity.dto.LabelCategoryRequest; -import com.worlabel.domain.category.entity.dto.LabelCategoryResponse; -import com.worlabel.domain.category.service.LabelCategoryService; +import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryRequest; +import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse; +import com.worlabel.domain.labelcategory.service.LabelCategoryService; import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; @@ -12,6 +12,8 @@ import com.worlabel.global.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.data.repository.query.Param; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -35,7 +37,7 @@ public class LabelCategoryController { return categoryService.createCategory(memberId, projectId, categoryRequest); } - @Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다..") + @Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다.") @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @GetMapping("/{category_id}") @@ -47,6 +49,18 @@ public class LabelCategoryController { return categoryService.getCategoryById(memberId, projectId, categoryId); } + @Operation(summary = "레이블 카테고리 존재 여부 조회", description = "해당 프로젝트에 같은 레이블 카테고리 이름이 있는지 조회합니다.") + @SwaggerApiSuccess(description = "카테고리 존재 여부를 조회합니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @GetMapping("/exist") + public boolean existByCategoryName( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId, + @Param("categoryName") final String categoryName + ) { + return categoryService.existByCategoryName(memberId, projectId, categoryName); + } + @Operation(summary = "레이블 카테고리 리스트 조회", description = "레이블 카테고리 리스트를 조회합니다..") @SwaggerApiSuccess(description = "카테고리 리스트를 성공적으로 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @@ -57,17 +71,19 @@ public class LabelCategoryController { ) { return categoryService.getCategoryList(memberId, projectId); } + @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") @DeleteMapping("/{category_id}") - public BaseResponse deleteFolder( + public void deleteCategoryById( @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @PathVariable("category_id") final Integer categoryId) { categoryService.deleteCategory(memberId, projectId, categoryId); - return SuccessResponse.empty(); } + + } diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/LabelCategory.java similarity index 95% rename from backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/entity/LabelCategory.java index 7a0caf8..ec2cd67 100644 --- a/backend/src/main/java/com/worlabel/domain/category/entity/LabelCategory.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/LabelCategory.java @@ -1,4 +1,4 @@ -package com.worlabel.domain.category.entity; +package com.worlabel.domain.labelcategory.entity; import com.worlabel.domain.project.entity.Project; diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryRequest.java similarity index 89% rename from backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryRequest.java index b0037d9..851da52 100644 --- a/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryRequest.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryRequest.java @@ -1,4 +1,4 @@ -package com.worlabel.domain.category.entity.dto; +package com.worlabel.domain.labelcategory.entity.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; diff --git a/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryResponse.java similarity index 84% rename from backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryResponse.java index 0b9869f..ab5507b 100644 --- a/backend/src/main/java/com/worlabel/domain/category/entity/dto/LabelCategoryResponse.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/entity/dto/LabelCategoryResponse.java @@ -1,6 +1,6 @@ -package com.worlabel.domain.category.entity.dto; +package com.worlabel.domain.labelcategory.entity.dto; -import com.worlabel.domain.category.entity.LabelCategory; +import com.worlabel.domain.labelcategory.entity.LabelCategory; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java b/backend/src/main/java/com/worlabel/domain/labelcategory/repository/LabelCategoryRepository.java similarity index 55% rename from backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/repository/LabelCategoryRepository.java index d1bfe44..1d69d49 100644 --- a/backend/src/main/java/com/worlabel/domain/category/repository/LabelCategoryRepository.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/repository/LabelCategoryRepository.java @@ -1,13 +1,13 @@ -package com.worlabel.domain.category.repository; +package com.worlabel.domain.labelcategory.repository; -import com.worlabel.domain.category.entity.LabelCategory; +import com.worlabel.domain.labelcategory.entity.LabelCategory; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface LabelCategoryRepository extends JpaRepository { - boolean existsByName(String name); - List findAllByProjectId(Integer projectId); + + boolean existsByNameAndProjectId(String categoryName, Integer projectId); } diff --git a/backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java b/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java similarity index 66% rename from backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java rename to backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java index 3fcbd12..a4c836c 100644 --- a/backend/src/main/java/com/worlabel/domain/category/service/LabelCategoryService.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java @@ -1,9 +1,9 @@ -package com.worlabel.domain.category.service; +package com.worlabel.domain.labelcategory.service; -import com.worlabel.domain.category.entity.LabelCategory; -import com.worlabel.domain.category.entity.dto.LabelCategoryRequest; -import com.worlabel.domain.category.entity.dto.LabelCategoryResponse; -import com.worlabel.domain.category.repository.LabelCategoryRepository; +import com.worlabel.domain.labelcategory.entity.LabelCategory; +import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryRequest; +import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse; +import com.worlabel.domain.labelcategory.repository.LabelCategoryRepository; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; import com.worlabel.domain.project.service.ProjectService; @@ -28,7 +28,7 @@ public class LabelCategoryService { participantService.checkEditorUnauthorized(memberId, projectId); // 이미 존재하는지 확인 있다면 예외 - if (labelCategoryRepository.existsByName(categoryRequest.getCategoryName())) { + if (labelCategoryRepository.existsByNameAndProjectId(categoryRequest.getCategoryName(), projectId)) { throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); } @@ -40,26 +40,30 @@ public class LabelCategoryService { return LabelCategoryResponse.from(labelCategory); } - public void deleteCategory(final int memberId, final int projectId, final int categoryId) { + public void deleteCategory(final int memberId, final int projectId, final int categoryId) { participantService.checkEditorUnauthorized(memberId, projectId); LabelCategory category = getCategory(categoryId); labelCategoryRepository.delete(category); } - public LabelCategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId){ - participantService.checkViewerUnauthorized(memberId,projectId); + public LabelCategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId) { + participantService.checkViewerUnauthorized(memberId, projectId); return LabelCategoryResponse.from(getCategory(categoryId)); } + public boolean existByCategoryName(final int memberId, final int projectId, final String categoryName) { + participantService.checkViewerUnauthorized(memberId, projectId); + return labelCategoryRepository.existsByNameAndProjectId(categoryName, projectId); + } public List getCategoryList(final Integer memberId, final Integer projectId) { - participantService.checkViewerUnauthorized(memberId,projectId); + participantService.checkViewerUnauthorized(memberId, projectId); List labelCategoryList = labelCategoryRepository.findAllByProjectId(projectId); return labelCategoryList.stream().map(LabelCategoryResponse::from).toList(); } private LabelCategory getCategory(final Integer categoryId) { - return labelCategoryRepository.findById(categoryId).orElseThrow(() ->new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); + return labelCategoryRepository.findById(categoryId).orElseThrow(() -> new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); } } diff --git a/backend/src/main/java/com/worlabel/domain/project/entity/Project.java b/backend/src/main/java/com/worlabel/domain/project/entity/Project.java index 1739ca4..a7c315b 100644 --- a/backend/src/main/java/com/worlabel/domain/project/entity/Project.java +++ b/backend/src/main/java/com/worlabel/domain/project/entity/Project.java @@ -1,7 +1,7 @@ package com.worlabel.domain.project.entity; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.worlabel.domain.category.entity.LabelCategory; +import com.worlabel.domain.labelcategory.entity.LabelCategory; import com.worlabel.domain.workspace.entity.Workspace; import com.worlabel.global.common.BaseEntity; import jakarta.persistence.*; From cdc9d741b3ef590e15892f8cae08b90e933e09af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Fri, 13 Sep 2024 21:28:53 +0900 Subject: [PATCH 7/7] =?UTF-8?q?Chore:=20=EA=B3=B5=EB=B0=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B0=9C=ED=96=89=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LabelCategoryController.java | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java b/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java index b1eba79..17a12c5 100644 --- a/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/controller/LabelCategoryController.java @@ -7,13 +7,10 @@ import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; import com.worlabel.global.exception.ErrorCode; -import com.worlabel.global.response.BaseResponse; -import com.worlabel.global.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -30,10 +27,7 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 성공적으로 생성합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @PostMapping - public LabelCategoryResponse createFolder( - @CurrentUser final Integer memberId, - @PathVariable("project_id") final Integer projectId, - @RequestBody final LabelCategoryRequest categoryRequest) { + public LabelCategoryResponse createFolder(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @RequestBody final LabelCategoryRequest categoryRequest) { return categoryService.createCategory(memberId, projectId, categoryRequest); } @@ -41,11 +35,7 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @GetMapping("/{category_id}") - public LabelCategoryResponse getCategoryById( - @CurrentUser final Integer memberId, - @PathVariable("project_id") final Integer projectId, - @PathVariable("category_id") final Integer categoryId - ) { + public LabelCategoryResponse getCategoryById(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @PathVariable("category_id") final Integer categoryId) { return categoryService.getCategoryById(memberId, projectId, categoryId); } @@ -53,11 +43,7 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 존재 여부를 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @GetMapping("/exist") - public boolean existByCategoryName( - @CurrentUser final Integer memberId, - @PathVariable("project_id") final Integer projectId, - @Param("categoryName") final String categoryName - ) { + public boolean existByCategoryName(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @Param("categoryName") final String categoryName) { return categoryService.existByCategoryName(memberId, projectId, categoryName); } @@ -65,25 +51,16 @@ public class LabelCategoryController { @SwaggerApiSuccess(description = "카테고리 리스트를 성공적으로 조회합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @GetMapping - public List getCategoryList( - @CurrentUser final Integer memberId, - @PathVariable("project_id") final Integer projectId - ) { + public List getCategoryList(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId) { return categoryService.getCategoryList(memberId, projectId); } - @Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.") @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.") @DeleteMapping("/{category_id}") - public void deleteCategoryById( - @CurrentUser final Integer memberId, - @PathVariable("project_id") final Integer projectId, - @PathVariable("category_id") final Integer categoryId) { + public void deleteCategoryById(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, @PathVariable("category_id") final Integer categoryId) { categoryService.deleteCategory(memberId, projectId, categoryId); } - - }