Repository navigation
refactor(mindrecord): 주간리포트 날짜 파싱·주간 범위 검증을 data 계층 mapper 로 이동 #961
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a42cf1
refactor(mindrecord): 주간리포트 날짜 파싱을 data 계층 mapper 로 옮긴다
Sadturtleman 7c13af4
fix(mindrecord): 주차 조회 실패 뒤에도 화면 안에서 복구할 수 있게 한다
Sadturtleman 7020e08
Merge branch 'feat/725-emotion-analysis-status' into refactor/547-wee…
OnlyReadOneBook 61de691
Merge branch 'refactor/547-weekly-date-parsing' into fix/723-weekly-r…
OnlyReadOneBook 52c42f5
fix(mindrecord): 주간리포트 상단 카드도 화면이 그리는 목록을 센다
Sadturtleman 59dcd3e
Merge pull request #965 from Afternote/fix/723-weekly-report-recovery
Sadturtleman 7ee1cfc
Merge branch 'develop' into refactor/547-weekly-date-parsing
Sadturtleman f3edadb
Merge develop into refactor/547-weekly-date-parsing
Sadturtleman 0c51d3a
Merge develop into refactor/547-weekly-date-parsing
Sadturtleman 88fe7fe
Merge branch 'develop' into refactor/547-weekly-date-parsing
OnlyReadOneBook c908571
Merge remote-tracking branch 'origin/develop' into refactor/547-weekl…
Sadturtleman f1ef526
Merge remote-tracking branch 'origin/refactor/547-weekly-date-parsing…
Sadturtleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ord/data/src/main/kotlin/com/afternote/feature/mindrecord/data/mapper/ServerDateParser.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.afternote.feature.mindrecord.data.mapper | ||
|
|
||
| import java.time.LocalDate | ||
| import java.time.format.DateTimeFormatter | ||
|
|
||
| /** | ||
| * 서버가 내려주는 날짜 문자열을 [LocalDate] 로 해석한다 (해석 못 하면 null). | ||
| * | ||
| * 응답 포맷 지식을 **DTO→도메인 경계에 둔다.** 종전에는 `WeeklyReportViewModel` 이 | ||
| * "서버가 `yyyy.MM.dd 요일` 또는 ISO 로 내려준다" 는 사실을 알고 직접 파싱했다 — | ||
| * presentation 이 와이어 포맷을 아는 구조라, 도메인 소비자가 늘 때마다 같은 파싱을 | ||
| * 다시 구현해야 했다 (#547). | ||
| * | ||
| * 세 포맷을 모두 허용한다. `ISO_DATE` 만 두면 시각이 붙은 값(`2026-03-21T20:13:42`)에서 | ||
| * 뒤가 남아 파싱이 실패한다. 요일이 붙은 값(`2026.05.22 금`)은 앞 조각만 쓴다. | ||
| */ | ||
| internal fun parseServerDateOrNull(raw: String): LocalDate? { | ||
| val datePart = raw.substringBefore(' ').trim() | ||
| if (datePart.isEmpty()) return null | ||
| for (formatter in SERVER_DATE_FORMATTERS) { | ||
| val parsed = runCatching { LocalDate.parse(datePart, formatter) }.getOrNull() | ||
| if (parsed != null) return parsed | ||
| } | ||
| return null | ||
| } | ||
|
|
||
| private val SERVER_DATE_FORMATTERS: List<DateTimeFormatter> = | ||
| listOf( | ||
| DateTimeFormatter.ofPattern("yyyy.MM.dd"), | ||
| DateTimeFormatter.ISO_DATE, | ||
| DateTimeFormatter.ISO_DATE_TIME, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../src/test/java/com/afternote/feature/mindrecord/data/mapper/WeeklyReportDateMapperTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.afternote.feature.mindrecord.data.mapper | ||
|
|
||
| import com.afternote.feature.mindrecord.data.dto.WeeklyReportDailyQuestionDto | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
| import java.time.LocalDate | ||
|
|
||
| /** | ||
| * 서버 날짜 해석과 실패 정책이 DTO→도메인 경계에 있다는 계약 (#547). | ||
| * | ||
| * 종전에는 이 지식이 `WeeklyReportViewModel` 에 있었고, 실패 처리도 소비처마다 갈렸다 — | ||
| * 집계 경로는 버리고 표시 경로는 `LocalDate.now()` 로 메워 파싱 못 한 기록이 **오늘 | ||
| * 작성한 것처럼** 카드에 앉았다. 이제 한 곳에서 정한다: **해석 못 하면 제외.** | ||
| */ | ||
| class WeeklyReportDateMapperTest { | ||
| private fun dto(date: String) = WeeklyReportDailyQuestionDto(title = "질문", content = "답변", date = date) | ||
|
|
||
| @Test | ||
| fun `요일이 붙은 서버 기본 포맷을 해석한다`() { | ||
| // 실서버가 이 형태로 내려준다 (2026-08-23 실측). | ||
| assertEquals(LocalDate.of(2026, 8, 23), dto("2026.08.23 일").toDomainOrNull()?.date) | ||
| } | ||
|
|
||
| @Test | ||
| fun `ISO 날짜도 해석한다`() { | ||
| assertEquals(LocalDate.of(2026, 3, 21), dto("2026-03-21").toDomainOrNull()?.date) | ||
| } | ||
|
|
||
| @Test | ||
| fun `시각이 붙은 ISO 도 해석한다`() { | ||
| // ISO_DATE 만 두면 뒤가 남아 실패한다 — 세 포맷을 모두 허용하는 이유다. | ||
| assertEquals(LocalDate.of(2026, 3, 25), dto("2026-03-25T20:13:42").toDomainOrNull()?.date) | ||
| } | ||
|
|
||
| @Test | ||
| fun `해석하지 못한 날짜는 오늘로 메우지 않고 제외한다`() { | ||
| // 오늘로 메우면 그 기록이 오늘 작성한 것처럼 HISTORY 카드에 앉아 이상을 감춘다. | ||
| assertNull(dto("알 수 없음").toDomainOrNull()) | ||
| assertNull(dto("").toDomainOrNull()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `제외돼도 나머지 항목은 살아남는다`() { | ||
| // 실패의 폭이 목록 전체가 되면 안 된다. | ||
| val kept = | ||
| listOf(dto("2026.08.23 일"), dto("깨진 값"), dto("2026-08-22")) | ||
| .mapNotNull { it.toDomainOrNull() } | ||
|
|
||
| assertEquals( | ||
| listOf(LocalDate.of(2026, 8, 23), LocalDate.of(2026, 8, 22)), | ||
| kept.map { it.date }, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `제목과 본문은 그대로 통과한다`() { | ||
| val domain = dto("2026.08.23 일").toDomainOrNull() | ||
|
|
||
| assertEquals("질문", domain?.title) | ||
| assertEquals("답변", domain?.content) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[blocking] 파싱을 data 계층으로 올리면서 이 필드가
String→LocalDate가 됐는데,:app의 androidTest 픽스처가 아직 문자열을 넘깁니다. develop 병합으로 androidTest 컴파일 게이트가 들어오면서 CI 에 드러났습니다.세 곳 모두 이미
LocalDate를 손에 들고 있어서.toString()만 떼면 됩니다.이 타입을 좁힌 것 자체는 좋은 변경입니다 — 문자열이었으면 이런 자리가 컴파일러에 안 걸리고 런타임까지 갔을 겁니다. 지금은 그 좁힘의 값을 치르는 자리이니 사용처만 데려가 주세요.