From b2794f1518fa7615435d765b337682622e844b4c Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:35:40 +0900 Subject: [PATCH 1/6] =?UTF-8?q?docs(README):=20=EB=A9=94=EB=AA=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c99c1d9..ca5be4a 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,14 @@ --- -### ☑️ 메모 수정 기능 +### 🏁 메모 수정 기능 - 저장된 메모의 content를 수정할 수 있어야 한다. ### ⚠️ 메모 수정 기능 예외 상황 +- 수정할 메모가 없다면 아무 수행도 해선 안된다. + --- ### ☑️ 메모 추출 기능 From d1230c5d0e2718210f08034f4b9580ae68e50058 Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:36:01 +0900 Subject: [PATCH 2/6] =?UTF-8?q?test(MemoServiceTest):=20=EB=A9=94=EB=AA=A8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memo/service/MemoServiceTest.kt | 97 +++++++++++++++++-- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoServiceTest.kt b/src/test/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoServiceTest.kt index de59ddf..5c776cb 100644 --- a/src/test/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoServiceTest.kt +++ b/src/test/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoServiceTest.kt @@ -191,8 +191,8 @@ class MemoServiceTest : BasePlatformTestCase() { // given val memo1 = Memo( id = System.currentTimeMillis(), - createdAt = java.time.LocalDateTime.now(), - updatedAt = java.time.LocalDateTime.now(), + createdAt = LocalDateTime.now(), + updatedAt = LocalDateTime.now(), content = "메모1", commitHash = null, filePath = "/path/to/file1", @@ -205,8 +205,8 @@ class MemoServiceTest : BasePlatformTestCase() { val memo2 = Memo( id = System.currentTimeMillis() + 1, - createdAt = java.time.LocalDateTime.now(), - updatedAt = java.time.LocalDateTime.now(), + createdAt = LocalDateTime.now(), + updatedAt = LocalDateTime.now(), content = "메모2", commitHash = null, filePath = "/path/to/file2", @@ -243,7 +243,7 @@ class MemoServiceTest : BasePlatformTestCase() { // ========= 메모 삭제 기능 ========= fun `test 메모 삭제 기능 - 정상 삭제`() { - val now = java.time.LocalDateTime.now() + val now = LocalDateTime.now() val memo1 = Memo( id = 1L, createdAt = now, @@ -310,5 +310,90 @@ class MemoServiceTest : BasePlatformTestCase() { } assertTrue(result.isSuccess, "예외가 발생하면 안 됩니다.") } -} + // ========= 메모 수정 기능 ========= + fun `test 메모 수정 성공`() { + // given + val now = LocalDateTime.now() + val original = Memo( + id = 1L, + createdAt = now, + updatedAt = now, + content = "old", + commitHash = null, + filePath = "/path/file", + selectedCodeSnippet = "snippet", + selectionStart = 0, + selectionEnd = 5, + visibleStart = 1, + visibleEnd = 3 + ) + whenever(memoRepository.findMemoById(1L)).thenReturn(original) + + val updated = original.update(content = "new") + whenever(memoRepository.save(updated)).thenAnswer {} + + // when + MemoService(project).updateMemo(1L, "new") + + // then + org.mockito.kotlin.verify(memoRepository).removeMemoById(1L) + org.mockito.kotlin.verify(memoRepository).save(org.mockito.kotlin.check { + assertEquals("new", it.content) + }) + } + + fun `test 조회 실패 시 아무 것도 하지 않음`() { + // given + whenever(memoRepository.findMemoById(999L)).thenReturn(null) + + // when + MemoService(project).updateMemo(999L, "new") + + // then + org.mockito.kotlin.verify(memoRepository, org.mockito.kotlin.never()) + .removeMemoById(org.mockito.kotlin.any()) + org.mockito.kotlin.verify(memoRepository, org.mockito.kotlin.never()) + .save(org.mockito.kotlin.any()) + } + + fun `test udpate 적용된 필드 검증`() { + // given + val createdAt = LocalDateTime.now().minusDays(1) + val original = Memo( + id = 1L, + createdAt = createdAt, + updatedAt = createdAt, + content = "before", + commitHash = "abc", + filePath = "/path", + selectedCodeSnippet = "code", + selectionStart = 10, + selectionEnd = 20, + visibleStart = 5, + visibleEnd = 15 + ) + whenever(memoRepository.findMemoById(1L)).thenReturn(original) + + val service = MemoService(project) + + // when + service.updateMemo(1L, "after") + + // then + org.mockito.kotlin.verify(memoRepository).save(org.mockito.kotlin.check { updated -> + assertEquals(1L, updated.id) + assertEquals("after", updated.content) + + assertEquals(original.createdAt, updated.createdAt) + assertEquals(original.commitHash, updated.commitHash) + assertEquals(original.filePath, updated.filePath) + assertEquals(original.selectedCodeSnippet, updated.selectedCodeSnippet) + assertEquals(original.selectionStart, updated.selectionStart) + assertEquals(original.selectionEnd, updated.selectionEnd) + assertEquals(original.visibleStart, updated.visibleStart) + assertEquals(original.visibleEnd, updated.visibleEnd) + }) + } + +} From 37a80c1978fa6a061d045f5721342e94c40de713 Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:39:35 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat(MemoRepository):=20findMemoById=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yeoli/devlog/domain/memo/repository/MemoRepository.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/repository/MemoRepository.kt b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/repository/MemoRepository.kt index 2d6d123..8b49052 100644 --- a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/repository/MemoRepository.kt +++ b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/repository/MemoRepository.kt @@ -24,11 +24,16 @@ class MemoRepository : PersistentStateComponent { state.memos.add(memo.toState()) } + fun findMemoById(memoId: Long): Memo? { + val memoState = state.memos.find { it.id == memoId } + return memoState?.toDomain() + } + fun getAll(): List { return state.memos.map { it.toDomain() } } - private fun removeMemoById(memoId: Long) { + fun removeMemoById(memoId: Long) { state.memos.removeIf { it.id == memoId } } @@ -37,4 +42,5 @@ class MemoRepository : PersistentStateComponent { removeMemoById(memoId) } } + } From 8d931b27ec6d38cb0113472307eee33a5ce19b1f Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:40:51 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat(Memo):=20update=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yeoli/devlog/domain/memo/domain/Memo.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/domain/Memo.kt b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/domain/Memo.kt index e820a7f..1bb1b4f 100644 --- a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/domain/Memo.kt +++ b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/domain/Memo.kt @@ -75,4 +75,22 @@ class Memo( visibleStart = this.visibleStart, visibleEnd = this.visibleEnd ) + + fun update( + content: String = this.content + ): Memo { + return Memo( + id = this.id, + createdAt = this.createdAt, + updatedAt = LocalDateTime.now(), + content = content, + commitHash = this.commitHash, + filePath = this.filePath, + selectedCodeSnippet = this.selectedCodeSnippet, + selectionStart = this.selectionStart, + selectionEnd = this.selectionEnd, + visibleStart = this.visibleStart, + visibleEnd = this.visibleEnd + ) + } } From 3fd78ad943d8bfec82861031206d59dfa99d324d Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:41:22 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat(MemoService):=20=EB=A9=94=EB=AA=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yeoli/devlog/domain/memo/service/MemoService.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoService.kt b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoService.kt index 50ab391..0874bd2 100644 --- a/src/main/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoService.kt +++ b/src/main/kotlin/com/github/yeoli/devlog/domain/memo/service/MemoService.kt @@ -108,4 +108,15 @@ class MemoService(private val project: Project) { logger.warn("[removeMemos] 메모 삭제 중 알 수 없는 에러가 발생했습니다. ${e.message}", e) } } + + fun updateMemo(memoId: Long, newContent: String) { + try { + val memo: Memo = memoRepository.findMemoById(memoId) ?: return + val updated = memo.update(newContent) + memoRepository.removeMemoById(memoId) + memoRepository.save(updated) + } catch (e: Exception) { + logger.warn("[updateMemo] 메모 수정 중 알 수 없는 에러가 발생했습니다. ${e.message}", e) + } + } } \ No newline at end of file From c410995b88f8cb955cb2c507e9ceadf2180ba3be Mon Sep 17 00:00:00 2001 From: yeo-li Date: Sat, 22 Nov 2025 20:42:20 +0900 Subject: [PATCH 6/6] =?UTF-8?q?docs(README):=20=EB=A9=94=EB=AA=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca5be4a..8e75a9a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ --- -### 🏁 메모 수정 기능 +### ✅ 메모 수정 기능 - 저장된 메모의 content를 수정할 수 있어야 한다.