Feat: 카테고리 존재 여부 API
This commit is contained in:
parent
c451ea606b
commit
a108096eba
@ -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.labelcategory.entity.dto.LabelCategoryRequest;
|
||||||
import com.worlabel.domain.category.entity.dto.LabelCategoryResponse;
|
import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse;
|
||||||
import com.worlabel.domain.category.service.LabelCategoryService;
|
import com.worlabel.domain.labelcategory.service.LabelCategoryService;
|
||||||
import com.worlabel.global.annotation.CurrentUser;
|
import com.worlabel.global.annotation.CurrentUser;
|
||||||
import com.worlabel.global.config.swagger.SwaggerApiError;
|
import com.worlabel.global.config.swagger.SwaggerApiError;
|
||||||
import com.worlabel.global.config.swagger.SwaggerApiSuccess;
|
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.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,7 +37,7 @@ public class LabelCategoryController {
|
|||||||
return categoryService.createCategory(memberId, projectId, categoryRequest);
|
return categoryService.createCategory(memberId, projectId, categoryRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다..")
|
@Operation(summary = "레이블 카테고리 단일 조회", description = "레이블 카테고리를 조회합니다.")
|
||||||
@SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.")
|
@SwaggerApiSuccess(description = "카테고리 성공적으로 조회합니다.")
|
||||||
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
||||||
@GetMapping("/{category_id}")
|
@GetMapping("/{category_id}")
|
||||||
@ -47,6 +49,18 @@ public class LabelCategoryController {
|
|||||||
return categoryService.getCategoryById(memberId, projectId, categoryId);
|
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 = "레이블 카테고리 리스트를 조회합니다..")
|
@Operation(summary = "레이블 카테고리 리스트 조회", description = "레이블 카테고리 리스트를 조회합니다..")
|
||||||
@SwaggerApiSuccess(description = "카테고리 리스트를 성공적으로 조회합니다.")
|
@SwaggerApiSuccess(description = "카테고리 리스트를 성공적으로 조회합니다.")
|
||||||
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
||||||
@ -59,15 +73,17 @@ public class LabelCategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.")
|
@Operation(summary = "카테고리 삭제", description = "카테고리를 삭제합니다.")
|
||||||
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
|
||||||
@SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.")
|
@SwaggerApiSuccess(description = "카테고리를 성공적으로 삭제합니다.")
|
||||||
@DeleteMapping("/{category_id}")
|
@DeleteMapping("/{category_id}")
|
||||||
public BaseResponse<Void> deleteFolder(
|
public void deleteCategoryById(
|
||||||
@CurrentUser final Integer memberId,
|
@CurrentUser final Integer memberId,
|
||||||
@PathVariable("project_id") final Integer projectId,
|
@PathVariable("project_id") final Integer projectId,
|
||||||
@PathVariable("category_id") final Integer categoryId) {
|
@PathVariable("category_id") final Integer categoryId) {
|
||||||
categoryService.deleteCategory(memberId, projectId, categoryId);
|
categoryService.deleteCategory(memberId, projectId, categoryId);
|
||||||
return SuccessResponse.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.worlabel.domain.category.entity;
|
package com.worlabel.domain.labelcategory.entity;
|
||||||
|
|
||||||
|
|
||||||
import com.worlabel.domain.project.entity.Project;
|
import com.worlabel.domain.project.entity.Project;
|
@ -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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
@ -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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -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 org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface LabelCategoryRepository extends JpaRepository<LabelCategory, Integer> {
|
public interface LabelCategoryRepository extends JpaRepository<LabelCategory, Integer> {
|
||||||
|
|
||||||
boolean existsByName(String name);
|
|
||||||
|
|
||||||
List<LabelCategory> findAllByProjectId(Integer projectId);
|
List<LabelCategory> findAllByProjectId(Integer projectId);
|
||||||
|
|
||||||
|
boolean existsByNameAndProjectId(String categoryName, Integer projectId);
|
||||||
}
|
}
|
@ -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.labelcategory.entity.LabelCategory;
|
||||||
import com.worlabel.domain.category.entity.dto.LabelCategoryRequest;
|
import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryRequest;
|
||||||
import com.worlabel.domain.category.entity.dto.LabelCategoryResponse;
|
import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse;
|
||||||
import com.worlabel.domain.category.repository.LabelCategoryRepository;
|
import com.worlabel.domain.labelcategory.repository.LabelCategoryRepository;
|
||||||
import com.worlabel.domain.participant.service.ParticipantService;
|
import com.worlabel.domain.participant.service.ParticipantService;
|
||||||
import com.worlabel.domain.project.entity.Project;
|
import com.worlabel.domain.project.entity.Project;
|
||||||
import com.worlabel.domain.project.service.ProjectService;
|
import com.worlabel.domain.project.service.ProjectService;
|
||||||
@ -28,7 +28,7 @@ public class LabelCategoryService {
|
|||||||
participantService.checkEditorUnauthorized(memberId, projectId);
|
participantService.checkEditorUnauthorized(memberId, projectId);
|
||||||
|
|
||||||
// 이미 존재하는지 확인 있다면 예외
|
// 이미 존재하는지 확인 있다면 예외
|
||||||
if (labelCategoryRepository.existsByName(categoryRequest.getCategoryName())) {
|
if (labelCategoryRepository.existsByNameAndProjectId(categoryRequest.getCategoryName(), projectId)) {
|
||||||
throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST);
|
throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,20 +46,24 @@ public class LabelCategoryService {
|
|||||||
labelCategoryRepository.delete(category);
|
labelCategoryRepository.delete(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelCategoryResponse 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);
|
participantService.checkViewerUnauthorized(memberId, projectId);
|
||||||
return LabelCategoryResponse.from(getCategory(categoryId));
|
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<LabelCategoryResponse> getCategoryList(final Integer memberId, final Integer projectId) {
|
public List<LabelCategoryResponse> getCategoryList(final Integer memberId, final Integer projectId) {
|
||||||
participantService.checkViewerUnauthorized(memberId,projectId);
|
participantService.checkViewerUnauthorized(memberId, projectId);
|
||||||
List<LabelCategory> labelCategoryList = labelCategoryRepository.findAllByProjectId(projectId);
|
List<LabelCategory> labelCategoryList = labelCategoryRepository.findAllByProjectId(projectId);
|
||||||
return labelCategoryList.stream().map(LabelCategoryResponse::from).toList();
|
return labelCategoryList.stream().map(LabelCategoryResponse::from).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private LabelCategory getCategory(final Integer categoryId) {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.worlabel.domain.project.entity;
|
package com.worlabel.domain.project.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
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.domain.workspace.entity.Workspace;
|
||||||
import com.worlabel.global.common.BaseEntity;
|
import com.worlabel.global.common.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
Loading…
Reference in New Issue
Block a user