Skip to content

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

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

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.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 },
{ _ ->
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.now())
}); // 제재를 당하고 있지 않은 상태

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

}