Skip to content

Commit

Permalink
add : 회원가입 시, 전체 멤버에 대한 기본 관계 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
xonmin committed Aug 14, 2024
1 parent d7ac6af commit 5740cfd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/MemberController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class MemberController(
)
)

// 가입된 멤버에 대해서 기본 관계 생성
memberUseCase.createDefaultMemberRelation(memberId)

return DojoApiResponse.success(MemberCreateResponse(memberId))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class MemberRelation(
val lastUpdatedAt: LocalDateTime,
) {
companion object {
fun create(
fun createAccompanyRelation(
fromId: MemberId,
toId: MemberId,
): MemberRelation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ interface MemberRelationService {
toId: MemberId,
)

fun bulkCreateRelation(
fromId: MemberId,
theOtherMemberIds: List<MemberId>,
): List<MemberRelationId>

fun updateRelationToFriend(
fromId: String,
toId: String,
Expand Down Expand Up @@ -56,10 +61,24 @@ class DefaultMemberRelationService(
fromId: MemberId,
toId: MemberId,
) {
val memberRelation = MemberRelation.create(fromId, toId)
val memberRelation = MemberRelation.createAccompanyRelation(fromId, toId)
memberRelationRepository.save(memberRelation.toEntity())
}

@Transactional
override fun bulkCreateRelation(
fromId: MemberId,
theOtherMemberIds: List<MemberId>,
): List<MemberRelationId> {
val memberRelationEntityList =
theOtherMemberIds.map {
MemberRelation.createAccompanyRelation(fromId, it).toEntity()
}

val entities = memberRelationRepository.saveAll(memberRelationEntityList)
return entities.map { MemberRelationId(it.id) }
}

@Transactional
override fun updateRelationToFriend(
fromId: String,
Expand Down
13 changes: 13 additions & 0 deletions service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mashup.dojo.domain.ImageId
import com.mashup.dojo.domain.MemberGender
import com.mashup.dojo.domain.MemberId
import com.mashup.dojo.domain.MemberPlatform
import com.mashup.dojo.domain.MemberRelationId
import com.mashup.dojo.service.CoinService
import com.mashup.dojo.service.ImageService
import com.mashup.dojo.service.MemberRelationService
Expand Down Expand Up @@ -47,6 +48,8 @@ interface MemberUseCase {

// ToDo 로직 연결 후 추후 제거
fun findMemberByIdMock(targetMemberId: MemberId): ProfileResponse

fun createDefaultMemberRelation(newMemberId: MemberId): List<MemberRelationId>
}

@Component
Expand Down Expand Up @@ -132,4 +135,14 @@ class DefaultMemberUseCase(
friendCount = 0
)
}

@Transactional
override fun createDefaultMemberRelation(newMemberId: MemberId): List<MemberRelationId> {
val allMemberIds =
memberService.findAllMember()
.filter { it.id != newMemberId }
.map { it.id }

return memberRelationService.bulkCreateRelation(newMemberId, allMemberIds)
}
}

0 comments on commit 5740cfd

Please sign in to comment.