Refactor: participant 확인 -> 어노테이션으로 분리
This commit is contained in:
parent
6833d2b85d
commit
8a0f38040b
@ -4,9 +4,11 @@ import com.worlabel.domain.folder.entity.Folder;
|
|||||||
import com.worlabel.domain.folder.repository.FolderRepository;
|
import com.worlabel.domain.folder.repository.FolderRepository;
|
||||||
import com.worlabel.domain.folder.entity.dto.FolderRequest;
|
import com.worlabel.domain.folder.entity.dto.FolderRequest;
|
||||||
import com.worlabel.domain.folder.entity.dto.FolderResponse;
|
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.participant.service.ParticipantService;
|
||||||
import com.worlabel.domain.project.entity.Project;
|
import com.worlabel.domain.project.entity.Project;
|
||||||
import com.worlabel.domain.project.repository.ProjectRepository;
|
import com.worlabel.domain.project.repository.ProjectRepository;
|
||||||
|
import com.worlabel.global.annotation.CheckPrivilege;
|
||||||
import com.worlabel.global.exception.CustomException;
|
import com.worlabel.global.exception.CustomException;
|
||||||
import com.worlabel.global.exception.ErrorCode;
|
import com.worlabel.global.exception.ErrorCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -20,14 +22,12 @@ public class FolderService {
|
|||||||
|
|
||||||
private final FolderRepository folderRepository;
|
private final FolderRepository folderRepository;
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
private final ParticipantService participantService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 폴더 생성
|
* 폴더 생성
|
||||||
*/
|
*/
|
||||||
|
@CheckPrivilege(PrivilegeType.EDITOR)
|
||||||
public FolderResponse createFolder(final Integer memberId, final Integer projectId, final FolderRequest folderRequest) {
|
public FolderResponse createFolder(final Integer memberId, final Integer projectId, final FolderRequest folderRequest) {
|
||||||
participantService.checkEditorUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
Project project = getProject(projectId);
|
Project project = getProject(projectId);
|
||||||
|
|
||||||
Folder parent = null;
|
Folder parent = null;
|
||||||
@ -45,9 +45,8 @@ public class FolderService {
|
|||||||
* 폴더 조회
|
* 폴더 조회
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
public FolderResponse getFolderById(final Integer memberId, final Integer projectId, final Integer folderId) {
|
public FolderResponse getFolderById(final Integer memberId, final Integer projectId, final Integer folderId) {
|
||||||
participantService.checkViewerUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
// 최상위 폴더
|
// 최상위 폴더
|
||||||
if (folderId == 0) {
|
if (folderId == 0) {
|
||||||
return FolderResponse.from(folderRepository.findAllByProjectIdAndParentIsNull(projectId));
|
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) {
|
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 folder = getFolder(folderId, projectId);
|
||||||
|
|
||||||
Folder parentFolder = folderRepository.findById(updatedFolderRequest.getParentId())
|
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) {
|
public void deleteFolder(final Integer memberId, final Integer projectId, final Integer folderId) {
|
||||||
participantService.checkEditorUnauthorized(memberId, projectId);
|
|
||||||
Folder folder = getFolder(folderId, projectId);
|
Folder folder = getFolder(folderId, projectId);
|
||||||
folderRepository.delete(folder);
|
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) {
|
public FolderResponse getFolderByIdWithNeedReview(final Integer memberId, final Integer projectId, final Integer folderId) {
|
||||||
participantService.checkViewerUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
// 최상위 폴더
|
// 최상위 폴더
|
||||||
if (folderId == 0) {
|
if (folderId == 0) {
|
||||||
return FolderResponse.from(folderRepository.findAllByProjectIdAndParentIsNull(projectId));
|
return FolderResponse.from(folderRepository.findAllByProjectIdAndParentIsNull(projectId));
|
||||||
|
@ -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.LabelCategoryRequest;
|
||||||
import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse;
|
import com.worlabel.domain.labelcategory.entity.dto.LabelCategoryResponse;
|
||||||
import com.worlabel.domain.labelcategory.repository.LabelCategoryRepository;
|
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.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;
|
||||||
|
import com.worlabel.global.annotation.CheckPrivilege;
|
||||||
import com.worlabel.global.exception.CustomException;
|
import com.worlabel.global.exception.CustomException;
|
||||||
import com.worlabel.global.exception.ErrorCode;
|
import com.worlabel.global.exception.ErrorCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -21,12 +23,10 @@ import java.util.List;
|
|||||||
public class LabelCategoryService {
|
public class LabelCategoryService {
|
||||||
|
|
||||||
private final LabelCategoryRepository labelCategoryRepository;
|
private final LabelCategoryRepository labelCategoryRepository;
|
||||||
private final ParticipantService participantService;
|
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.EDITOR)
|
||||||
public LabelCategoryResponse createCategory(final Integer memberId, final Integer projectId, final LabelCategoryRequest categoryRequest) {
|
public LabelCategoryResponse createCategory(final Integer memberId, final Integer projectId, final LabelCategoryRequest categoryRequest) {
|
||||||
participantService.checkEditorUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
// 이미 존재하는지 확인 있다면 예외
|
// 이미 존재하는지 확인 있다면 예외
|
||||||
if (labelCategoryRepository.existsByNameAndProjectId(categoryRequest.getCategoryName(), projectId)) {
|
if (labelCategoryRepository.existsByNameAndProjectId(categoryRequest.getCategoryName(), projectId)) {
|
||||||
throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST);
|
throw new CustomException(ErrorCode.PROJECT_CATEGORY_EXIST);
|
||||||
@ -40,24 +40,24 @@ public class LabelCategoryService {
|
|||||||
return LabelCategoryResponse.from(labelCategory);
|
return LabelCategoryResponse.from(labelCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.EDITOR)
|
||||||
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);
|
LabelCategory category = getCategory(categoryId);
|
||||||
labelCategoryRepository.delete(category);
|
labelCategoryRepository.delete(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
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);
|
|
||||||
return LabelCategoryResponse.from(getCategory(categoryId));
|
return LabelCategoryResponse.from(getCategory(categoryId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
public boolean existByCategoryName(final int memberId, final int projectId, final String categoryName) {
|
public boolean existByCategoryName(final int memberId, final int projectId, final String categoryName) {
|
||||||
participantService.checkViewerUnauthorized(memberId, projectId);
|
|
||||||
return labelCategoryRepository.existsByNameAndProjectId(categoryName, projectId);
|
return labelCategoryRepository.existsByNameAndProjectId(categoryName, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
public List<LabelCategoryResponse> getCategoryList(final Integer memberId, final Integer projectId) {
|
public List<LabelCategoryResponse> getCategoryList(final Integer memberId, final Integer 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();
|
||||||
}
|
}
|
||||||
@ -65,5 +65,4 @@ public class LabelCategoryService {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user