Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#100 - 이용제한 API의 스펙을 클라이언트의 요구에 맞게 변경한다. #110

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/resources/config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,21 +52,23 @@ 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(
listOf(
Pair(
RestrictionType.PERMANENT_BAN_VOTE_REPORT,
Long.MAX_VALUE
),
Pair(
RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT,
30,
)
)
)
Expand All @@ -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
)
)
)
Expand All @@ -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
Expand All @@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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<RestrictionType, LocalDate>): 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
)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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<RestrictionType, LocalDate>
) {
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 },
{ _ ->
Comment on lines +30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오홍 이렇게도 표현할 수 있군요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알러뷰

Pair(RestrictionType.NONE, LocalDate.of(9999, 12, 31))
}); // 제재를 당하고 있지 않은 상태

companion object {
fun fromRestrictionPriority(loginUser: User): Pair<RestrictionType, LocalDate> {
return entries.first { it.discriminationRestrictionType(loginUser) }
.restrictionCalculator(loginUser)
}
}

}
Loading