Skip to content

Commit

Permalink
refactor: BlockedUser 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sectionr0 committed Aug 8, 2024
1 parent 47dbd2d commit 169051c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ class GetMessageServiceTest : BehaviorSpec({
messagePort.findAllMessagesByTypeAndReceiverAfterCursor(
receiverId = receiver.id,
cursorId = cursorId,
blockedMessages = blockedUserIds,
blockedMessageIds = blockedUserIds,
pageable = pageRequest
)
} returns messages.take(10)
every {
messagePort.countReceivedMessagesAfterCursor(
receiverId = receiver.id,
cursorId = cursorId,
blockedMessages = blockedUserIds
blockedMessageIds = blockedUserIds
)
} returns 11
every { blockedUserPort.findAllByBlockerId(receiver.id) } returns emptyList()
Expand Down Expand Up @@ -240,15 +240,15 @@ class GetMessageServiceTest : BehaviorSpec({
messagePort.findAllMessagesByTypeAndReceiverAfterCursor(
receiverId = receiver.id,
cursorId = cursorId,
blockedMessages = blockedUserIds,
blockedMessageIds = blockedUserIds,
pageable = pageRequest
)
} returns messages.drop(10)
every {
messagePort.countReceivedMessagesAfterCursor(
receiverId = receiver.id,
cursorId = cursorId,
blockedMessages = blockedUserIds
blockedMessageIds = blockedUserIds
)
} returns 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class BlockedUserService(
blockedId = blockedUser.id,
messageId = messageId
)
check(!isAlreadyBlocked) { "이미 차단된 사용자입니다." }

val createBlockedUser = BlockedUser.create(
blockerId = loginUser.id,
blockedId = blockedUser.id,
messageId = messageId
messageId = messageId,
isAlreadyBlocked = isAlreadyBlocked
)
val saveBlockedUser = blockedUserPort.save(createBlockedUser)

return BlockedUserResponse.of(saveBlockedUser.id)
}

Expand All @@ -53,6 +54,7 @@ class BlockedUserService(
val message = findMessageById(id = messageId, messagePort = messagePort)
message.validateReceivedMessage(loginUser)
val blockedUser = findUserById(id = message.senderId, userPort = userPort)

return Pair(loginUser, blockedUser)
}

Expand Down
9 changes: 6 additions & 3 deletions domain/src/main/kotlin/com/wespot/user/block/BlockedUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ data class BlockedUser(
fun create(
blockerId: Long,
blockedId: Long,
messageId: Long
) =
BlockedUser(
messageId: Long,
isAlreadyBlocked: Boolean
): BlockedUser{
check(!isAlreadyBlocked) { "이미 차단된 사용자입니다." }
return BlockedUser(
id = 0,
blockerId = blockerId,
blockedId = blockedId,
messageId = messageId,
createdAt = LocalDateTime.now()
)
}
}

}

0 comments on commit 169051c

Please sign in to comment.