Skip to content

Commit

Permalink
Merge pull request #88 from Jhsysng/feat/reminder
Browse files Browse the repository at this point in the history
Feat/reminder
  • Loading branch information
Jhsysng authored Jul 6, 2024
2 parents 02abb61 + 5863fd9 commit 29de77d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class InsightService {
private final InsightImageRepository insightImageRepository;
private final HashTagRepository hashTagRepository;
private final CustomReminderRepository customReminderRepository;
private final CustomInsightRepository customInsightRepository;
// S3 클라이언트와 버킷 이름을 주입
@Autowired
private S3Client s3Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public class ReminderQuestionQueryDto {
private Long reminderQuestionId;
private String insightTitle;
private String insightMainImage;
private LocalDateTime lastRemindedAt;
private LocalDateTime reminderAt;
private LocalDateTime answeredAt;
private List<String> insightTagList;

@Builder
public ReminderQuestionQueryDto(String reminderQuestion, LocalDateTime reminderUpdatedAt, Long insightId, Long reminderId, Long reminderQuestionId, String insightTitle, String insightMainImage, LocalDateTime lastRemindedAt, LocalDateTime answeredAt, List<String> insightTagList) {
public ReminderQuestionQueryDto(String reminderQuestion, LocalDateTime reminderUpdatedAt, Long insightId, Long reminderId, Long reminderQuestionId, String insightTitle, String insightMainImage, LocalDateTime reminderAt, LocalDateTime answeredAt, List<String> insightTagList) {
this.reminderQuestion = reminderQuestion;
this.reminderUpdatedAt = reminderUpdatedAt;
this.insightId = insightId;
this.reminderId = reminderId;
this.reminderQuestionId = reminderQuestionId;
this.insightTitle = insightTitle;
this.insightMainImage = insightMainImage;
this.lastRemindedAt = lastRemindedAt;
this.reminderAt = reminderAt;
this.answeredAt = answeredAt;
this.insightTagList = insightTagList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ public List<Reminder> findOldestReminders(Long userId) {
.fetch();
}

// 리마인드할 인사이트 조회
public List<Long> findRemindersToNotify(Long userId, LocalDate today) {

// 오늘 날짜와 요일
DayOfWeek todayDayOfWeek = today.getDayOfWeek();
int todayMonthDay = today.getDayOfMonth();
public List<Long> findRemindersToNotifyV2(Long userId, LocalDate date) {
DayOfWeek todayDayOfWeek = date.getDayOfWeek();
int todayMonthDay = date.getDayOfMonth();

return queryFactory
.select(reminder.reminderId)
Expand All @@ -100,29 +97,29 @@ public List<Long> findRemindersToNotify(Long userId, LocalDate today) {
.join(reminder.insight, insight)
.where(reminder.isEnable.isTrue()
.and(insight.folder.user.userId.eq(userId))
.and(insight.createdAt.before(date.atStartOfDay())) // 인사이트 추가 날짜 필터링
.and(
reminderDate.remindType.eq(RemindType.DEFAULT)
.and(
reminder.lastRemindedAt.after(LocalDate.now().minusDays(1).atStartOfDay())
.or(reminder.lastRemindedAt.after(LocalDate.now().minusWeeks(1).atStartOfDay()))
.or(reminder.lastRemindedAt.after(LocalDate.now().minusMonths(1).atStartOfDay()))
reminder.lastRemindedAt.eq(date.minusDays(1).atStartOfDay())
.or(reminder.lastRemindedAt.eq(date.minusWeeks(1).atStartOfDay()))
.or(reminder.lastRemindedAt.eq(date.minusMonths(1).atStartOfDay()))
)
.or(
reminderDate.remindType.eq(RemindType.WEEK)
.and(reminderDate.remindDays.contains(todayDayOfWeek.getValue()))
.and(insight.folder.user.userId.eq(userId))
.and(reminder.lastRemindedAt.before(date.atStartOfDay()))
)
.or(
reminderDate.remindType.eq(RemindType.MONTH)
.and(reminderDate.remindDays.contains(todayMonthDay))
.and(insight.folder.user.userId.eq(userId))
.and(reminder.lastRemindedAt.before(date.atStartOfDay()))
)
)
).fetch();

}

public List<ReminderInsightQueryDto> findReminderInsights(List<Long> reminderIds){
public List<ReminderInsightQueryDto> findReminderInsights(List<Long> reminderIds, LocalDate reqDate){
if(reminderIds.isEmpty()){
return Collections.emptyList();
}
Expand All @@ -147,7 +144,7 @@ public List<ReminderInsightQueryDto> findReminderInsights(List<Long> reminderIds
dto.setInsightTagList(tags);
dto.setTodayRead(Optional.ofNullable(dto.getLastRemindedAt())
.map(LocalDateTime::toLocalDate)
.map(date -> date.isEqual(LocalDate.now()))
.map(date -> date.isEqual(reqDate))
.orElse(false));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public ReminderAnswerResDto answerReminderQuestion(Long userId, ReminderAnswerRe
public ReminderCalenderResDto getReminderCalender(Long userId, ReminderCalenderReqDto reminderCalenderReqDto){
log.info("[ReminderService] getReminderCalender userId: {}", userId);
//remind 할 remind id 조회
List<Long> reminderIds = customReminderRepository.findRemindersToNotify(userId, reminderCalenderReqDto.getRequestDate());
List<Long> reminderIds = customReminderRepository.findRemindersToNotifyV2(userId, reminderCalenderReqDto.getRequestDate());
//reminde id로 Insight 조회
List<ReminderInsightQueryDto> reminderInsightQueryDtos = customReminderRepository.findReminderInsights(reminderIds);
List<ReminderInsightQueryDto> reminderInsightQueryDtos = customReminderRepository.findReminderInsights(reminderIds, reminderCalenderReqDto.getRequestDate());

// ReminderCalenderResDto로 변환
return ReminderCalenderResDto.builder()
Expand Down

0 comments on commit 29de77d

Please sign in to comment.