From ac141072411c87dd4911c53785de11e959ba5a7f Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Wed, 20 Nov 2024 14:05:00 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=ED=87=B4=EC=B6=9C?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/controller/TeamController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 a39c4ba9..68a9d0c8 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -4,6 +4,7 @@ import static com.tiki.server.team.message.SuccessMessage.*; import java.security.Principal; +import java.util.List; import com.tiki.server.common.dto.BaseResponse; import com.tiki.server.team.dto.response.CategoriesGetResponse; @@ -56,6 +57,17 @@ public ResponseEntity> getCategories() { return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); } + @DeleteMapping("/{teamId}/members") + public ResponseEntity kickOutMemberFromTeam( + Principal principal, + @PathVariable long teamId, + @RequestParam List kickOutMemberIds + ){ + long memberId = Long.parseLong(principal.getName()); + teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberIds); + return ResponseEntity.noContent().build(); + } + @DeleteMapping("/{teamId}") public ResponseEntity deleteTeam( Principal principal, From c1fe080d0445ea4431e8f954e14bd27787a965f2 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Wed, 20 Nov 2024 14:05:40 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=ED=87=B4=EC=B6=9C?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/service/TeamService.java | 123 ++++++++++-------- 1 file changed, 66 insertions(+), 57 deletions(-) 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 89b75c59..e64458f2 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -4,6 +4,7 @@ import static com.tiki.server.team.message.ErrorCode.INVALID_AUTHORIZATION_DELETE; import java.util.List; +import java.util.Optional; import com.tiki.server.document.adapter.DocumentDeleter; import com.tiki.server.document.adapter.DocumentFinder; @@ -40,61 +41,69 @@ @Transactional(readOnly = true) public class TeamService { - private final TeamSaver teamSaver; - private final TeamFinder teamFinder; - private final TeamDeleter teamDeleter; - private final MemberFinder memberFinder; - private final DocumentFinder documentFinder; - private final DocumentDeleter documentDeleter; - private final TimeBlockDeleter timeBlockDeleter; - private final MemberTeamManagerFinder memberTeamManagerFinder; - private final MemberTeamManagerDeleter memberTeamManagerDeleter; - private final MemberTeamManagerSaver memberTeamManagerSaver; - - @Transactional - public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { - Member member = memberFinder.findById(memberId); - Team team = teamSaver.save(createTeam(request, member.getUniv())); - memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); - return TeamCreateResponse.from(team); - } - - public TeamsGetResponse getAllTeams(long memberId) { - Member member = memberFinder.findById(memberId); - University univ = member.getUniv(); - List team = teamFinder.findAllByUniv(univ); - return TeamsGetResponse.from(team); - } - - public CategoriesGetResponse getCategories() { - Category[] categories = Category.values(); - return CategoriesGetResponse.from(categories); - } - - @Transactional - public void deleteTeam(long memberId, long teamId) { - checkIsAdmin(memberId, teamId); - List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); - memberTeamManagerDeleter.deleteAll(memberTeamManagers); - List documents = documentFinder.findAllByTeamId(teamId); - documentDeleter.deleteAll(documents); - timeBlockDeleter.deleteAllByTeamId(teamId); - teamDeleter.deleteById(teamId); - } - - private Team createTeam(TeamCreateRequest request, University univ) { - return Team.of(request, univ); - } - - private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { - return MemberTeamManager.of(member, team, position); - } - - private void checkIsAdmin(long memberId, long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (!memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(INVALID_AUTHORIZATION_DELETE); - } - memberTeamManagerDeleter.delete(memberTeamManager); - } + private final TeamSaver teamSaver; + private final TeamFinder teamFinder; + private final TeamDeleter teamDeleter; + private final MemberFinder memberFinder; + private final DocumentFinder documentFinder; + private final DocumentDeleter documentDeleter; + private final TimeBlockDeleter timeBlockDeleter; + private final MemberTeamManagerFinder memberTeamManagerFinder; + private final MemberTeamManagerDeleter memberTeamManagerDeleter; + private final MemberTeamManagerSaver memberTeamManagerSaver; + + @Transactional + public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { + Member member = memberFinder.findById(memberId); + Team team = teamSaver.save(createTeam(request, member.getUniv())); + memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); + return TeamCreateResponse.from(team); + } + + public TeamsGetResponse getAllTeams(long memberId) { + Member member = memberFinder.findById(memberId); + University univ = member.getUniv(); + List team = teamFinder.findAllByUniv(univ); + return TeamsGetResponse.from(team); + } + + public CategoriesGetResponse getCategories() { + Category[] categories = Category.values(); + return CategoriesGetResponse.from(categories); + } + + @Transactional + public void deleteTeam(long memberId, long teamId) { + checkIsAdmin(memberId, teamId); + List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); + memberTeamManagerDeleter.deleteAll(memberTeamManagers); + List documents = documentFinder.findAllByTeamId(teamId); + documentDeleter.deleteAll(documents); + timeBlockDeleter.deleteAllByTeamId(teamId); + teamDeleter.deleteById(teamId); + } + + @Transactional + public void kickOutMemberFromTeam(final long memberId, final long teamId, final List kickOutMemberIds) { + checkIsAdmin(memberId, teamId); + kickOutMemberIds.stream() + .map(kickOutMemberId -> memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId)) + .flatMap(Optional::stream) + .forEach(memberTeamManagerDeleter::delete); + } + + private Team createTeam(TeamCreateRequest request, University univ) { + return Team.of(request, univ); + } + + private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { + return MemberTeamManager.of(member, team, position); + } + + private void checkIsAdmin(long memberId, long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + if (!memberTeamManager.getPosition().equals(ADMIN)) { + throw new TeamException(INVALID_AUTHORIZATION_DELETE); + } + } } From b9d60bca82db0b513300d29859fef0fdece1515d Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Wed, 20 Nov 2024 14:43:52 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/controller/TeamController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 68a9d0c8..412d7a81 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -68,6 +68,16 @@ public ResponseEntity kickOutMemberFromTeam( return ResponseEntity.noContent().build(); } + @DeleteMapping("/{teamId}/leave") + public ResponseEntity leaveTeam( + Principal principal, + @PathVariable long teamId + ){ + long memberId = Long.parseLong(principal.getName()); + teamService.leaveTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } + @DeleteMapping("/{teamId}") public ResponseEntity deleteTeam( Principal principal, From c813d85a3bd6d71780cf7f090ae1971118ed078a Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Wed, 20 Nov 2024 14:48:24 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/team/service/TeamService.java | 5 +++++ 1 file changed, 5 insertions(+) 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 e64458f2..91312e19 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -92,6 +92,11 @@ public void kickOutMemberFromTeam(final long memberId, final long teamId, final .forEach(memberTeamManagerDeleter::delete); } + public void leaveTeam(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerDeleter.delete(memberTeamManager); + } + private Team createTeam(TeamCreateRequest request, University univ) { return Team.of(request, univ); } From f34882a86703925d2e921f78b95b96f352ee0fcd Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 09:39:46 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20api=EB=8B=B9=201=EB=AA=85=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/team/controller/TeamController.java | 5 ++--- .../java/com/tiki/server/team/service/TeamService.java | 8 +++----- 2 files changed, 5 insertions(+), 8 deletions(-) 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 412d7a81..a5c65dd4 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -4,7 +4,6 @@ import static com.tiki.server.team.message.SuccessMessage.*; import java.security.Principal; -import java.util.List; import com.tiki.server.common.dto.BaseResponse; import com.tiki.server.team.dto.response.CategoriesGetResponse; @@ -61,10 +60,10 @@ public ResponseEntity> getCategories() { public ResponseEntity kickOutMemberFromTeam( Principal principal, @PathVariable long teamId, - @RequestParam List kickOutMemberIds + @RequestParam long kickOutMemberId ){ long memberId = Long.parseLong(principal.getName()); - teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberIds); + teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); return ResponseEntity.noContent().build(); } 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 91312e19..c748ce14 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -84,12 +84,10 @@ public void deleteTeam(long memberId, long teamId) { } @Transactional - public void kickOutMemberFromTeam(final long memberId, final long teamId, final List kickOutMemberIds) { + public void kickOutMemberFromTeam(final long memberId, final long teamId, final long kickOutMemberId) { checkIsAdmin(memberId, teamId); - kickOutMemberIds.stream() - .map(kickOutMemberId -> memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId)) - .flatMap(Optional::stream) - .forEach(memberTeamManagerDeleter::delete); + Optional memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId); + memberTeamManager.ifPresent(memberTeamManagerDeleter::delete); } public void leaveTeam(final long memberId, final long teamId) { From d6508e16dedcfc0eff6e570492ba45bd70645581 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:31:04 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[CHORE]=20=EB=A9=A4=EB=B2=84=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=20=EC=A0=84=EB=8B=AC=20=EB=B0=A9=EC=8B=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/team/controller/TeamController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a5c65dd4..61082de6 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -56,11 +56,11 @@ public ResponseEntity> getCategories() { return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); } - @DeleteMapping("/{teamId}/members") + @DeleteMapping("/{teamId}/members/{kickOutMemberId}") public ResponseEntity kickOutMemberFromTeam( Principal principal, @PathVariable long teamId, - @RequestParam long kickOutMemberId + @PathVariable long kickOutMemberId ){ long memberId = Long.parseLong(principal.getName()); teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); From 685ad5cf5189766180d8ed839dfe2be6390dca3c Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:31:42 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[CHORE]=20=EB=A9=A4=EB=B2=84=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/service/TeamService.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) 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 c748ce14..eaf6156e 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -2,6 +2,7 @@ import static com.tiki.server.common.entity.Position.ADMIN; import static com.tiki.server.team.message.ErrorCode.INVALID_AUTHORIZATION_DELETE; +import static com.tiki.server.team.message.ErrorCode.TOO_HIGH_AUTHORIZATION; import java.util.List; import java.util.Optional; @@ -11,6 +12,8 @@ import com.tiki.server.document.entity.Document; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerDeleter; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; +import com.tiki.server.note.adapter.NoteFinder; +import com.tiki.server.note.entity.Note; import com.tiki.server.team.adapter.TeamDeleter; import com.tiki.server.team.adapter.TeamFinder; import com.tiki.server.team.dto.response.CategoriesGetResponse; @@ -45,6 +48,7 @@ public class TeamService { private final TeamFinder teamFinder; private final TeamDeleter teamDeleter; private final MemberFinder memberFinder; + private final NoteFinder noteFinder; private final DocumentFinder documentFinder; private final DocumentDeleter documentDeleter; private final TimeBlockDeleter timeBlockDeleter; @@ -53,14 +57,14 @@ public class TeamService { private final MemberTeamManagerSaver memberTeamManagerSaver; @Transactional - public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { + public TeamCreateResponse createTeam(final long memberId, final TeamCreateRequest request) { Member member = memberFinder.findById(memberId); Team team = teamSaver.save(createTeam(request, member.getUniv())); memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); return TeamCreateResponse.from(team); } - public TeamsGetResponse getAllTeams(long memberId) { + public TeamsGetResponse getAllTeams(final long memberId) { Member member = memberFinder.findById(memberId); University univ = member.getUniv(); List team = teamFinder.findAllByUniv(univ); @@ -73,7 +77,7 @@ public CategoriesGetResponse getCategories() { } @Transactional - public void deleteTeam(long memberId, long teamId) { + public void deleteTeam(final long memberId, final long teamId) { checkIsAdmin(memberId, teamId); List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); memberTeamManagerDeleter.deleteAll(memberTeamManagers); @@ -87,26 +91,42 @@ public void deleteTeam(long memberId, long teamId) { public void kickOutMemberFromTeam(final long memberId, final long teamId, final long kickOutMemberId) { checkIsAdmin(memberId, teamId); Optional memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId); + deleteNoteDependency(memberId, teamId); memberTeamManager.ifPresent(memberTeamManagerDeleter::delete); } + @Transactional public void leaveTeam(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = checkIsNotAdmin(memberId, teamId); + deleteNoteDependency(memberId, teamId); memberTeamManagerDeleter.delete(memberTeamManager); } - private Team createTeam(TeamCreateRequest request, University univ) { + private void deleteNoteDependency(final long memberId, final long teamId) { + List notes = noteFinder.findAllByMemberIdAndTeamId(memberId, teamId); + notes.forEach(Note::deleteMemberDependency); + } + + private Team createTeam(final TeamCreateRequest request, final University univ) { return Team.of(request, univ); } - private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { + private MemberTeamManager createMemberTeamManager(final Member member, final Team team, final Position position) { return MemberTeamManager.of(member, team, position); } - private void checkIsAdmin(long memberId, long teamId) { + private void checkIsAdmin(final long memberId, final long teamId) { MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); if (!memberTeamManager.getPosition().equals(ADMIN)) { throw new TeamException(INVALID_AUTHORIZATION_DELETE); } } + + private MemberTeamManager checkIsNotAdmin(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + if (memberTeamManager.getPosition().equals(ADMIN)) { + throw new TeamException(TOO_HIGH_AUTHORIZATION); + } + return memberTeamManager; + } } From 618277afd02a9d1656ec76557be54e9b7177ed5e Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:32:15 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[FEAT]=20=EB=85=B8=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/note/adapter/NoteFinder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java index 97e2b44a..04e62f50 100644 --- a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java +++ b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java @@ -26,6 +26,10 @@ public List findByCreatedAtAfterOrderByModifiedAtAsc(final LocalDateTime c return noteRepository.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageRequest); } + public List findAllByMemberIdAndTeamId(final long memberId, final long teamId) { + return noteRepository.findAllByMemberIdAndTeamId(memberId, teamId); + } + public Note findById(final long noteId) { return noteRepository.findById(noteId) .orElseThrow(() -> new NoteException(INVALID_NOTE)); From e4e1702d9a8ab5ee744a07c7be0b2d2a55c74055 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:32:40 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[FEAT]=20=EB=85=B8=ED=8A=B8=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/note/entity/Note.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tiki/server/note/entity/Note.java b/src/main/java/com/tiki/server/note/entity/Note.java index 1ef479e9..a2decdbe 100644 --- a/src/main/java/com/tiki/server/note/entity/Note.java +++ b/src/main/java/com/tiki/server/note/entity/Note.java @@ -87,6 +87,10 @@ public void updateValue( this.noteType = noteType; } + public void deleteMemberDependency(){ + this.memberId = null; + } + private void checkAuthor(final long clientId) { if (this.memberId != clientId) { throw new NoteException(UPDATE_ONLY_AUTHOR); From d68d60a3a0a530673b2c9e16ee5399864af2886a Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:32:55 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[FEAT]=20=EB=85=B8=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/note/repository/NoteRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/tiki/server/note/repository/NoteRepository.java b/src/main/java/com/tiki/server/note/repository/NoteRepository.java index 46a7804e..2317f820 100644 --- a/src/main/java/com/tiki/server/note/repository/NoteRepository.java +++ b/src/main/java/com/tiki/server/note/repository/NoteRepository.java @@ -16,4 +16,6 @@ public interface NoteRepository extends JpaRepository { @Query("SELECT n FROM Note n WHERE n.createdAt > :createdAt ORDER BY n.createdAt ASC") List findByCreatedAtAfterOrderByModifiedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable); + + List findAllByMemberIdAndTeamId(long memberId, long TeamId); } From b5c27739ea43ce8511212dfbc61b05fcb2055c56 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:33:15 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[FEAT]=20=EA=B6=8C=ED=95=9C=EC=9D=B4=20?= =?UTF-8?q?=EC=96=B4=EB=93=9C=EB=AF=BC=EC=9D=BC=EC=8B=9C=20=ED=84=B0?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=EC=97=90=EB=9F=AC=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/team/message/ErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tiki/server/team/message/ErrorCode.java b/src/main/java/com/tiki/server/team/message/ErrorCode.java index 2f90e6b3..993c42bf 100644 --- a/src/main/java/com/tiki/server/team/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/team/message/ErrorCode.java @@ -13,7 +13,8 @@ public enum ErrorCode { /* 403 FORBIDDEN : 권한 없음 */ - INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "팀 삭제에 대한 권한이 없습니다."), + INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "권한이 없습니다."), + TOO_HIGH_AUTHORIZATION(FORBIDDEN, "어드민은 진행할 수 없습니다."), /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ INVALID_TEAM(NOT_FOUND, "유효하지 않은 단체입니다."); From 961a6340c17f611b315cfa0deb02825e10d59e1d Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 18:41:02 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[FEAT]=20=EA=B6=8C=ED=95=9C=EC=9D=B4=20?= =?UTF-8?q?=EC=96=B4=EB=93=9C=EB=AF=BC=EC=9D=BC=EC=8B=9C=20=ED=84=B0?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=EC=97=90=EB=9F=AC=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/team/message/ErrorCode.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tiki/server/team/message/ErrorCode.java b/src/main/java/com/tiki/server/team/message/ErrorCode.java index 993c42bf..3f871892 100644 --- a/src/main/java/com/tiki/server/team/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/team/message/ErrorCode.java @@ -1,20 +1,21 @@ package com.tiki.server.team.message; -import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NOT_FOUND; - import org.springframework.http.HttpStatus; import lombok.AllArgsConstructor; import lombok.Getter; +import static org.springframework.http.HttpStatus.*; + @Getter @AllArgsConstructor public enum ErrorCode { + /* 400 BAD_REQUEST : 잘못된 요청 */ + TOO_HIGH_AUTHORIZATION(BAD_REQUEST, "어드민은 진행할 수 없습니다."), + /* 403 FORBIDDEN : 권한 없음 */ INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "권한이 없습니다."), - TOO_HIGH_AUTHORIZATION(FORBIDDEN, "어드민은 진행할 수 없습니다."), /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ INVALID_TEAM(NOT_FOUND, "유효하지 않은 단체입니다."); From 1faed9b1f0e66f77958406ddb2a60fab2e2cc6e3 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 21:15:00 +0900 Subject: [PATCH 13/16] =?UTF-8?q?[CHORE]=20=EC=BB=A8=EB=B2=A4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/controller/TeamController.java | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) 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 61082de6..0b6c8aeb 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -26,64 +26,64 @@ @RequestMapping("api/v1/teams") public class TeamController implements TeamControllerDocs { - private final TeamService teamService; + private final TeamService teamService; - @Override - @PostMapping - public ResponseEntity> createTeam( - Principal principal, - @RequestBody TeamCreateRequest request - ) { - long memberId = Long.parseLong(principal.getName()); - TeamCreateResponse response = teamService.createTeam(memberId, request); - return ResponseEntity.created( - UriGenerator.getUri("/api/v1/teams/" + response.teamId()) - ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); - } + @Override + @PostMapping + public ResponseEntity> createTeam( + final Principal principal, + @RequestBody final TeamCreateRequest request + ) { + long memberId = Long.parseLong(principal.getName()); + TeamCreateResponse response = teamService.createTeam(memberId, request); + return ResponseEntity.created( + UriGenerator.getUri("/api/v1/teams/" + response.teamId()) + ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); + } - @Override - @GetMapping - public ResponseEntity> getAllTeams(Principal principal) { - long memberId = Long.parseLong(principal.getName()); - TeamsGetResponse response = teamService.getAllTeams(memberId); - return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); - } + @Override + @GetMapping + public ResponseEntity> getAllTeams(final Principal principal) { + long memberId = Long.parseLong(principal.getName()); + TeamsGetResponse response = teamService.getAllTeams(memberId); + return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); + } - @Override - @GetMapping("/category") - public ResponseEntity> getCategories() { - CategoriesGetResponse response = teamService.getCategories(); - return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); - } + @Override + @GetMapping("/category") + public ResponseEntity> getCategories() { + CategoriesGetResponse response = teamService.getCategories(); + return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); + } - @DeleteMapping("/{teamId}/members/{kickOutMemberId}") - public ResponseEntity kickOutMemberFromTeam( - Principal principal, - @PathVariable long teamId, - @PathVariable long kickOutMemberId - ){ - long memberId = Long.parseLong(principal.getName()); - teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); - return ResponseEntity.noContent().build(); - } + @DeleteMapping("/{teamId}/members/{kickOutMemberId}") + public ResponseEntity kickOutMemberFromTeam( + final Principal principal, + @PathVariable final long teamId, + @PathVariable final long kickOutMemberId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); + return ResponseEntity.noContent().build(); + } - @DeleteMapping("/{teamId}/leave") - public ResponseEntity leaveTeam( - Principal principal, - @PathVariable long teamId - ){ - long memberId = Long.parseLong(principal.getName()); - teamService.leaveTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } + @DeleteMapping("/{teamId}/leave") + public ResponseEntity leaveTeam( + final Principal principal, + @PathVariable final long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.leaveTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } - @DeleteMapping("/{teamId}") - public ResponseEntity deleteTeam( - Principal principal, - @PathVariable long teamId - ) { - long memberId = Long.parseLong(principal.getName()); - teamService.deleteTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } + @DeleteMapping("/{teamId}") + public ResponseEntity deleteTeam( + final Principal principal, + @PathVariable final long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.deleteTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } } From ee2b6a2077524312d713e6f625410d0689871ae8 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 21:22:06 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[CHORE]=20=ED=83=88=ED=87=B4,=20=ED=87=B4?= =?UTF-8?q?=EC=B6=9C=20=EB=A1=9C=EC=A7=81=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberTeamManagerController.java | 42 +++++++++++++++ .../service/MemberTeamManagerService.java | 53 +++++++++++++++++++ .../team/controller/TeamController.java | 21 -------- .../tiki/server/team/service/TeamService.java | 33 ------------ 4 files changed, 95 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java new file mode 100644 index 00000000..9f99291d --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java @@ -0,0 +1,42 @@ +package com.tiki.server.memberteammanager.controller; + +import com.tiki.server.common.dto.BaseResponse; +import com.tiki.server.memberteammanager.service.MemberTeamManagerService; +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + + +@RestController +@AllArgsConstructor +@RequestMapping("api/v1/teams") +public class MemberTeamManagerController { + + private final MemberTeamManagerService memberTeamManagerService; + + @DeleteMapping("/{teamId}/members/{kickOutMemberId}") + public ResponseEntity kickOutMemberFromTeam( + final Principal principal, + @PathVariable final long teamId, + @PathVariable final long kickOutMemberId + ) { + long memberId = Long.parseLong(principal.getName()); + memberTeamManagerService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); + return ResponseEntity.noContent().build(); + } + + @DeleteMapping("/{teamId}/leave") + public ResponseEntity leaveTeam( + final Principal principal, + @PathVariable final long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + memberTeamManagerService.leaveTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } +} 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 dde6e437..879f2fde 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -1,12 +1,65 @@ package com.tiki.server.memberteammanager.service; +import com.tiki.server.memberteammanager.adapter.MemberTeamManagerDeleter; +import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; +import com.tiki.server.memberteammanager.adapter.MemberTeamManagerSaver; +import com.tiki.server.memberteammanager.entity.MemberTeamManager; +import com.tiki.server.note.adapter.NoteFinder; +import com.tiki.server.note.entity.Note; +import com.tiki.server.team.exception.TeamException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; +import java.util.List; + +import static com.tiki.server.common.entity.Position.ADMIN; +import static com.tiki.server.team.message.ErrorCode.INVALID_AUTHORIZATION_DELETE; +import static com.tiki.server.team.message.ErrorCode.TOO_HIGH_AUTHORIZATION; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) public class MemberTeamManagerService { + + private final NoteFinder noteFinder; + private final MemberTeamManagerFinder memberTeamManagerFinder; + private final MemberTeamManagerDeleter memberTeamManagerDeleter; + private final MemberTeamManagerSaver memberTeamManagerSaver; + + @Transactional + public void kickOutMemberFromTeam(final long memberId, final long teamId, final long kickOutMemberId) { + checkIsAdmin(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(kickOutMemberId, teamId); + deleteNoteDependency(kickOutMemberId, teamId); + memberTeamManagerDeleter.delete(memberTeamManager); + } + + @Transactional + public void leaveTeam(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = checkIsNotAdmin(memberId, teamId); + deleteNoteDependency(memberId, teamId); + memberTeamManagerDeleter.delete(memberTeamManager); + } + + private void checkIsAdmin(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + if (!memberTeamManager.getPosition().equals(ADMIN)) { + throw new TeamException(INVALID_AUTHORIZATION_DELETE); + } + } + + private MemberTeamManager checkIsNotAdmin(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + if (memberTeamManager.getPosition().equals(ADMIN)) { + throw new TeamException(TOO_HIGH_AUTHORIZATION); + } + return memberTeamManager; + } + + private void deleteNoteDependency(final long memberId, final long teamId) { + List notes = noteFinder.findAllByMemberIdAndTeamId(memberId, teamId); + notes.forEach(Note::deleteMemberDependency); + } } 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 0b6c8aeb..e656fc19 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -56,27 +56,6 @@ public ResponseEntity> getCategories() { return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); } - @DeleteMapping("/{teamId}/members/{kickOutMemberId}") - public ResponseEntity kickOutMemberFromTeam( - final Principal principal, - @PathVariable final long teamId, - @PathVariable final long kickOutMemberId - ) { - long memberId = Long.parseLong(principal.getName()); - teamService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); - return ResponseEntity.noContent().build(); - } - - @DeleteMapping("/{teamId}/leave") - public ResponseEntity leaveTeam( - final Principal principal, - @PathVariable final long teamId - ) { - long memberId = Long.parseLong(principal.getName()); - teamService.leaveTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } - @DeleteMapping("/{teamId}") public ResponseEntity deleteTeam( final Principal principal, 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 eaf6156e..60ca1149 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -2,18 +2,14 @@ import static com.tiki.server.common.entity.Position.ADMIN; import static com.tiki.server.team.message.ErrorCode.INVALID_AUTHORIZATION_DELETE; -import static com.tiki.server.team.message.ErrorCode.TOO_HIGH_AUTHORIZATION; import java.util.List; -import java.util.Optional; import com.tiki.server.document.adapter.DocumentDeleter; import com.tiki.server.document.adapter.DocumentFinder; import com.tiki.server.document.entity.Document; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerDeleter; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; -import com.tiki.server.note.adapter.NoteFinder; -import com.tiki.server.note.entity.Note; import com.tiki.server.team.adapter.TeamDeleter; import com.tiki.server.team.adapter.TeamFinder; import com.tiki.server.team.dto.response.CategoriesGetResponse; @@ -48,7 +44,6 @@ public class TeamService { private final TeamFinder teamFinder; private final TeamDeleter teamDeleter; private final MemberFinder memberFinder; - private final NoteFinder noteFinder; private final DocumentFinder documentFinder; private final DocumentDeleter documentDeleter; private final TimeBlockDeleter timeBlockDeleter; @@ -87,26 +82,6 @@ public void deleteTeam(final long memberId, final long teamId) { teamDeleter.deleteById(teamId); } - @Transactional - public void kickOutMemberFromTeam(final long memberId, final long teamId, final long kickOutMemberId) { - checkIsAdmin(memberId, teamId); - Optional memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId); - deleteNoteDependency(memberId, teamId); - memberTeamManager.ifPresent(memberTeamManagerDeleter::delete); - } - - @Transactional - public void leaveTeam(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = checkIsNotAdmin(memberId, teamId); - deleteNoteDependency(memberId, teamId); - memberTeamManagerDeleter.delete(memberTeamManager); - } - - private void deleteNoteDependency(final long memberId, final long teamId) { - List notes = noteFinder.findAllByMemberIdAndTeamId(memberId, teamId); - notes.forEach(Note::deleteMemberDependency); - } - private Team createTeam(final TeamCreateRequest request, final University univ) { return Team.of(request, univ); } @@ -121,12 +96,4 @@ private void checkIsAdmin(final long memberId, final long teamId) { throw new TeamException(INVALID_AUTHORIZATION_DELETE); } } - - private MemberTeamManager checkIsNotAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(TOO_HIGH_AUTHORIZATION); - } - return memberTeamManager; - } } From 8ae008a96cc5943329d71be47814a786b272476f Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 21:22:21 +0900 Subject: [PATCH 15/16] =?UTF-8?q?[CHORE]=20pr=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/note/adapter/NoteFinder.java | 16 ++++++++++++---- .../server/note/repository/NoteRepository.java | 8 ++++---- .../tiki/server/note/service/NoteService.java | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java index 04e62f50..fdcf4748 100644 --- a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java +++ b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java @@ -18,12 +18,20 @@ public class NoteFinder { private final NoteRepository noteRepository; - public List findByCreatedAtBeforeOrderByModifiedAtDesc(final LocalDateTime createdAt, final PageRequest pageRequest) { - return noteRepository.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageRequest); + public List findByCreatedAtBeforeOrderByModifiedAtDesc( + final LocalDateTime createdAt, + final PageRequest pageRequest, + final long teamId + ) { + return noteRepository.findByTeamIdAndCreatedAtBeforeOrderByCreatedDesc(createdAt, pageRequest, teamId); } - public List findByCreatedAtAfterOrderByModifiedAtAsc(final LocalDateTime createdAt, final PageRequest pageRequest) { - return noteRepository.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageRequest); + public List findByCreatedAtAfterOrderByModifiedAtAsc( + final LocalDateTime createdAt, + final PageRequest pageRequest, + final long teamId + ) { + return noteRepository.findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(createdAt, pageRequest, teamId); } public List findAllByMemberIdAndTeamId(final long memberId, final long teamId) { diff --git a/src/main/java/com/tiki/server/note/repository/NoteRepository.java b/src/main/java/com/tiki/server/note/repository/NoteRepository.java index 2317f820..043fa4be 100644 --- a/src/main/java/com/tiki/server/note/repository/NoteRepository.java +++ b/src/main/java/com/tiki/server/note/repository/NoteRepository.java @@ -11,11 +11,11 @@ public interface NoteRepository extends JpaRepository { - @Query("SELECT n FROM Note n WHERE n.createdAt < :createdAt ORDER BY n.createdAt DESC") - List findByCreatedAtBeforeOrderByModifiedAtDesc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable); + @Query("SELECT n FROM Note n WHERE n.teamId = :teamId AND n.createdAt < :createdAt ORDER BY n.createdAt DESC") + List findByTeamIdAndCreatedAtBeforeOrderByCreatedDesc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable, long teamId); - @Query("SELECT n FROM Note n WHERE n.createdAt > :createdAt ORDER BY n.createdAt ASC") - List findByCreatedAtAfterOrderByModifiedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable); + @Query("SELECT n FROM Note n WHERE n.teamId = :teamId AND n.createdAt > :createdAt ORDER BY n.createdAt ASC") + List findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable, long teamId); List findAllByMemberIdAndTeamId(long memberId, long TeamId); } 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 3f5e3e89..3888b4ef 100644 --- a/src/main/java/com/tiki/server/note/service/NoteService.java +++ b/src/main/java/com/tiki/server/note/service/NoteService.java @@ -139,7 +139,7 @@ public NoteListGetServiceResponse getNote( ) { memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE); - List noteList = getNotes(createdAt, sortOrder, pageable); + List noteList = getNotes(createdAt, sortOrder, pageable, teamId); List noteGetResponses = noteList.stream() .map(note -> NoteGetResponse.of(note, getMemberName(note.getMemberId(), teamId))) .toList(); @@ -191,11 +191,11 @@ private void updateNoteTimeBlockManager(final List timeBlockIds, final lon noteTimeBlockManagerDeleter.deleteByNoteIdAndTimeBlockId(noteId, idsToRemove); } - private List getNotes(final LocalDateTime createdAt, final SortOrder sortOrder, final PageRequest pageable) { + private List getNotes(final LocalDateTime createdAt, final SortOrder sortOrder, final PageRequest pageable, final long teamId) { if (sortOrder == SortOrder.DESC) { - return noteFinder.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageable); + return noteFinder.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageable, teamId); } - return noteFinder.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageable); + return noteFinder.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageable, teamId); } private List getTimeBlocksMappedByNote(final long noteId) { From d1755914a742b8acce7792e5c1cf8562d00d68d4 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Fri, 29 Nov 2024 22:40:17 +0900 Subject: [PATCH 16/16] =?UTF-8?q?[CHORE]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document/service/DocumentService.java | 16 ++++++++-------- .../server/folder/service/FolderService.java | 6 +++--- .../adapter/MemberTeamManagerFinder.java | 7 +------ .../service/MemberTeamManagerService.java | 6 +++--- .../tiki/server/note/service/NoteService.java | 18 ++++++++---------- .../tiki/server/team/service/TeamService.java | 2 +- .../timeblock/service/TimeBlockService.java | 8 ++++---- 7 files changed, 28 insertions(+), 35 deletions(-) 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/service/MemberTeamManagerService.java b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java index 879f2fde..d5ddee36 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -31,7 +31,7 @@ public class MemberTeamManagerService { @Transactional public void kickOutMemberFromTeam(final long memberId, final long teamId, final long kickOutMemberId) { checkIsAdmin(memberId, teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(kickOutMemberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(kickOutMemberId, teamId); deleteNoteDependency(kickOutMemberId, teamId); memberTeamManagerDeleter.delete(memberTeamManager); } @@ -44,14 +44,14 @@ public void leaveTeam(final long memberId, final long teamId) { } private void checkIsAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); if (!memberTeamManager.getPosition().equals(ADMIN)) { throw new TeamException(INVALID_AUTHORIZATION_DELETE); } } private MemberTeamManager checkIsNotAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); if (memberTeamManager.getPosition().equals(ADMIN)) { throw new TeamException(TOO_HIGH_AUTHORIZATION); } 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/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 60ca1149..e3248815 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -91,7 +91,7 @@ private MemberTeamManager createMemberTeamManager(final Member member, final Tea } private void checkIsAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); if (!memberTeamManager.getPosition().equals(ADMIN)) { throw new TeamException(INVALID_AUTHORIZATION_DELETE); } 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());