Skip to content

Commit

Permalink
[Feat]: 복약 일정 조회 시 스티커 파라미터 추가 (#151)
Browse files Browse the repository at this point in the history
StickerInfo 추가
복약 일정 조회 시 스티커 파라미터 추가

Related to: #150
  • Loading branch information
onpyeong committed Jul 24, 2024
1 parent 79a7b3a commit 2d337f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package io.sobok.SobokSobok.pill.infrastructure;

import com.querydsl.core.Tuple;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.sobok.SobokSobok.pill.domain.PillSchedule;
import io.sobok.SobokSobok.pill.domain.QPill;
import io.sobok.SobokSobok.pill.domain.QPillSchedule;
import io.sobok.SobokSobok.pill.ui.dto.DateScheduleResponse;
import io.sobok.SobokSobok.pill.ui.dto.MonthScheduleResponse;
import io.sobok.SobokSobok.pill.ui.dto.PillScheduleInfo;
import io.sobok.SobokSobok.pill.ui.dto.StickerInfo;
import io.sobok.SobokSobok.sticker.domain.QLikeSchedule;
import io.sobok.SobokSobok.sticker.domain.QSticker;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
Expand Down Expand Up @@ -106,17 +104,22 @@ public List<DateScheduleResponse> getDateSchedule(Long userId, LocalDate date) {
.where(pillSchedule.scheduleDate.eq(date), pillSchedule.scheduleTime.eq(time))
.fetch();

Map<Long, List<Long>> stickerIdMap = pillScheduleIds.stream()
Map<Long, List<StickerInfo>> stickerIdMap = pillScheduleIds.stream()
.collect(Collectors.toMap(id -> id, id -> queryFactory
.select(likeSchedule.stickerId)
.select(likeSchedule.stickerId, likeSchedule.id)
.from(likeSchedule)
.where(likeSchedule.scheduleId.eq(id))
.fetch()));
.fetch().stream()
.map(tuple -> StickerInfo.builder()
.stickerId(tuple.get(0, Long.class))
.likeScheduleId(tuple.get(1, Long.class))
.build()
).collect(Collectors.toList())));

// 결과 매핑
List<PillScheduleInfo> pillScheduleInfoList = pillScheduleIds.stream()
.flatMap(scheduleId -> {
List<Long> stickerIds = stickerIdMap.getOrDefault(scheduleId, Collections.emptyList());
List<StickerInfo> stickerIds = stickerIdMap.getOrDefault(scheduleId, Collections.emptyList());
return queryFactory
.select(
pillSchedule.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package io.sobok.SobokSobok.pill.ui.dto;

import lombok.Builder;

import java.util.List;
import lombok.Builder;

@Builder
public record PillScheduleInfo(

Long scheduleId,
Long pillId,
String pillName,
Boolean isCheck,
Integer color,
List<Long> stickerId,
Long stickerTotalCount
Long scheduleId,
Long pillId,
String pillName,
Boolean isCheck,
Integer color,
List<StickerInfo> stickerId,
Long stickerTotalCount
) {

}
11 changes: 11 additions & 0 deletions src/main/java/io/sobok/SobokSobok/pill/ui/dto/StickerInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.sobok.SobokSobok.pill.ui.dto;

import lombok.Builder;

@Builder
public record StickerInfo(
Long stickerId,
Long likeScheduleId
) {

}

0 comments on commit 2d337f0

Please sign in to comment.