From a9c9b61e8b79e6e063094dd0f5bd14235a2b5e99 Mon Sep 17 00:00:00 2001 From: soohyun Date: Thu, 18 Jan 2024 02:21:45 +0900 Subject: [PATCH] =?UTF-8?q?[#139]=20refactor:=20deleteCategory=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/app/toaster/controller/CategoryController.java | 4 +++- .../app/toaster/service/category/CategoryService.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/linkmind/src/main/java/com/app/toaster/controller/CategoryController.java b/linkmind/src/main/java/com/app/toaster/controller/CategoryController.java index 6067a5a..92d0194 100644 --- a/linkmind/src/main/java/com/app/toaster/controller/CategoryController.java +++ b/linkmind/src/main/java/com/app/toaster/controller/CategoryController.java @@ -11,11 +11,13 @@ import com.app.toaster.service.category.CategoryService; import com.app.toaster.service.search.SearchService; import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.List; @RestController @@ -41,7 +43,7 @@ public ApiResponse createCateory( @ResponseStatus(HttpStatus.OK) public ApiResponse deleteCategory( @UserId Long userId, - @RequestBody DeleteCategoryDto deleteCategoryDto + @NotNull @RequestParam(value = "deleteCategoryDto") ArrayList deleteCategoryDto ){ categoryService.deleteCategory(deleteCategoryDto); return ApiResponse.success(Success.DELETE_CATEGORY_SUCCESS); diff --git a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java index 1376441..cd217c5 100644 --- a/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java +++ b/linkmind/src/main/java/com/app/toaster/service/category/CategoryService.java @@ -12,6 +12,7 @@ import com.app.toaster.domain.Toast; import com.app.toaster.domain.User; import com.app.toaster.exception.Error; +import com.app.toaster.exception.model.BadRequestException; import com.app.toaster.exception.model.CustomException; import com.app.toaster.exception.model.NotFoundException; import com.app.toaster.infrastructure.CategoryRepository; @@ -63,11 +64,14 @@ public void createCategory(final Long userId, final CreateCategoryDto createCate } @Transactional - public void deleteCategory(final DeleteCategoryDto deleteCategoryDto){ + public void deleteCategory(final ArrayList deleteCategoryDto){ + if(deleteCategoryDto.isEmpty()){ + throw new BadRequestException(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage()); + } - toastRepository.updateCategoryIdsToNull(deleteCategoryDto.deleteCategoryList()); + toastRepository.updateCategoryIdsToNull(deleteCategoryDto); - for (Long categoryId : deleteCategoryDto.deleteCategoryList()) { + for (Long categoryId : deleteCategoryDto) { Category category = categoryRepository.findById(categoryId) .orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_CATEGORY_EXCEPTION, Error.NOT_FOUND_CATEGORY_EXCEPTION.getMessage()));