Skip to content

Commit e243c19

Browse files
author
kusuri12
committed
fix(diary): fix query about get diaries
1 parent 8f399f9 commit e243c19

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

src/main/kotlin/modeep/hear/domain/diary/port/out/query/QueryDiaryPort.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface QueryDiaryPort {
1515
userId: UUID,
1616
yearMonth: YearMonth,
1717
hasPhoto: Boolean,
18-
imageType: DiarySourceType,
18+
imageType: DiarySourceType?,
1919
tag: String? = null,
2020
pageable: Pageable
2121
): List<UUID>

src/main/kotlin/modeep/hear/infrastructure/adapter/in/diary/dto/request/QueryDiariesRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import org.springframework.format.annotation.DateTimeFormat
55
import java.time.YearMonth
66

77
data class QueryDiariesRequest(
8-
val imageType: DiarySourceType = DiarySourceType.MANUAL,
9-
val hasPhoto: Boolean = false,
8+
val imageType: DiarySourceType? = null,
9+
val hasPhoto: Boolean = true,
1010
@field:DateTimeFormat(pattern = "yyyy-MM")
1111
val yearMonth: YearMonth? = null,
1212
val limit: Int = 32,

src/main/kotlin/modeep/hear/infrastructure/adapter/out/diary/DiaryCompositeAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DiaryCompositeAdapter(
3030
userId: UUID,
3131
yearMonth: YearMonth,
3232
hasPhoto: Boolean,
33-
imageType: DiarySourceType,
33+
imageType: DiarySourceType?,
3434
tag: String?,
3535
pageable: Pageable
3636
): List<UUID> =

src/main/kotlin/modeep/hear/infrastructure/adapter/out/diary/persistence/DiaryPersistenceAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class DiaryPersistenceAdapter(
2929
userId: UUID,
3030
yearMonth: YearMonth,
3131
hasPhoto: Boolean,
32-
imageType: DiarySourceType,
32+
imageType: DiarySourceType?,
3333
tag: String?,
3434
pageable: Pageable
3535
): List<UUID> {
3636
val start = yearMonth.atDay(1).atStartOfDay()
3737
val end = yearMonth.plusMonths(1).atDay(1).atStartOfDay()
3838

39-
return repo.findIdsByFilters(userId, start, end, imageType.name, hasPhoto, tag, pageable)
39+
return repo.findIdsByFilters(userId, start, end, imageType?.name, hasPhoto, tag, pageable)
4040
}
4141

4242
override fun findAllByIdInWithImages(ids: List<UUID>): List<Diary> {

src/main/kotlin/modeep/hear/infrastructure/adapter/out/diary/persistence/repository/DiaryRepository.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ interface DiaryRepository : JpaRepository<DiaryJpaEntity, UUID> {
2828
SELECT 1 FROM diary_images di
2929
WHERE di.diary_id = d.id
3030
AND di.image_url IS NOT NULL
31-
AND (:imageType IS NULL OR di.source_type = :imageType)
31+
))
32+
AND (:imageType IS NULL OR EXISTS (
33+
SELECT 1 FROM diary_images di
34+
WHERE di.diary_id = d.id
35+
AND di.source_type = :imageType
3236
))
3337
-- '?' 연산자 대신 jsonb_exists 함수 사용
3438
AND (:tag IS NULL OR jsonb_exists(d.tags, :tag))

0 commit comments

Comments
 (0)