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] =?UTF-8?q?Feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=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.*;