From 1017f82fab0d07405fedb12749a4b20a5524701f Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:02:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EB=9D=BC=EC=9A=B4=EC=A7=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9C=A0=EC=A0=80=20=EC=95=84=EC=9D=B4=EB=94=94?= =?UTF-8?q?=EB=A1=9C=20=EB=9D=BC=EC=9A=B4=EC=A7=80=20=EA=B3=B5=EC=9C=A0?= =?UTF-8?q?=EC=9E=90=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20Optional=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../daobe/lounge/domain/repository/LoungeSharerRepository.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/daobe/lounge/domain/repository/LoungeSharerRepository.java b/src/main/java/com/example/daobe/lounge/domain/repository/LoungeSharerRepository.java index 00a4ed14..73843e30 100644 --- a/src/main/java/com/example/daobe/lounge/domain/repository/LoungeSharerRepository.java +++ b/src/main/java/com/example/daobe/lounge/domain/repository/LoungeSharerRepository.java @@ -2,6 +2,7 @@ import com.example.daobe.lounge.domain.LoungeSharer; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -42,5 +43,5 @@ SELECT COUNT(ls) FROM LoungeSharer ls void deleteByUserIdAndLoungeId(Long userId, Long loungeId); - LoungeSharer findByUserIdAndLoungeId(Long userId, Long loungeId); + Optional findByUserIdAndLoungeId(Long userId, Long loungeId); } From a4020439b369c35421612b9a2ea6e4177b9e302a Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:02:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=B5=9C=EB=8C=80=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=EC=9D=98=20=EB=9D=BC=EC=9A=B4=EC=A7=80=EC=97=90=20?= =?UTF-8?q?=EC=86=8C=EC=86=8D=EB=90=98=EC=96=B4=EB=8F=84=20=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20=EC=88=98=EB=9D=BD=EB=90=98=EB=8A=94=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=ED=95=B4=EA=B2=B0=20#261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lounge/application/LoungeFacadeService.java | 2 +- .../lounge/application/LoungeSharerService.java | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/daobe/lounge/application/LoungeFacadeService.java b/src/main/java/com/example/daobe/lounge/application/LoungeFacadeService.java index c07c55a6..bccc0dee 100644 --- a/src/main/java/com/example/daobe/lounge/application/LoungeFacadeService.java +++ b/src/main/java/com/example/daobe/lounge/application/LoungeFacadeService.java @@ -66,7 +66,7 @@ public void inviteUser(LoungeInviteDto request, Long inviterId) { public void updateInvitedUserStatus(Long userId, Long loungeId) { User invitedUser = userService.getUserById(userId); Lounge findLounge = loungeService.getLoungeById(loungeId); - loungeSharerService.updateInvitedUserStatus(invitedUser, findLounge); + loungeSharerService.updateInvitedUserStatus(invitedUser.getId(), findLounge.getId()); } // 라운지 내 유저 검색 diff --git a/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java b/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java index 07ca83b6..202fa452 100644 --- a/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java +++ b/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java @@ -30,7 +30,6 @@ public class LoungeSharerService { private final LoungeSharerRepository loungeSharerRepository; public void createAndSaveLoungeSharer(User user, Lounge lounge) { - // 라운지 최대 개수를 초과하는지 검증 if (isOverMaximumCountLounge(user.getId())) { throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION); } @@ -54,12 +53,18 @@ public void inviteUser(User user, Lounge lounge, Long inviterId) { } // FIXME: - public void updateInvitedUserStatus(User invitedUser, Lounge lounge) { - LoungeSharer findSharer = loungeSharerRepository.findByUserIdAndLoungeId(invitedUser.getId(), lounge.getId()); - if (!findSharer.isActive()) { - findSharer.updateStatusActive(); - loungeSharerRepository.save(findSharer); + public void updateInvitedUserStatus(Long invitedUserId, Long loungeId) { + LoungeSharer loungeSharer = loungeSharerRepository.findByUserIdAndLoungeId(invitedUserId, loungeId) + .orElseThrow(() -> new LoungeException(INVALID_LOUNGE_SHARER_EXCEPTION)); + if (loungeSharer.isActive()) { + throw new LoungeException(ALREADY_EXISTS_LOUNGE_USER_EXCEPTION); } + + if (isOverMaximumCountLounge(invitedUserId)) { + throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION); + } + loungeSharer.updateStatusActive(); + loungeSharerRepository.save(loungeSharer); } public List searchLoungeSharer(Long userId, String nickname, Lounge lounge) {