Skip to content

Commit

Permalink
Merge branch 'dev' into release-v2/remove-elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
M-ung committed Nov 24, 2024
2 parents a0aaa37 + 09a54e1 commit 9a74139
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface DiaryRepository extends JpaRepository<Diary, Long>, DiaryRepositoryCustom {
Optional<Diary> findByDiaryDateAndUserIdAndDiaryStatus(LocalDate diaryDate, Long userId, DiaryStatus diaryStatus);
List<Diary> findAllByDiaryDateAndUserIdAndDiaryStatus(LocalDate diaryDate, Long userId, DiaryStatus diaryStatus);
Optional<Diary> findByDiaryIdAndMoodBuddyStatus(Long diaryId, MoodBuddyStatus moodBuddyStatus);
Optional<Diary> findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(Long diaryId, DiaryStatus diaryStatus, MoodBuddyStatus moodBuddyStatus);


@Query(value = "SELECT * FROM diary WHERE user_id = :userId AND DATE_FORMAT(diary_date, '%Y-%m') = :month AND diary_status = :status", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package moodbuddy.moodbuddy.domain.diary.repository.draft;

import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus;
import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface DraftDiaryRepository extends JpaRepository<Diary, Long>, DraftDiaryRepositoryCustom {
Optional<Diary> findByDiaryIdAndMoodBuddyStatus(Long diaryId, MoodBuddyStatus moodBuddyStatus);
Optional<Diary> findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(Long diaryId, DiaryStatus diaryStatus, MoodBuddyStatus moodBuddyStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Page<DiaryResDetailDTO> findAllByUserIdWithPageable(Long userId, Pageable
List<DiaryResDetailDTO> diaryList = diaries.stream().map(d -> {
List<String> diaryImgList = queryFactory.select(diaryImage.diaryImgURL)
.from(diaryImage)
.where(diaryImage.diaryId.eq(d.getDiaryId()))
.where(diaryImage.diaryId.eq(d.getDiaryId()).and(diaryImage.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE)))
.fetch();

return DiaryResDetailDTO.builder()
Expand Down Expand Up @@ -84,13 +84,17 @@ public Page<DiaryResDetailDTO> findAllByUserIdWithPageable(Long userId, Pageable
@Override
public Page<DiaryResDetailDTO> findAllByEmotionWithPageable(DiaryEmotion emotion, Long userId, Pageable pageable) {
List<Diary> diaries = queryFactory.selectFrom(diary)
.where(diaryEmotionEq(emotion).and(diary.userId.eq(userId).and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))))
.where(diaryEmotionEq(emotion).and(diary.userId.eq(userId)
.and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE)
.and(diary.diaryStatus.eq(DiaryStatus.PUBLISHED))
)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

Map<Long, List<String>> diaryImages = queryFactory.selectFrom(diaryImage)
.where(diaryImage.diaryId.in(diaries.stream().map(Diary::getDiaryId).collect(Collectors.toList())))
.where(diaryImage.diaryId.in(diaries.stream().map(Diary::getDiaryId).collect(Collectors.toList()))
.and(diaryImage.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE)))
.fetch()
.stream()
.collect(Collectors.groupingBy(
Expand Down Expand Up @@ -156,7 +160,9 @@ public Page<DiaryResDetailDTO> findAllByFilterWithPageable(DiaryReqFilterDTO fil
}

List<Diary> results = queryFactory.selectFrom(diary)
.where(builder)
.where(builder
.and(diary.diaryStatus.eq(DiaryStatus.PUBLISHED)
.and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void deleteTodayDraftDiaries(LocalDate diaryDate, Long userId) {

@Override
public Diary getDiaryById(Long diaryId) {
return diaryRepository.findByDiaryIdAndMoodBuddyStatus(diaryId, MoodBuddyStatus.ACTIVE)
return diaryRepository.findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(diaryId, DiaryStatus.PUBLISHED, MoodBuddyStatus.ACTIVE)
.orElseThrow(() -> new DiaryNotFoundException(NOT_FOUND_DIARY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DiaryReqDraftSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqSaveDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindAllDTO;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void draftSelectDelete(DiaryReqDraftSelectDeleteDTO requestDTO, Long user
}

private Diary getDraftDiaryById(Long diaryId) {
return draftDiaryRepository.findByDiaryIdAndMoodBuddyStatus(diaryId, MoodBuddyStatus.ACTIVE)
return draftDiaryRepository.findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(diaryId, DiaryStatus.DRAFT, MoodBuddyStatus.ACTIVE)
.orElseThrow(() -> new DiaryNotFoundException(NOT_FOUND_DRAFT_DIARY));
}
}

0 comments on commit 9a74139

Please sign in to comment.