Skip to content

Commit

Permalink
Merge pull request #70 from SWEET-DEVELOPERS/feature/#69-gift
Browse files Browse the repository at this point in the history
[fix] ์นœ๊ตฌ๋“ค์ด ๋“ฑ๋กํ•œ ์„ ๋ฌผ ์กฐํšŒ API response ์ˆ˜์ •
  • Loading branch information
hysong4u authored Jan 15, 2024
2 parents 5f250d6 + ca4cb3f commit 0d1f888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public record FriendGiftDto(
String name,
int cost,
String url,
LocalDateTime createDate
String giftOwner
) {

public static FriendGiftDto of(Gift gift) {
return new FriendGiftDto(
gift.getId(),
gift.getImageUrl(),
gift.getName(),
gift.getCost(),
gift.getUrl(),
gift.getCreateDate()
);
public static FriendGiftDto of(Gift gift, String giftOwner) {
return FriendGiftDto.builder()
.giftId(gift.getId())
.imageUrl(gift.getImageUrl())
.name(gift.getName())
.cost(gift.getCost())
.url(gift.getUrl())
.giftOwner(giftOwner)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static org.codehaus.groovy.runtime.DefaultGroovyMethods.collect;
import static org.sopt.sweet.global.error.ErrorCode.*;

@RequiredArgsConstructor
Expand Down Expand Up @@ -224,13 +225,15 @@ public List<FriendGiftDto> getFriendGift(Long memberId, Long roomId) {
checkRoomMemberNotExists(room, member);
List<Gift> gifts = giftRepository.findByRoomAndMemberNot(room, member);
return mapGiftsToFriendGiftDtoList(gifts);

}


private List<FriendGiftDto> mapGiftsToFriendGiftDtoList(List<Gift> gifts) {

return gifts.stream()
.sorted(Comparator.comparing(Gift::getCreateDate).reversed())
.map(gift -> FriendGiftDto.of(gift))
.map(gift -> FriendGiftDto.of(gift, gift.getMember().getNickName()))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit 0d1f888

Please sign in to comment.