From 710292bd7985110f1fb3da556b3499e1b316932e Mon Sep 17 00:00:00 2001 From: jaeyeonkim Date: Tue, 27 Aug 2024 22:22:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20Restriction=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/CheckedRestrictionResponse.kt | 19 +++------ .../service/CheckedUserRestrictionService.kt | 4 +- .../user/restriction/RestrictionPriority.kt | 42 +++++++++++++++++++ 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt diff --git a/core/src/main/kotlin/com/wespot/user/dto/response/CheckedRestrictionResponse.kt b/core/src/main/kotlin/com/wespot/user/dto/response/CheckedRestrictionResponse.kt index 8e7d69e7..42b27784 100644 --- a/core/src/main/kotlin/com/wespot/user/dto/response/CheckedRestrictionResponse.kt +++ b/core/src/main/kotlin/com/wespot/user/dto/response/CheckedRestrictionResponse.kt @@ -1,27 +1,18 @@ package com.wespot.user.dto.response import com.wespot.user.RestrictionType -import com.wespot.user.User import java.time.LocalDate data class CheckedRestrictionResponse( - val messageRestrictionType: RestrictionType, - val messageReleaseDate: LocalDate, - val voteRestrictionType: RestrictionType, - val voteReleaseDate: LocalDate, + val restrictionType: RestrictionType, + val releaseDate: LocalDate, ) { - companion object { - - fun from(user: User): CheckedRestrictionResponse { + fun from(userRestriction: Pair): CheckedRestrictionResponse { return CheckedRestrictionResponse( - user.restriction.messageRestriction.restrictionType, - user.restriction.messageRestriction.releaseDate, - user.restriction.voteRestriction.restrictionType, - user.restriction.voteRestriction.releaseDate + restrictionType = userRestriction.first, + releaseDate = userRestriction.second ) } - } - } diff --git a/core/src/main/kotlin/com/wespot/user/service/CheckedUserRestrictionService.kt b/core/src/main/kotlin/com/wespot/user/service/CheckedUserRestrictionService.kt index 6128c752..825ef596 100644 --- a/core/src/main/kotlin/com/wespot/user/service/CheckedUserRestrictionService.kt +++ b/core/src/main/kotlin/com/wespot/user/service/CheckedUserRestrictionService.kt @@ -4,6 +4,7 @@ import com.wespot.auth.service.SecurityUtils import com.wespot.user.dto.response.CheckedRestrictionResponse import com.wespot.user.port.`in`.CheckedUserRestrictionUseCase import com.wespot.user.port.out.UserPort +import com.wespot.user.restriction.RestrictionPriority import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -15,8 +16,9 @@ class CheckedUserRestrictionService( @Transactional(readOnly = true) override fun getUserRestriction(): CheckedRestrictionResponse { val loginUser = SecurityUtils.getLoginUser(userPort) + val userRestriction = RestrictionPriority.fromRestrictionPriority(loginUser) - return CheckedRestrictionResponse.from(loginUser) + return CheckedRestrictionResponse.from(userRestriction) } } diff --git a/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt b/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt new file mode 100644 index 00000000..86b5137b --- /dev/null +++ b/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt @@ -0,0 +1,42 @@ +package com.wespot.user.restriction + +import com.wespot.user.RestrictionType +import com.wespot.user.User +import java.time.LocalDate + +enum class RestrictionPriority( + private val discriminationRestrictionType: (loginUser: User) -> Boolean, + private val restrictionCalculator: (loginUser: User) -> Pair +) { + FIRST_PRIORITY_RESTRICTION( + { loginUser -> loginUser.restriction.messageRestriction.restrictionType == RestrictionType.PERMANENT_BAN_MESSAGE_REPORT }, + { loginUser -> + Pair( + RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, + loginUser.restriction.messageRestriction.releaseDate + ) + }), // 가장 우선순위가 높은 쪽지로 인한 영구제재 + SECOND_PRIORITY_RESTRICTION( + { loginUser -> loginUser.restriction.messageRestriction.restrictionType == RestrictionType.PERMANENT_BAN_VOTE_REPORT }, + { loginUser -> + Pair(RestrictionType.PERMANENT_BAN_VOTE_REPORT, loginUser.restriction.voteRestriction.releaseDate) + }), // 두 번째로 우선순위가 높은 투표로 인한 영구제재 + THIRD_PRIORITY_RESTRICTION( + { loginUser -> loginUser.restriction.messageRestriction.restrictionType == RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT }, + { loginUser -> + Pair(RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT, loginUser.restriction.messageRestriction.releaseDate) + }), // 세 번째로 우선순위가 높은 쪽지로 인한 이용제한 + LAST_PRIORITY_RESTRICTION( + { _ -> true }, + { _ -> + Pair(RestrictionType.NONE, LocalDate.now()) + }); // 제재를 당하고 있지 않은 상태 + + companion object { + fun fromRestrictionPriority(loginUser: User): Pair { + return entries.first { it.discriminationRestrictionType(loginUser) } + .restrictionCalculator(loginUser) + } + } + +} From 8a5bf3063fe3ea9e69f7937d7c068281640cf924 Mon Sep 17 00:00:00 2001 From: jaeyeonkim Date: Tue, 27 Aug 2024 22:35:33 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- .../CheckedUserRestrictionServiceTest.kt | 53 +++++++++---------- .../user/restriction/RestrictionPriority.kt | 4 +- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/app/src/test/kotlin/com/wespot/user/service/CheckedUserRestrictionServiceTest.kt b/app/src/test/kotlin/com/wespot/user/service/CheckedUserRestrictionServiceTest.kt index 50c245d6..4924292d 100644 --- a/app/src/test/kotlin/com/wespot/user/service/CheckedUserRestrictionServiceTest.kt +++ b/app/src/test/kotlin/com/wespot/user/service/CheckedUserRestrictionServiceTest.kt @@ -25,18 +25,20 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( val response = checkedUserRestrictionService.getUserRestriction() // then - response.messageRestrictionType shouldBe RestrictionType.NONE - response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) - response.voteRestrictionType shouldBe RestrictionType.NONE - response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) + response.restrictionType shouldBe RestrictionType.NONE + response.releaseDate shouldBe LocalDate.of(9999, 12, 31) } @Test - fun `사용자가 메시지로 인해 제한을 당한 것을 확인한다`() { + fun `사용자가 쪽지와 투표로 인해 영구제재를 당했을 때, 쪽지에 대한 제재 상황을 반환받는다`() { // given val user = UserFixture.createUserWithRestrictionTypeAndRestrictDay( listOf( + Pair( + RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, + Long.MAX_VALUE + ), Pair( RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, Long.MAX_VALUE @@ -50,14 +52,12 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( val response = checkedUserRestrictionService.getUserRestriction() // then - response.messageRestrictionType shouldBe RestrictionType.PERMANENT_BAN_MESSAGE_REPORT - response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) - response.voteRestrictionType shouldBe RestrictionType.NONE - response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) + response.restrictionType shouldBe RestrictionType.PERMANENT_BAN_MESSAGE_REPORT + response.releaseDate shouldBe LocalDate.of(9999, 12, 31) } @Test - fun `사용자가 투표로 인해 제한을 당한 것을 확인한다`() { + fun `사용자가 투표 영구 제재와 쪽지 이용 제재를 받았을 때, 투표로 인해 영구제재를 당한 것을 확인한다`() { // given val user = UserFixture.createUserWithRestrictionTypeAndRestrictDay( @@ -65,6 +65,10 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( Pair( RestrictionType.PERMANENT_BAN_VOTE_REPORT, Long.MAX_VALUE + ), + Pair( + RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT, + 30, ) ) ) @@ -75,25 +79,20 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( val response = checkedUserRestrictionService.getUserRestriction() // then - response.messageRestrictionType shouldBe RestrictionType.NONE - response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) - response.voteRestrictionType shouldBe RestrictionType.PERMANENT_BAN_VOTE_REPORT - response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) + response.restrictionType shouldBe RestrictionType.PERMANENT_BAN_VOTE_REPORT + response.releaseDate shouldBe LocalDate.of(9999, 12, 31) } @Test - fun `사용자가 투표, 쪽지로 인해 제한을 당한 것을 확인한다`() { + fun `사용자가 쪽지로 인해 30일 이용제한을 당한 것을 확인한다`() { // given + val now = LocalDate.now() val user = UserFixture.createUserWithRestrictionTypeAndRestrictDay( listOf( Pair( - RestrictionType.PERMANENT_BAN_VOTE_REPORT, - Long.MAX_VALUE - ), - Pair( - RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, - Long.MAX_VALUE + RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT, + 30 ) ) ) @@ -104,10 +103,8 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( val response = checkedUserRestrictionService.getUserRestriction() // then - response.messageRestrictionType shouldBe RestrictionType.PERMANENT_BAN_MESSAGE_REPORT - response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) - response.voteRestrictionType shouldBe RestrictionType.PERMANENT_BAN_VOTE_REPORT - response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) + response.restrictionType shouldBe RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT + response.releaseDate shouldBe now.plusDays(30) } @Test @@ -130,10 +127,8 @@ class CheckedUserRestrictionServiceTest @Autowired constructor( val response = checkedUserRestrictionService.getUserRestriction() // then - response.messageRestrictionType shouldBe RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT - response.messageReleaseDate shouldBe now.plusDays(90) - response.voteRestrictionType shouldBe RestrictionType.NONE - response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) + response.restrictionType shouldBe RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT + response.releaseDate shouldBe now.plusDays(90) } } diff --git a/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt b/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt index 86b5137b..4e21da55 100644 --- a/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt +++ b/domain/src/main/kotlin/com/wespot/user/restriction/RestrictionPriority.kt @@ -17,7 +17,7 @@ enum class RestrictionPriority( ) }), // 가장 우선순위가 높은 쪽지로 인한 영구제재 SECOND_PRIORITY_RESTRICTION( - { loginUser -> loginUser.restriction.messageRestriction.restrictionType == RestrictionType.PERMANENT_BAN_VOTE_REPORT }, + { loginUser -> loginUser.restriction.voteRestriction.restrictionType == RestrictionType.PERMANENT_BAN_VOTE_REPORT }, { loginUser -> Pair(RestrictionType.PERMANENT_BAN_VOTE_REPORT, loginUser.restriction.voteRestriction.releaseDate) }), // 두 번째로 우선순위가 높은 투표로 인한 영구제재 @@ -29,7 +29,7 @@ enum class RestrictionPriority( LAST_PRIORITY_RESTRICTION( { _ -> true }, { _ -> - Pair(RestrictionType.NONE, LocalDate.now()) + Pair(RestrictionType.NONE, LocalDate.of(9999, 12, 31)) }); // 제재를 당하고 있지 않은 상태 companion object { From 0a1d86bd2729b09c0ce3d0dc74620490aa18791d Mon Sep 17 00:00:00 2001 From: jaeyeonkim Date: Tue, 27 Aug 2024 22:38:33 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20TimeZone=20Caching=EC=9D=84=20?= =?UTF-8?q?=EB=A7=89=EC=95=84=20LocalDate=20=ED=83=80=EC=9E=84=20=EB=B6=88?= =?UTF-8?q?=EC=9D=BC=EC=B9=98=20=EB=AC=B8=EC=A0=9C=EB=A5=BC=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/resources/config b/app/src/main/resources/config index 14d02be3..86f470ba 160000 --- a/app/src/main/resources/config +++ b/app/src/main/resources/config @@ -1 +1 @@ -Subproject commit 14d02be3c34c4955a7d6cf58b9ed939f3deb9cb3 +Subproject commit 86f470babe0b7a6270fc3f8b4e2ccd16a18d9310