diff --git a/backend/src/main/java/com/worlabel/domain/folder/service/FolderService.java b/backend/src/main/java/com/worlabel/domain/folder/service/FolderService.java index d7f0703..ab55f2a 100644 --- a/backend/src/main/java/com/worlabel/domain/folder/service/FolderService.java +++ b/backend/src/main/java/com/worlabel/domain/folder/service/FolderService.java @@ -4,9 +4,11 @@ import com.worlabel.domain.folder.entity.Folder; import com.worlabel.domain.folder.repository.FolderRepository; import com.worlabel.domain.folder.entity.dto.FolderRequest; import com.worlabel.domain.folder.entity.dto.FolderResponse; +import com.worlabel.domain.participant.entity.PrivilegeType; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; import com.worlabel.domain.project.repository.ProjectRepository; +import com.worlabel.global.annotation.CheckPrivilege; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; import lombok.RequiredArgsConstructor; @@ -20,14 +22,12 @@ public class FolderService { private final FolderRepository folderRepository; private final ProjectRepository projectRepository; - private final ParticipantService participantService; /** * 폴더 생성 */ + @CheckPrivilege(PrivilegeType.EDITOR) public FolderResponse createFolder(final Integer memberId, final Integer projectId, final FolderRequest folderRequest) { - participantService.checkEditorUnauthorized(memberId, projectId); - Project project = getProject(projectId); Folder parent = null; @@ -45,9 +45,8 @@ public class FolderService { * 폴더 조회 */ @Transactional(readOnly = true) + @CheckPrivilege(PrivilegeType.VIEWER) public FolderResponse getFolderById(final Integer memberId, final Integer projectId, final Integer folderId) { - participantService.checkViewerUnauthorized(memberId, projectId); - // 최상위 폴더 if (folderId == 0) { return FolderResponse.from(folderRepository.findAllByProjectIdAndParentIsNull(projectId)); @@ -59,9 +58,8 @@ public class FolderService { /** * 폴더 수정 */ + @CheckPrivilege(PrivilegeType.EDITOR) public FolderResponse updateFolder(final Integer memberId, final Integer projectId, final Integer folderId, final FolderRequest updatedFolderRequest) { - participantService.checkEditorUnauthorized(memberId, projectId); - Folder folder = getFolder(folderId, projectId); Folder parentFolder = folderRepository.findById(updatedFolderRequest.getParentId()) @@ -75,8 +73,8 @@ public class FolderService { /** * 폴더 삭제 */ + @CheckPrivilege(PrivilegeType.EDITOR) public void deleteFolder(final Integer memberId, final Integer projectId, final Integer folderId) { - participantService.checkEditorUnauthorized(memberId, projectId); Folder folder = getFolder(folderId, projectId); folderRepository.delete(folder); } @@ -84,9 +82,8 @@ public class FolderService { /** * 리뷰 목록만 조회 */ + @CheckPrivilege(PrivilegeType.VIEWER) public FolderResponse getFolderByIdWithNeedReview(final Integer memberId, final Integer projectId, final Integer folderId) { - participantService.checkViewerUnauthorized(memberId, projectId); - // 최상위 폴더 if (folderId == 0) { return FolderResponse.from(folderRepository.findAllByProjectIdAndParentIsNull(projectId)); diff --git a/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java b/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java index a4c836c..4d5c7f2 100644 --- a/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java +++ b/backend/src/main/java/com/worlabel/domain/labelcategory/service/LabelCategoryService.java @@ -4,9 +4,11 @@ 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.entity.PrivilegeType; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; import com.worlabel.domain.project.service.ProjectService; +import com.worlabel.global.annotation.CheckPrivilege; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; import lombok.RequiredArgsConstructor; @@ -21,12 +23,10 @@ import java.util.List; public class LabelCategoryService { private final LabelCategoryRepository labelCategoryRepository; - private final ParticipantService participantService; private final ProjectService projectService; + @CheckPrivilege(PrivilegeType.EDITOR) public LabelCategoryResponse createCategory(final Integer memberId, final Integer projectId, final LabelCategoryRequest categoryRequest) { - participantService.checkEditorUnauthorized(memberId, projectId); - // 이미 존재하는지 확인 있다면 예외 if (labelCategoryRepository.existsByNameAndProjectId(categoryRequest.getCategoryName(), projectId)) { throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST); @@ -40,24 +40,24 @@ public class LabelCategoryService { return LabelCategoryResponse.from(labelCategory); } + @CheckPrivilege(PrivilegeType.EDITOR) public void deleteCategory(final int memberId, final int projectId, final int categoryId) { - participantService.checkEditorUnauthorized(memberId, projectId); LabelCategory category = getCategory(categoryId); labelCategoryRepository.delete(category); } + @CheckPrivilege(PrivilegeType.VIEWER) public LabelCategoryResponse getCategoryById(final int memberId, final int projectId, final int categoryId) { - participantService.checkViewerUnauthorized(memberId, projectId); return LabelCategoryResponse.from(getCategory(categoryId)); } + @CheckPrivilege(PrivilegeType.VIEWER) public boolean existByCategoryName(final int memberId, final int projectId, final String categoryName) { - participantService.checkViewerUnauthorized(memberId, projectId); return labelCategoryRepository.existsByNameAndProjectId(categoryName, projectId); } + @CheckPrivilege(PrivilegeType.VIEWER) 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(); } @@ -65,5 +65,4 @@ public class LabelCategoryService { private LabelCategory getCategory(final Integer categoryId) { return labelCategoryRepository.findById(categoryId).orElseThrow(() -> new CustomException(ErrorCode.PROJECT_CATEGORY_NOT_FOUND)); } - }