diff --git a/src/main/java/com/tiki/server/document/service/DocumentService.java b/src/main/java/com/tiki/server/document/service/DocumentService.java index 2acadc30..355b48fd 100644 --- a/src/main/java/com/tiki/server/document/service/DocumentService.java +++ b/src/main/java/com/tiki/server/document/service/DocumentService.java @@ -39,7 +39,7 @@ public class DocumentService { private final DeletedDocumentAdapter deletedDocumentAdapter; public DocumentsGetResponse getAllDocuments(final long memberId, final long teamId, final String type) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); return getAllDocumentsByType(teamId, accessiblePosition); @@ -47,7 +47,7 @@ public DocumentsGetResponse getAllDocuments(final long memberId, final long team @Transactional public void deleteDocument(final long memberId, final long teamId, final long documentId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Document document = documentFinder.findByIdWithTimeBlock(documentId); memberTeamManager.checkMemberAccessible(document.getTimeBlock().getAccessiblePosition()); documentDeleter.delete(document); @@ -56,21 +56,21 @@ public void deleteDocument(final long memberId, final long teamId, final long do @Transactional public void createDocuments(final long memberId, final long teamId, final Long folderId, final DocumentsCreateRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); validateFolder(folderId, teamId); validateFileName(folderId, teamId, request); saveDocuments(teamId, folderId, request); } public DocumentsGetResponse get(final long memberId, final long teamId, final Long folderId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List documents = documentFinder.findByTeamIdAndFolderId(teamId, folderId); return DocumentsGetResponse.from(documents); } @Transactional public void delete(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List documents = documentFinder.findAllByIdAndTeamId(documentIds, teamId); deletedDocumentAdapter.save(documents); documentDeleter.deleteAll(documents); @@ -78,21 +78,21 @@ public void delete(final long memberId, final long teamId, final List docu @Transactional public void deleteTrash(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId); deletedDocumentAdapter.deleteAll(deletedDocuments); } @Transactional public void restore(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId); documentSaver.restore(deletedDocuments); deletedDocumentAdapter.deleteAll(deletedDocuments); } public DeletedDocumentsGetResponse getTrash(final long memberId, final long teamId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(teamId); return DeletedDocumentsGetResponse.from(deletedDocuments); } diff --git a/src/main/java/com/tiki/server/folder/service/FolderService.java b/src/main/java/com/tiki/server/folder/service/FolderService.java index 2be875a0..5dfb46f6 100644 --- a/src/main/java/com/tiki/server/folder/service/FolderService.java +++ b/src/main/java/com/tiki/server/folder/service/FolderService.java @@ -39,7 +39,7 @@ public class FolderService { public FoldersGetResponse get(final long memberId, final long teamId, final Long folderId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Folder folder = getFolder(teamId, folderId); String path = getChildFolderPath(folder); List folders = folderFinder.findByTeamIdAndPath(teamId, path); @@ -49,7 +49,7 @@ public FoldersGetResponse get(final long memberId, final long teamId, @Transactional public FolderCreateResponse create(final long memberId, final long teamId, final Long folderId, final FolderCreateRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Folder parentFolder = getFolder(teamId, folderId); String path = getChildFolderPath(parentFolder); validateFolderName(teamId, path, request); @@ -59,7 +59,7 @@ public FolderCreateResponse create(final long memberId, final long teamId, @Transactional public void delete(final long memberId, final long teamId, final List folderIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List folders = folderFinder.findAllById(folderIds, teamId); deleteFolders(folders); } diff --git a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java index 84ff2bb4..38b726fa 100644 --- a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java +++ b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import java.util.List; -import java.util.Optional; @RepositoryAdapter @RequiredArgsConstructor @@ -18,15 +17,11 @@ public class MemberTeamManagerFinder { private final MemberTeamManagerRepository memberTeamManagerRepository; - public MemberTeamManager findByMemberIdAndTeamIdOrElseThrow(long memberId, long teamId) { + public MemberTeamManager findByMemberIdAndTeamId(long memberId, long teamId) { return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId) .orElseThrow(() -> new MemberTeamManagerException(INVALID_MEMBER_TEAM_MANAGER)); } - public Optional findByMemberIdAndTeamId(final long memberId, final long teamId) { - return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId); - } - public List findBelongTeamByMemberId(long memberId) { return memberTeamManagerRepository.findAllBelongTeamByMemberId(memberId).stream().toList(); } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java index 7e35ea2e..04d38414 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -1,5 +1,6 @@ package com.tiki.server.memberteammanager.controller; +import com.tiki.server.common.dto.BaseResponse; import com.tiki.server.common.dto.SuccessResponse; import com.tiki.server.memberteammanager.controller.dto.request.UpdateTeamMemberNameRequest; import com.tiki.server.memberteammanager.service.MemberTeamManagerService; @@ -23,7 +24,7 @@ public class MemberTeamController { @GetMapping("/teams/{teamId}/members/position") public ResponseEntity> getMemberTeamPosition( - Principal principal, + final Principal principal, @PathVariable final long teamId ) { long memberId = Long.parseLong(principal.getName()); @@ -32,13 +33,13 @@ public ResponseEntity> getMemberT } @PatchMapping("/teams/{teamId}/members/name") - public ResponseEntity> updateTeamMemberName( - Principal principal, + public ResponseEntity updateTeamMemberName( + final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamMemberNameRequest request ) { long memberId = Long.parseLong(principal.getName()); memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName()); - return ResponseEntity.ok().body(success(UPDATE_NAME.getMessage(), null)); + return ResponseEntity.ok(success(UPDATE_NAME.getMessage())); } } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java index 57c8144f..9b6fc655 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.memberteammanager.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamMemberNameRequest( - String newName + @NotNull String newName ) { } diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index 5d19a540..c6e29230 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -65,15 +65,15 @@ public void checkMemberAccessible(Position accesiblePosition) { } } - public void setName(final String name){ + public void updateName(final String name){ this.name = name; } - public void setPositionToExecutive(){ + public void updatePositionToExecutive(){ this.position = Position.EXECUTIVE; } - public void setPositionToAdmin(){ + public void updatePositionToAdmin(){ this.position = Position.ADMIN; } } diff --git a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java index bf503ed1..5ea3a791 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -16,13 +16,13 @@ public class MemberTeamManagerService { private final MemberTeamManagerFinder memberTeamManagerFinder; public MemberTeamPositionGetResponse getPosition(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); return MemberTeamPositionGetResponse.from(memberTeamManager.getPosition()); } @Transactional public void updateTeamMemberName(final long memberId, final long teamId, final String name) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - memberTeamManager.setName(name); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + memberTeamManager.updateName(name); } } diff --git a/src/main/java/com/tiki/server/note/service/NoteService.java b/src/main/java/com/tiki/server/note/service/NoteService.java index 3888b4ef..a9be7efc 100644 --- a/src/main/java/com/tiki/server/note/service/NoteService.java +++ b/src/main/java/com/tiki/server/note/service/NoteService.java @@ -6,7 +6,6 @@ import com.tiki.server.document.entity.Document; import com.tiki.server.member.adapter.MemberFinder; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; -import com.tiki.server.memberteammanager.entity.MemberTeamManager; import com.tiki.server.note.adapter.NoteDeleter; import com.tiki.server.note.adapter.NoteFinder; import com.tiki.server.note.adapter.NoteSaver; @@ -32,7 +31,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import static com.tiki.server.common.Constants.INIT_NUM; import static com.tiki.server.note.constants.NoteConstants.PAGE_SIZE; @@ -57,7 +55,7 @@ public class NoteService { @Transactional public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteFree(request.contents()); Note note = createNote(NoteBase.of(request), encryptedContents, NoteType.FREE); createNoteTimeBlockManagers(request.timeBlockIds(), note.getId()); @@ -67,7 +65,7 @@ public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceReque @Transactional public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServiceRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteTemplate( request.answerWhatActivity(), request.answerHowToPrepare(), @@ -83,7 +81,7 @@ public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServ @Transactional public void updateNoteFree(final NoteFreeUpdateServiceRequest request) { Note note = noteFinder.findById(request.noteId()); - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteFree(request.contents()); note.updateValue( request.memberId(), @@ -102,7 +100,7 @@ public void updateNoteFree(final NoteFreeUpdateServiceRequest request) { @Transactional public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) { Note note = noteFinder.findById(request.noteId()); - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteTemplate( request.answerWhatActivity(), request.answerHowToPrepare(), @@ -125,7 +123,7 @@ public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) { @Transactional public void deleteNotes(final List noteIds, final long teamId, final long memberId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); noteDocumentManagerDeleter.deleteByNoteIds(noteIds); noteTimeBlockManagerDeleter.noteTimeBlockManagerDeleteByIds(noteIds); noteDeleter.deleteNoteByIds(noteIds); @@ -137,7 +135,7 @@ public NoteListGetServiceResponse getNote( final LocalDateTime createdAt, final SortOrder sortOrder ) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE); List noteList = getNotes(createdAt, sortOrder, pageable, teamId); List noteGetResponses = noteList.stream() @@ -147,7 +145,7 @@ public NoteListGetServiceResponse getNote( } public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long memberId, final long noteId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Note note = noteFinder.findById(noteId); List documentList = getDocumentListMappedByNote(noteId); List timeBlockList = getTimeBlocksMappedByNote(noteId); @@ -159,7 +157,7 @@ public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long private String getMemberName(final Long noteMemberId, final long teamId) { return Optional.ofNullable(noteMemberId) - .map(id -> memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(id, teamId).getName()) + .map(id -> memberTeamManagerFinder.findByMemberIdAndTeamId(id, teamId).getName()) .orElse("알 수 없음"); } diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index 90da066b..22a31e1e 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -69,35 +69,35 @@ public ResponseEntity deleteTeam( } @PatchMapping("/{teamId}/name") - public ResponseEntity> updateTeamName( + public ResponseEntity updateTeamName( final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamNameRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateTeamName(memberId, teamId, request.newTeamName()); - return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_NAME.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_NAME.getMessage())); } @PatchMapping("/{teamId}/icon") - public ResponseEntity> updateIconImage( + public ResponseEntity updateIconImage( final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamIconRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateIconImage(memberId, teamId, request.iconImageUrl()); - return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_ICON.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_ICON.getMessage())); } @PatchMapping("/{teamId}/member/{targetId}/admin") - public ResponseEntity> alterAdmin( + public ResponseEntity alterAdmin( final Principal principal, @PathVariable final long teamId, @PathVariable final long targetId ) { long memberId = Long.parseLong(principal.getName()); teamService.alterAdmin(memberId, teamId, targetId); - return ResponseEntity.ok().body(success(SUCCESS_ALTER_AUTHORITY.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_ALTER_AUTHORITY.getMessage())); } } diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java index 5dc819de..4a0e039a 100644 --- a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.team.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamIconRequest( - String iconImageUrl + @NotNull String iconImageUrl ) { } diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java index 98fe995f..278810df 100644 --- a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.team.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamNameRequest( - String newTeamName + @NotNull String newTeamName ) { } diff --git a/src/main/java/com/tiki/server/team/entity/Team.java b/src/main/java/com/tiki/server/team/entity/Team.java index de9e8bca..aff50a76 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -26,39 +26,43 @@ @NoArgsConstructor(access = PROTECTED) public class Team extends BaseTime { - @Id - @GeneratedValue(strategy = IDENTITY) - @Column(name = "team_id") - private Long id; + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "team_id") + private Long id; - private String name; + private String name; - private String overview; + private String overview; - @Enumerated(value = STRING) - private Category category; + @Enumerated(value = STRING) + private Category category; - @Enumerated(value = STRING) - private University univ; + @Enumerated(value = STRING) + private University univ; - private String imageUrl; + private String imageUrl; - private String iconImageUrl; + private String iconImageUrl; - public static Team of(TeamCreateRequest request, University univ) { - return Team.builder() - .name(request.name()) - .category(request.category()) - .univ(univ) - .iconImageUrl(request.iconImageUrl()) - .build(); - } + public static Team of(TeamCreateRequest request, University univ) { + return Team.builder() + .name(request.name()) + .category(request.category()) + .univ(univ) + .iconImageUrl(request.iconImageUrl()) + .build(); + } - public void setName(final String name){ - this.name = name; - } + public void updateName(final String name) { + this.name = name; + } - public void setIconImageUrl(final String url){ - this.iconImageUrl = url; - } + public void setIconImageUrl(final String url) { + this.iconImageUrl = url; + } + + public boolean isDefaultImage() { + return this.getIconImageUrl().isBlank(); + } } diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 24429fe6..2f9724c7 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -88,7 +88,7 @@ public void deleteTeam(final long memberId, final long teamId) { public void updateTeamName(final long memberId, final long teamId, final String newTeamName) { checkIsAdmin(memberId, teamId); Team team = teamFinder.findById(teamId); - team.setName(newTeamName); + team.updateName(newTeamName); } @Transactional @@ -102,9 +102,9 @@ public void updateIconImage(final long memberId, final long teamId, final String @Transactional public void alterAdmin(final long memberId, final long teamId, final long targetId) { MemberTeamManager oldAdmin = checkIsAdmin(memberId, teamId); - MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(targetId, teamId); - oldAdmin.setPositionToExecutive(); - newAdmin.setPositionToAdmin(); + MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamId(targetId, teamId); + oldAdmin.updatePositionToExecutive(); + newAdmin.updatePositionToAdmin(); } private Team createTeam(final TeamCreateRequest request, final University univ) { @@ -112,7 +112,7 @@ private Team createTeam(final TeamCreateRequest request, final University univ) } private void deleteIconUrl(final Team team) { - if (!team.getIconImageUrl().isBlank()) { + if (!team.isDefaultImage()) { s3Handler.deleteFile(team.getIconImageUrl()); } } @@ -122,10 +122,8 @@ private MemberTeamManager createMemberTeamManager(final Member member, final Tea } private MemberTeamManager checkIsAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (!memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(INVALID_AUTHORIZATION_DELETE); - } - return memberTeamManager; + MemberTeamManager accessMember = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + accessMember.checkMemberAccessible(ADMIN); + return accessMember; } } diff --git a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java index cf2262f7..66169dd6 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -54,7 +54,7 @@ public TimeBlockCreateResponse createTimeBlock( TimeBlockCreateRequest request ) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); TimeBlock timeBlock = saveTimeBlock(team, accessiblePosition, request); @@ -64,7 +64,7 @@ public TimeBlockCreateResponse createTimeBlock( public TimelineGetResponse getTimeline(long memberId, long teamId, String type, String date) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); List timeBlocks = timeBlockFinder.findByTeamAndAccessiblePositionAndDate( @@ -73,7 +73,7 @@ public TimelineGetResponse getTimeline(long memberId, long teamId, String type, } public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); List documents = documentFinder.findAllByTimeBlockId(timeBlockId); @@ -83,7 +83,7 @@ public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, @Transactional public void deleteTimeBlock(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); documentDeleter.deleteAllByTimeBlockId(timeBlock.getId());