From e02196a3276c7e7986ef7ec53ccae41dc0f7dded Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:31:02 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B4=EC=A7=80=EC=97=90=20=EC=B4=88=EB=8C=80=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=B4=88=EB=8C=80=EC=8B=9C=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EB=8A=94=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80=20#261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/daobe/lounge/exception/LoungeExceptionType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java b/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java index ff648b9d..18629769 100644 --- a/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java +++ b/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java @@ -9,7 +9,8 @@ public enum LoungeExceptionType implements BaseExceptionType { NOT_ACTIVE_LOUNGE_EXCEPTION("활성 상태가 아닌 라운지입니다.", HttpStatus.NOT_FOUND), INVALID_LOUNGE_OWNER_EXCEPTION("유효하지 않은 라운지 주인입니다.", HttpStatus.FORBIDDEN), INVALID_LOUNGE_SHARER_EXCEPTION("유효하지 않은 라운지 공유자입니다.", HttpStatus.FORBIDDEN), - ALREADY_INVITED_USER_EXCEPTION("이미 라운지에 소속된 유저입니다.", HttpStatus.BAD_REQUEST), + ALREADY_EXISTS_LOUNGE_USER_EXCEPTION("이미 라운지에 소속된 유저입니다.", HttpStatus.CONFLICT), + ALREADY_INVITED_USER_EXCEPTION("이미 라운지에 초대된 유저입니다.", HttpStatus.BAD_REQUEST), ALREADY_DELETED_LOUNGE_EXCEPTION("이미 삭제된 라운지입니다.", HttpStatus.NOT_FOUND), MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION("라운지 개수는 최대 4개를 초과할 수 없습니다.", HttpStatus.BAD_REQUEST), NOT_ALLOW_LOUNGE_WITHDRAW_EXCEPTION("라운지 생성자는 탈퇴할 수 없습니다.", HttpStatus.BAD_REQUEST); From 3ca7316a5c5c96187923c822be5f2907b5709dd5 Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:56:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=ED=99=9C=EC=84=B1=ED=99=94=EB=90=9C?= =?UTF-8?q?=20=EB=9D=BC=EC=9A=B4=EC=A7=80=20=EA=B3=B5=EC=9C=A0=EC=9E=90=20?= =?UTF-8?q?=EC=B9=B4=EC=9A=B4=ED=8C=85=20=EB=B2=84=EA=B7=B8=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=AC=B8=20=EC=88=98=EC=A0=95=20#261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/LoungeSharerRepository.java | 14 +++++++++++++- 1 file changed, 13 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 596e7861..00a4ed14 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 @@ -19,11 +19,23 @@ SELECT CASE WHEN EXISTS ( """) boolean existsActiveLoungeSharerByUserIdAndLoungeId(@Param("userId") Long userId, @Param("loungeId") Long loungeId); + @Query(""" + SELECT CASE WHEN EXISTS ( + SELECT 1 + FROM LoungeSharer ls + WHERE ls.user.id = :userId + AND ls.lounge.id = :loungeId + ) THEN true ELSE false END + """) + boolean existsLoungeSharerByUserIdAndLoungeId(@Param("userId") Long userId, @Param("loungeId") Long loungeId); + List findByLounge_IdAndUser_NicknameContaining(Long loungeId, String nickname); @Query(""" SELECT COUNT(ls) FROM LoungeSharer ls - JOIN ls.lounge l WHERE l.status = 'ACTIVE' + JOIN ls.lounge l + WHERE l.status = 'ACTIVE' + AND ls.status = 'ACTIVE' AND ls.user.id = :userId """) long countActiveLoungeSharerByUserId(@Param("userId") Long userId); From 432e2d8a8ee2745dfc4172f0f27dbf4fe2e810b6 Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:57:15 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B4=EC=A7=80=EC=97=90=20=EC=B4=88=EB=8C=80=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=B4=88=EB=8C=80=EC=8B=9C=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=80=EC=9E=A5=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=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 --- .../application/LoungeSharerService.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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 f2b197cb..1ea1f94d 100644 --- a/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java +++ b/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java @@ -1,5 +1,6 @@ package com.example.daobe.lounge.application; +import static com.example.daobe.lounge.exception.LoungeExceptionType.ALREADY_EXISTS_LOUNGE_USER_EXCEPTION; import static com.example.daobe.lounge.exception.LoungeExceptionType.ALREADY_INVITED_USER_EXCEPTION; import static com.example.daobe.lounge.exception.LoungeExceptionType.INVALID_LOUNGE_SHARER_EXCEPTION; import static com.example.daobe.lounge.exception.LoungeExceptionType.MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION; @@ -30,7 +31,7 @@ public class LoungeSharerService { public void createAndSaveLoungeSharer(User user, Lounge lounge) { // 라운지 최대 개수를 초과하는지 검증 - if (isMaximumCountLounge(user.getId())) { + if (isOverMaximumCountLounge(user.getId())) { throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION); } @@ -43,7 +44,7 @@ public void createAndSaveLoungeSharer(User user, Lounge lounge) { } public void inviteUser(User user, Lounge lounge, Long inviterId) { - validateInvite(user, lounge, inviterId); + validateInvite(user.getId(), lounge, inviterId); LoungeSharer loungeSharer = LoungeSharer.builder() .user(user) .lounge(lounge) @@ -52,6 +53,7 @@ public void inviteUser(User user, Lounge lounge, Long inviterId) { eventPublisher.publishEvent(new LoungeInviteEvent(inviterId, loungeSharer)); } + // FIXME: public void updateInvitedUserStatus(User invitedUser, Lounge lounge) { LoungeSharer findSharer = loungeSharerRepository.findByUserIdAndLoungeId(invitedUser.getId(), lounge.getId()); if (!findSharer.isActive()) { @@ -81,15 +83,16 @@ public void validateLoungeSharer(Long userId, Long loungeId) { } // TODO: 추후 도메인 로직으로 분리 - private void validateInvite(User user, Lounge lounge, Long inviterId) { + private void validateInvite(Long userId, Lounge lounge, Long inviterId) { lounge.isActiveOrThrow(); validateLoungeSharer(inviterId, lounge.getId()); + validateAlreadyInvited(userId, lounge.getId()); - if (isExistUserInLounge(user.getId(), lounge.getId())) { - throw new LoungeException(ALREADY_INVITED_USER_EXCEPTION); + if (isExistUserInLounge(userId, lounge.getId())) { + throw new LoungeException(ALREADY_EXISTS_LOUNGE_USER_EXCEPTION); } - if (isMaximumCountLounge(user.getId())) { + if (isOverMaximumCountLounge(userId)) { throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION); } } @@ -98,7 +101,14 @@ private boolean isExistUserInLounge(Long userId, Long loungeId) { return loungeSharerRepository.existsActiveLoungeSharerByUserIdAndLoungeId(userId, loungeId); } - private boolean isMaximumCountLounge(Long userId) { - return loungeSharerRepository.countActiveLoungeSharerByUserId(userId) == MAX_LOUNGE_COUNT; + private boolean isOverMaximumCountLounge(Long userId) { + return loungeSharerRepository.countActiveLoungeSharerByUserId(userId) >= MAX_LOUNGE_COUNT; + } + + private void validateAlreadyInvited(Long userId, Long loungeId) { + boolean isAlreadyInvited = loungeSharerRepository.existsLoungeSharerByUserIdAndLoungeId(userId, loungeId); + if (isAlreadyInvited) { + throw new LoungeException(ALREADY_INVITED_USER_EXCEPTION); + } } -} +} \ No newline at end of file From 87e35fcc27f0e32a2a80d740cc40144bcb45b5ec Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:02:45 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=AF=B8=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B4=EC=A7=80=EC=97=90=20=EC=B4=88=EB=8C=80=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=EC=98=88=EC=99=B8=20HTTP=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=BD=94=EB=93=9C=20=EB=B0=8F=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/daobe/lounge/application/LoungeSharerService.java | 4 ++-- .../example/daobe/lounge/exception/LoungeExceptionType.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 1ea1f94d..07ca83b6 100644 --- a/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java +++ b/src/main/java/com/example/daobe/lounge/application/LoungeSharerService.java @@ -1,7 +1,7 @@ package com.example.daobe.lounge.application; import static com.example.daobe.lounge.exception.LoungeExceptionType.ALREADY_EXISTS_LOUNGE_USER_EXCEPTION; -import static com.example.daobe.lounge.exception.LoungeExceptionType.ALREADY_INVITED_USER_EXCEPTION; +import static com.example.daobe.lounge.exception.LoungeExceptionType.ALREADY_INVITED_LOUNGE_USER_EXCEPTION; import static com.example.daobe.lounge.exception.LoungeExceptionType.INVALID_LOUNGE_SHARER_EXCEPTION; import static com.example.daobe.lounge.exception.LoungeExceptionType.MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION; @@ -108,7 +108,7 @@ private boolean isOverMaximumCountLounge(Long userId) { private void validateAlreadyInvited(Long userId, Long loungeId) { boolean isAlreadyInvited = loungeSharerRepository.existsLoungeSharerByUserIdAndLoungeId(userId, loungeId); if (isAlreadyInvited) { - throw new LoungeException(ALREADY_INVITED_USER_EXCEPTION); + throw new LoungeException(ALREADY_INVITED_LOUNGE_USER_EXCEPTION); } } } \ No newline at end of file diff --git a/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java b/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java index 18629769..7bde460e 100644 --- a/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java +++ b/src/main/java/com/example/daobe/lounge/exception/LoungeExceptionType.java @@ -10,7 +10,7 @@ public enum LoungeExceptionType implements BaseExceptionType { INVALID_LOUNGE_OWNER_EXCEPTION("유효하지 않은 라운지 주인입니다.", HttpStatus.FORBIDDEN), INVALID_LOUNGE_SHARER_EXCEPTION("유효하지 않은 라운지 공유자입니다.", HttpStatus.FORBIDDEN), ALREADY_EXISTS_LOUNGE_USER_EXCEPTION("이미 라운지에 소속된 유저입니다.", HttpStatus.CONFLICT), - ALREADY_INVITED_USER_EXCEPTION("이미 라운지에 초대된 유저입니다.", HttpStatus.BAD_REQUEST), + ALREADY_INVITED_LOUNGE_USER_EXCEPTION("이미 라운지에 초대된 유저입니다.", HttpStatus.CONFLICT), ALREADY_DELETED_LOUNGE_EXCEPTION("이미 삭제된 라운지입니다.", HttpStatus.NOT_FOUND), MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION("라운지 개수는 최대 4개를 초과할 수 없습니다.", HttpStatus.BAD_REQUEST), NOT_ALLOW_LOUNGE_WITHDRAW_EXCEPTION("라운지 생성자는 탈퇴할 수 없습니다.", HttpStatus.BAD_REQUEST);