feat(gift): 선물함 리스트 배송지 상태를 응답한다
This commit is contained in:
@@ -62,6 +62,9 @@ data class GiftListResponse(
|
||||
counterpartMemberId = it.counterpartMemberId,
|
||||
counterpartNickname = it.counterpartNickname,
|
||||
counterpartProfileImageUrl = it.counterpartProfileImageUrl,
|
||||
recipientAddressRegistered = it.recipientAddressRegistered,
|
||||
recipientAddressDeadlineAt = it.recipientAddressDeadlineAt?.toUtcIso(),
|
||||
canceledAt = it.canceledAt?.toUtcIso(),
|
||||
createdAt = it.createdAt?.toUtcIso()
|
||||
)
|
||||
},
|
||||
@@ -83,6 +86,9 @@ data class GiftListItemResponse(
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String,
|
||||
val recipientAddressRegistered: Boolean,
|
||||
val recipientAddressDeadlineAt: String?,
|
||||
val canceledAt: String?,
|
||||
val createdAt: String?
|
||||
)
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ data class GiftListItemResult(
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String,
|
||||
val recipientAddressRegistered: Boolean,
|
||||
val recipientAddressDeadlineAt: LocalDateTime?,
|
||||
val canceledAt: LocalDateTime?,
|
||||
val createdAt: LocalDateTime?
|
||||
)
|
||||
|
||||
@@ -153,10 +156,13 @@ class GiftQueryService(
|
||||
val membersById = memberRepository.findAllById(
|
||||
gifts.content.flatMap { listOf(it.senderMemberId, it.recipientMemberId) }.toSet()
|
||||
).associateBy { it.id ?: throw invalidRequest() }
|
||||
val deliveriesByGiftId = deliveryRepository.findByGiftIdIn(
|
||||
gifts.content.mapNotNull { it.id }
|
||||
).associateBy { it.giftId }
|
||||
|
||||
return GiftListResult(
|
||||
totalCount = gifts.totalElements,
|
||||
items = gifts.content.map { it.toGiftListItem(memberId, membersById) },
|
||||
items = gifts.content.map { it.toGiftListItem(memberId, membersById, deliveriesByGiftId) },
|
||||
page = normalizedPage,
|
||||
size = normalizedSize,
|
||||
hasNext = gifts.hasNext()
|
||||
@@ -203,10 +209,16 @@ class GiftQueryService(
|
||||
)
|
||||
}
|
||||
|
||||
private fun Gift.toGiftListItem(memberId: Long, membersById: Map<Long, Member>): GiftListItemResult {
|
||||
private fun Gift.toGiftListItem(
|
||||
memberId: Long,
|
||||
membersById: Map<Long, Member>,
|
||||
deliveriesByGiftId: Map<Long, GiftDelivery>
|
||||
): 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()
|
||||
val delivery = deliveriesByGiftId[id] ?: throw invalidRequest()
|
||||
val recipientAddressRegistered = delivery.hasCompleteRecipientInformation()
|
||||
|
||||
return GiftListItemResult(
|
||||
applicationNo = applicationNo,
|
||||
@@ -219,6 +231,9 @@ class GiftQueryService(
|
||||
counterpartMemberId = counterpartId,
|
||||
counterpartNickname = counterpart.nickname,
|
||||
counterpartProfileImageUrl = counterpart.profileImageUrl(),
|
||||
recipientAddressRegistered = recipientAddressRegistered,
|
||||
recipientAddressDeadlineAt = delivery.recipientAddressDeadlineAt.takeUnless { recipientAddressRegistered },
|
||||
canceledAt = delivery.canceledAt,
|
||||
createdAt = createdAt
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user