Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: 복약 일정 조회 시 스티커 파라미터 추가 #151

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
) {

}
Loading