|
1 | 1 | package io.sobok.SobokSobok.pill.infrastructure;
|
2 | 2 |
|
3 | 3 | import com.querydsl.core.Tuple;
|
4 |
| -import com.querydsl.core.types.Projections; |
5 | 4 | import com.querydsl.core.types.dsl.CaseBuilder;
|
6 | 5 | import com.querydsl.jpa.impl.JPAQueryFactory;
|
7 |
| -import io.sobok.SobokSobok.pill.domain.PillSchedule; |
8 | 6 | import io.sobok.SobokSobok.pill.domain.QPill;
|
9 | 7 | import io.sobok.SobokSobok.pill.domain.QPillSchedule;
|
10 | 8 | import io.sobok.SobokSobok.pill.ui.dto.DateScheduleResponse;
|
11 | 9 | import io.sobok.SobokSobok.pill.ui.dto.MonthScheduleResponse;
|
12 | 10 | import io.sobok.SobokSobok.pill.ui.dto.PillScheduleInfo;
|
| 11 | +import io.sobok.SobokSobok.pill.ui.dto.StickerInfo; |
13 | 12 | import io.sobok.SobokSobok.sticker.domain.QLikeSchedule;
|
14 | 13 | import io.sobok.SobokSobok.sticker.domain.QSticker;
|
15 |
| -import lombok.RequiredArgsConstructor; |
16 |
| -import org.springframework.stereotype.Repository; |
17 |
| - |
18 | 14 | import java.time.LocalDate;
|
19 | 15 | import java.util.*;
|
20 | 16 | import java.util.stream.Collectors;
|
| 17 | +import lombok.RequiredArgsConstructor; |
| 18 | +import org.springframework.stereotype.Repository; |
21 | 19 |
|
22 | 20 | @Repository
|
23 | 21 | @RequiredArgsConstructor
|
@@ -106,17 +104,22 @@ public List<DateScheduleResponse> getDateSchedule(Long userId, LocalDate date) {
|
106 | 104 | .where(pillSchedule.scheduleDate.eq(date), pillSchedule.scheduleTime.eq(time))
|
107 | 105 | .fetch();
|
108 | 106 |
|
109 |
| - Map<Long, List<Long>> stickerIdMap = pillScheduleIds.stream() |
| 107 | + Map<Long, List<StickerInfo>> stickerIdMap = pillScheduleIds.stream() |
110 | 108 | .collect(Collectors.toMap(id -> id, id -> queryFactory
|
111 |
| - .select(likeSchedule.stickerId) |
| 109 | + .select(likeSchedule.stickerId, likeSchedule.id) |
112 | 110 | .from(likeSchedule)
|
113 | 111 | .where(likeSchedule.scheduleId.eq(id))
|
114 |
| - .fetch())); |
| 112 | + .fetch().stream() |
| 113 | + .map(tuple -> StickerInfo.builder() |
| 114 | + .stickerId(tuple.get(0, Long.class)) |
| 115 | + .likeScheduleId(tuple.get(1, Long.class)) |
| 116 | + .build() |
| 117 | + ).collect(Collectors.toList()))); |
115 | 118 |
|
116 | 119 | // 결과 매핑
|
117 | 120 | List<PillScheduleInfo> pillScheduleInfoList = pillScheduleIds.stream()
|
118 | 121 | .flatMap(scheduleId -> {
|
119 |
| - List<Long> stickerIds = stickerIdMap.getOrDefault(scheduleId, Collections.emptyList()); |
| 122 | + List<StickerInfo> stickerIds = stickerIdMap.getOrDefault(scheduleId, Collections.emptyList()); |
120 | 123 | return queryFactory
|
121 | 124 | .select(
|
122 | 125 | pillSchedule.id,
|
|
0 commit comments