diff --git a/api/src/main/kotlin/com/mashup/dojo/MemberController.kt b/api/src/main/kotlin/com/mashup/dojo/MemberController.kt index 3fbf3541..37e0e99a 100644 --- a/api/src/main/kotlin/com/mashup/dojo/MemberController.kt +++ b/api/src/main/kotlin/com/mashup/dojo/MemberController.kt @@ -53,6 +53,9 @@ class MemberController( ) ) + // 가입된 멤버에 대해서 기본 관계 생성 + memberUseCase.createDefaultMemberRelation(memberId) + return DojoApiResponse.success(MemberCreateResponse(memberId)) } diff --git a/service/src/main/kotlin/com/mashup/dojo/domain/MemberRelation.kt b/service/src/main/kotlin/com/mashup/dojo/domain/MemberRelation.kt index a047691a..7201d58a 100644 --- a/service/src/main/kotlin/com/mashup/dojo/domain/MemberRelation.kt +++ b/service/src/main/kotlin/com/mashup/dojo/domain/MemberRelation.kt @@ -18,7 +18,7 @@ data class MemberRelation( val lastUpdatedAt: LocalDateTime, ) { companion object { - fun create( + fun createAccompanyRelation( fromId: MemberId, toId: MemberId, ): MemberRelation { diff --git a/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt b/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt index 605b77dc..e1266327 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt @@ -23,6 +23,11 @@ interface MemberRelationService { toId: MemberId, ) + fun bulkCreateRelation( + fromId: MemberId, + theOtherMemberIds: List, + ): List + fun updateRelationToFriend( fromId: String, toId: String, @@ -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, + ): List { + 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, diff --git a/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt b/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt index 0e956321..56ee9bae 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt @@ -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 @@ -47,6 +48,8 @@ interface MemberUseCase { // ToDo 로직 연결 후 추후 제거 fun findMemberByIdMock(targetMemberId: MemberId): ProfileResponse + + fun createDefaultMemberRelation(newMemberId: MemberId): List } @Component @@ -132,4 +135,14 @@ class DefaultMemberUseCase( friendCount = 0 ) } + + @Transactional + override fun createDefaultMemberRelation(newMemberId: MemberId): List { + val allMemberIds = + memberService.findAllMember() + .filter { it.id != newMemberId } + .map { it.id } + + return memberRelationService.bulkCreateRelation(newMemberId, allMemberIds) + } }