|
1 | 1 | package org.clokey.domain.cloth.service; |
2 | 2 |
|
| 3 | +import java.time.LocalDate; |
| 4 | +import java.time.ZoneId; |
3 | 5 | import java.util.List; |
4 | 6 | import java.util.Map; |
5 | 7 | import java.util.Set; |
|
17 | 19 | import org.clokey.domain.cloth.exception.ClothErrorCode; |
18 | 20 | import org.clokey.domain.cloth.repository.ClothRepository; |
19 | 21 | import org.clokey.domain.coordinate.repository.CoordinateClothRepository; |
| 22 | +import org.clokey.domain.coordinate.repository.CoordinateRepository; |
20 | 23 | import org.clokey.domain.history.repository.HistoryClothTagRepository; |
21 | 24 | import org.clokey.domain.image.event.ImageDeleteEvent; |
22 | 25 | import org.clokey.domain.search.event.ClothDeleteEvent; |
|
28 | 31 | import org.clokey.response.SliceResponse; |
29 | 32 | import org.clokey.util.S3Util; |
30 | 33 | import org.springframework.context.ApplicationEventPublisher; |
| 34 | +import org.springframework.data.domain.PageRequest; |
31 | 35 | import org.springframework.data.domain.Slice; |
| 36 | +import org.springframework.data.domain.SliceImpl; |
32 | 37 | import org.springframework.stereotype.Service; |
33 | 38 | import org.springframework.transaction.annotation.Transactional; |
34 | 39 |
|
35 | 40 | @Service |
36 | 41 | @RequiredArgsConstructor |
37 | 42 | public class ClothServiceImpl implements ClothService { |
38 | 43 |
|
| 44 | + private static final ZoneId KST = ZoneId.of("Asia/Seoul"); |
| 45 | + |
39 | 46 | private final MemberUtil memberUtil; |
40 | 47 |
|
41 | 48 | private final ClothRepository clothRepository; |
42 | 49 | private final CategoryRepository categoryRepository; |
43 | 50 | private final HistoryClothTagRepository historyClothTagRepository; |
| 51 | + private final CoordinateRepository coordinateRepository; |
44 | 52 |
|
45 | 53 | private final ApplicationEventPublisher eventPublisher; |
46 | 54 | private final CoordinateClothRepository coordinateClothRepository; |
@@ -115,7 +123,27 @@ public SliceResponse<ClothListResponse> getClothes( |
115 | 123 | clothRepository.findAllMemberClothesByCategoriesAndSeasons( |
116 | 124 | lastClothId, size, direction, categoryIds, currentMember.getId(), seasons); |
117 | 125 |
|
118 | | - return SliceResponse.from(result); |
| 126 | + Set<Long> todayCoordinateClothIds = |
| 127 | + coordinateRepository |
| 128 | + .findDailyCoordinateByDateAndMemberId( |
| 129 | + LocalDate.now(KST), currentMember.getId()) |
| 130 | + .map( |
| 131 | + coordinate -> |
| 132 | + coordinate.getCoordinateClothes().stream() |
| 133 | + .map(cc -> cc.getCloth().getId()) |
| 134 | + .collect(Collectors.toSet())) |
| 135 | + .orElse(Set.of()); |
| 136 | + |
| 137 | + List<ClothListResponse> content = |
| 138 | + result.getContent().stream() |
| 139 | + .map( |
| 140 | + cloth -> |
| 141 | + cloth.withTodayCoordinateCloth( |
| 142 | + todayCoordinateClothIds.contains(cloth.clothId()))) |
| 143 | + .toList(); |
| 144 | + |
| 145 | + return SliceResponse.from( |
| 146 | + new SliceImpl<>(content, PageRequest.of(0, size), result.hasNext())); |
119 | 147 | } |
120 | 148 |
|
121 | 149 | @Override |
|
0 commit comments