From 2d15418d9a763b444cb821e7c4922e586ba56a54 Mon Sep 17 00:00:00 2001 From: Sadturtleman Date: Tue, 25 Aug 2026 16:16:30 +0900 Subject: [PATCH] =?UTF-8?q?fix(mindrecord):=20=EC=9D=BC=EA=B8=B0=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=8D=B8=EB=84=A4=EC=9D=BC=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B8=EB=AC=B8=20=EC=B2=AB=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=BD=91=EB=8A=94=EB=8B=A4=20(#1024)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버 계약에 imageUrl 이 없다 — 생성 요청에 실어 보내도 버려지고 목록 응답에도 키가 없어 항상 null 이다. 그래서 일기 카드의 썸네일 자리가 영영 비어 있었다. 데일리질문이 #549 에서 택한 방식과 같은 규칙을 쓴다: 표시 단계에서 본문 HTML 의 첫 img 를 뽑는다. 계약이 넓어지면 서버 값이 우선하도록 `imageUrl ?: 본문` 순서로 둔다. 생성 요청 DTO·payload 의 imageUrl 도 함께 걷었다 (수정 요청 쪽은 #1007 소관). Co-Authored-By: Claude Opus 5 (1M context) --- .../feature/mindrecord/data/dto/DiaryDto.kt | 4 +-- .../mindrecord/data/mapper/DiaryMapper.kt | 1 - .../data/dto/MindRecordDtoContractTest.kt | 1 - .../mindrecord/domain/model/DiaryModels.kt | 5 ++- .../presentation/mapper/MindRecordUiMapper.kt | 5 ++- .../viewmodel/DiaryWriteViewModel.kt | 1 - .../mapper/MindRecordUiMapperTest.kt | 32 +++++++++++++++++++ 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/dto/DiaryDto.kt b/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/dto/DiaryDto.kt index 5826c340d8..10268ed286 100644 --- a/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/dto/DiaryDto.kt +++ b/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/dto/DiaryDto.kt @@ -25,8 +25,8 @@ data class DiaryCreateRequestDto( @SerialName("content") val content: String, @SerialName("isDraft") val isDraft: Boolean, @SerialName("todayMood") val todayMood: TodayMoodDto, - // 응답 계약에 없는 필드 — 타입만 nullable 로 두고 기본값은 두지 않는다 (#789). - @SerialName("imageUrl") val imageUrl: String?, + // imageUrl 은 계약에 없어 걷었다 — 보내도 서버가 버리고 응답에도 키가 없다. 목록 + // 썸네일은 본문 HTML 의 첫 img 에서 뽑는다 (#1024, 데일리질문 #549 와 같은 규칙). // 생성 API 에서 `null` 과 빈 목록은 모두 "수신자 없음" 으로 정규화되고, 작성 UI 는 항상 // 목록을 갖고 있다. 빈 목록을 그대로 보내면 되므로 nullable 로 낮추지 않는다 (#789). @SerialName("receiverIds") val receiverIds: List, diff --git a/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/mapper/DiaryMapper.kt b/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/mapper/DiaryMapper.kt index 46e89315dd..76cf73f1ed 100644 --- a/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/mapper/DiaryMapper.kt +++ b/feature/mindrecord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/mapper/DiaryMapper.kt @@ -50,7 +50,6 @@ fun DiaryCreatePayload.toRequest(): DiaryCreateRequestDto = content = content, isDraft = isDraft, todayMood = todayMood.toDto(), - imageUrl = imageUrl, receiverIds = receiverIds, ) diff --git a/feature/mindrecord/data/src/test/java/com/afternote/feature/mindrecord/data/dto/MindRecordDtoContractTest.kt b/feature/mindrecord/data/src/test/java/com/afternote/feature/mindrecord/data/dto/MindRecordDtoContractTest.kt index 7320abda62..de8cde2b99 100644 --- a/feature/mindrecord/data/src/test/java/com/afternote/feature/mindrecord/data/dto/MindRecordDtoContractTest.kt +++ b/feature/mindrecord/data/src/test/java/com/afternote/feature/mindrecord/data/dto/MindRecordDtoContractTest.kt @@ -122,7 +122,6 @@ class MindRecordDtoContractTest { content = "c", isDraft = false, todayMood = TodayMoodDto.SOSO, - imageUrl = null, receiverIds = emptyList(), ), ) diff --git a/feature/mindrecord/domain/src/main/kotlin/com/afternote/feature/mindrecord/domain/model/DiaryModels.kt b/feature/mindrecord/domain/src/main/kotlin/com/afternote/feature/mindrecord/domain/model/DiaryModels.kt index 9ac8f68e14..b6c38041c1 100644 --- a/feature/mindrecord/domain/src/main/kotlin/com/afternote/feature/mindrecord/domain/model/DiaryModels.kt +++ b/feature/mindrecord/domain/src/main/kotlin/com/afternote/feature/mindrecord/domain/model/DiaryModels.kt @@ -15,6 +15,10 @@ data class Diary( val createdAt: String, /** 사용자가 직접 고른 오늘의 기분. 저장 컬럼이 필수라 응답에도 항상 있다 (#789). */ val todayMood: TodayMood, + /** + * 목록 카드 썸네일. **서버 응답에 이 키가 없어 항상 null 이다** — 표시 단계에서 본문 + * HTML 의 첫 img 로 채운다 (#1024). 계약이 넓어지면 그때 서버 값이 우선한다. + */ val imageUrl: String? = null, val isDraft: Boolean = false, ) @@ -30,7 +34,6 @@ data class DiaryCreatePayload( val content: String, val isDraft: Boolean, val todayMood: TodayMood, - val imageUrl: String? = null, /** 이 일기를 전달받을 수신자 ID 목록. 미선택 시 빈 목록 — 서버가 "수신자 없음" 으로 본다. */ val receiverIds: List, ) diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapper.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapper.kt index 7be02e373d..a4412f456b 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapper.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapper.kt @@ -62,7 +62,10 @@ fun Diary.toUi(): DailyDiary? { date = resolvedDate, content = content, emotion = todayMood.toEmoji(), - imageUrl = imageUrl, + // 서버 계약에 `imageUrl` 이 없다 — 요청에 실어 보내도 버려지고 응답에도 키가 없어 + // 항상 null 이다. 데일리질문과 같은 규칙으로 본문 HTML 의 첫 img 에서 뽑는다 + // (#1024 · #549). DTO 가 값을 주는 날이 오면 그쪽을 우선한다. + imageUrl = imageUrl ?: content.firstHtmlImageSrcOrNull(), ) } diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/viewmodel/DiaryWriteViewModel.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/viewmodel/DiaryWriteViewModel.kt index f295e34c58..c58917d6e7 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/viewmodel/DiaryWriteViewModel.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/viewmodel/DiaryWriteViewModel.kt @@ -157,7 +157,6 @@ class DiaryWriteViewModel content = state.content.toWireContent(uploadedImageUrls), isDraft = isDraft, todayMood = mood, - imageUrl = state.imageUrl, receiverIds = state.selectedReceiverIds.toList(), ), ) diff --git a/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapperTest.kt b/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapperTest.kt index a85fb699d7..7e7d7d5267 100644 --- a/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapperTest.kt +++ b/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/mapper/MindRecordUiMapperTest.kt @@ -62,6 +62,38 @@ class MindRecordUiMapperTest { todayMood = TodayMood.HAPPY, ) + @Test + fun `일기 썸네일도 본문 HTML 의 첫 이미지에서 나온다`() { + // 서버 계약에 imageUrl 이 없다 — 요청에 실어 보내도 버려지고 응답에도 키가 없어 + // 항상 null 이다. 그대로 두면 일기 카드 썸네일 자리가 영영 빈다 (#1024). + val diary = + Diary( + diaryId = 1L, + title = "제목", + content = "

본문

", + date = "2026-08-25", + createdAt = "2026.08.25 화", + todayMood = TodayMood.HAPPY, + ) + + assertEquals("https://cdn.example/mindrecords/permanent/13/a.png", diary.toUi()?.imageUrl) + } + + @Test + fun `본문에 이미지가 없는 일기는 썸네일 없이 텍스트 카드로 간다`() { + val diary = + Diary( + diaryId = 2L, + title = "제목", + content = "

글만 있는 본문

", + date = "2026-08-25", + createdAt = "2026.08.25 화", + todayMood = TodayMood.SOSO, + ) + + assertNull(diary.toUi()?.imageUrl) + } + @Test fun `데일리질문 썸네일은 본문 HTML 의 첫 이미지에서 나온다`() { // 서버 계약에 `imageUrl` 이 없어 응답 필드로는 영영 null 이다 — 본문에서 뽑지 않으면