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 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/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..4e21da55 --- /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.voteRestriction.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.of(9999, 12, 31)) + }); // 제재를 당하고 있지 않은 상태 + + companion object { + fun fromRestrictionPriority(loginUser: User): Pair { + return entries.first { it.discriminationRestrictionType(loginUser) } + .restrictionCalculator(loginUser) + } + } + +}