Skip to content

Commit

Permalink
refac: 친구신청 및 신청받는 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
minahYu committed Jun 12, 2024
1 parent e101402 commit fae8c95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 17 additions & 5 deletions user/src/main/kotlin/kpring/user/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ class User(
val friends: MutableSet<Friend> = mutableSetOf(),
// Other fields and methods...
) {
fun addFriendRelation(
friend: User,
requestStatus: FriendRequestStatus,
) {
val friendRelation = Friend(user = this, friend = friend, requestStatus = requestStatus)
fun requestFriend(user: User) {
val friendRelation =
Friend(
user = this,
friend = user,
requestStatus = FriendRequestStatus.REQUESTED,
)
friends.add(friendRelation)
}

fun receiveFriendRequest(user: User) {
val friendRelation =
Friend(
user = this,
friend = user,
requestStatus = FriendRequestStatus.RECEIVED,
)
friends.add(friendRelation)
}

Expand Down
5 changes: 2 additions & 3 deletions user/src/main/kotlin/kpring/user/service/FriendServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kpring.core.global.exception.ServiceException
import kpring.user.dto.response.DeleteFriendResponse
import kpring.user.dto.response.GetFriendsResponse
import kpring.user.dto.result.AddFriendResponse
import kpring.user.entity.FriendRequestStatus
import kpring.user.entity.User
import kpring.user.exception.UserErrorCode
import kpring.user.repository.FriendRepository
Expand All @@ -30,8 +29,8 @@ class FriendServiceImpl(

checkSelfFriend(user, friend)
checkFriendRelationExists(userId, friendId)
user.addFriendRelation(friend, FriendRequestStatus.REQUESTED)
friend.addFriendRelation(user, FriendRequestStatus.RECEIVED)
user.requestFriend(friend)
friend.receiveFriendRequest(user)

return AddFriendResponse(friend.id!!)
}
Expand Down

0 comments on commit fae8c95

Please sign in to comment.