feat(gift): 선물함 상대 회원 정보를 추가한다
This commit is contained in:
@@ -59,6 +59,9 @@ data class GiftListResponse(
|
||||
priceCan = it.priceCan,
|
||||
categoryName = it.categoryName,
|
||||
sizeName = it.sizeName,
|
||||
counterpartMemberId = it.counterpartMemberId,
|
||||
counterpartNickname = it.counterpartNickname,
|
||||
counterpartProfileImageUrl = it.counterpartProfileImageUrl,
|
||||
createdAt = it.createdAt?.toUtcIso()
|
||||
)
|
||||
},
|
||||
@@ -77,6 +80,9 @@ data class GiftListItemResponse(
|
||||
val priceCan: Int,
|
||||
val categoryName: String,
|
||||
val sizeName: String,
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String,
|
||||
val createdAt: String?
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift.application
|
||||
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.Gift
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftCategoryRepository
|
||||
@@ -11,6 +12,7 @@ import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftSizePriceRep
|
||||
import kr.co.vividnext.sodalive.v2.gift.domain.GiftDirection
|
||||
import kr.co.vividnext.sodalive.v2.gift.domain.GiftListType
|
||||
import kr.co.vividnext.sodalive.v2.gift.domain.GiftStatus
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.data.domain.Sort
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
@@ -39,6 +41,9 @@ data class GiftListItemResult(
|
||||
val priceCan: Int,
|
||||
val categoryName: String,
|
||||
val sizeName: String,
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String,
|
||||
val createdAt: LocalDateTime?
|
||||
)
|
||||
|
||||
@@ -99,7 +104,9 @@ class GiftQueryService(
|
||||
private val sizePriceRepository: GiftSizePriceRepository,
|
||||
private val giftRepository: GiftRepository,
|
||||
private val deliveryRepository: GiftDeliveryRepository,
|
||||
private val memberRepository: MemberRepository
|
||||
private val memberRepository: MemberRepository,
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
@Transactional(readOnly = true)
|
||||
fun getFormOptions() = GiftFormOptionsResult(
|
||||
@@ -140,9 +147,13 @@ class GiftQueryService(
|
||||
)
|
||||
}
|
||||
|
||||
val membersById = memberRepository.findAllById(
|
||||
gifts.content.flatMap { listOf(it.senderMemberId, it.recipientMemberId) }.toSet()
|
||||
).associateBy { it.id ?: throw invalidRequest() }
|
||||
|
||||
return GiftListResult(
|
||||
totalCount = gifts.totalElements,
|
||||
items = gifts.content.map { it.toGiftListItem(memberId) },
|
||||
items = gifts.content.map { it.toGiftListItem(memberId, membersById) },
|
||||
page = normalizedPage,
|
||||
size = normalizedSize,
|
||||
hasNext = gifts.hasNext()
|
||||
@@ -189,16 +200,31 @@ class GiftQueryService(
|
||||
)
|
||||
}
|
||||
|
||||
private fun Gift.toGiftListItem(memberId: Long) = GiftListItemResult(
|
||||
applicationNo = applicationNo,
|
||||
direction = if (senderMemberId == memberId) GiftDirection.SENT else GiftDirection.RECEIVED,
|
||||
status = status,
|
||||
statusName = status.displayName,
|
||||
priceCan = salePriceCan,
|
||||
categoryName = categoryNameSnapshot,
|
||||
sizeName = sizeCode.displayName,
|
||||
createdAt = createdAt
|
||||
)
|
||||
private fun Gift.toGiftListItem(memberId: Long, membersById: Map<Long, Member>): GiftListItemResult {
|
||||
val direction = if (senderMemberId == memberId) GiftDirection.SENT else GiftDirection.RECEIVED
|
||||
val counterpartId = if (direction == GiftDirection.SENT) recipientMemberId else senderMemberId
|
||||
val counterpart = membersById[counterpartId] ?: throw invalidRequest()
|
||||
|
||||
return GiftListItemResult(
|
||||
applicationNo = applicationNo,
|
||||
direction = direction,
|
||||
status = status,
|
||||
statusName = status.displayName,
|
||||
priceCan = salePriceCan,
|
||||
categoryName = categoryNameSnapshot,
|
||||
sizeName = sizeCode.displayName,
|
||||
counterpartMemberId = counterpartId,
|
||||
counterpartNickname = counterpart.nickname,
|
||||
counterpartProfileImageUrl = counterpart.profileImageUrl(),
|
||||
createdAt = createdAt
|
||||
)
|
||||
}
|
||||
|
||||
private fun Member.profileImageUrl() = if (profileImage.isNullOrBlank()) {
|
||||
"$cloudFrontHost/profile/default-profile.png"
|
||||
} else {
|
||||
"$cloudFrontHost/$profileImage"
|
||||
}
|
||||
|
||||
private fun Gift.directionFor(memberId: Long) = when {
|
||||
senderMemberId == memberId -> GiftDirection.SENT
|
||||
|
||||
Reference in New Issue
Block a user