Feat: 레이블 카테고리 단일 조회

This commit is contained in:
김용수 2024-09-13 17:17:23 +09:00
parent bb5a303d77
commit fa7acc5cd5
2 changed files with 19 additions and 15 deletions

View File

@ -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<Void> deleteFolder(
@CurrentUser final Integer memberId,

View File

@ -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));
}