Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

---

### 🏁 메모 조회 기능
### 메모 조회 기능

- 메모의 id를 이용해서 데이터를 조회할 수 있어야 한다.
- 전체 메모를 날짜순으로 조회할 수 있어야 한다.

### ⚠️ 메모 조회 기능 고려 사항
Expand All @@ -41,13 +40,15 @@

---

### ☑️ 메모 삭제 기능
### 메모 삭제 기능

- 저장된 메모를 삭제할 수 있어야 한다.
- 메모를 한 번에 여러개 삭제할 수 있어야 한다.

### ⚠️ 메모 삭제 기능 예외 상황

- 삭제할 메모가 없으면 아무 수행도 해선 안된다.

---

### ☑️ 메모 수정 기능
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ class MemoRepository : PersistentStateComponent<MemoStorageState> {
fun getAll(): List<Memo> {
return state.memos.map { it.toDomain() }
}

private fun removeMemoById(memoId: Long) {
state.memos.removeIf { it.id == memoId }
}

fun removeMemosById(memoIds: List<Long>) {
for (memoId in memoIds) {
removeMemoById(memoId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,15 @@ class MemoService(private val project: Project) {

return mutableListOf()
}

fun removeMemos(memos: List<Memo>) {
if (memos.isEmpty()) return

try {
val ids: List<Long> = memos.map { it.id }
memoRepository.removeMemosById(ids)
} catch (e: Exception) {
logger.warn("[removeMemos] 메모 삭제 중 알 수 없는 에러가 발생했습니다. ${e.message}", e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.intellij.util.Function
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.awt.Point
import java.time.LocalDateTime
import kotlin.test.assertTrue

class MemoServiceTest : BasePlatformTestCase() {
Expand Down Expand Up @@ -240,5 +241,74 @@ class MemoServiceTest : BasePlatformTestCase() {
assertTrue(result.isEmpty(), "예외 발생 시 빈 리스트를 반환해야 합니다.")
}

// ========= 메모 삭제 기능 =========
fun `test 메모 삭제 기능 - 정상 삭제`() {
val now = java.time.LocalDateTime.now()
val memo1 = Memo(
id = 1L,
createdAt = now,
updatedAt = now,
content = "a",
commitHash = null,
filePath = "/path/to/file1",
selectedCodeSnippet = null,
selectionStart = null,
selectionEnd = null,
visibleStart = null,
visibleEnd = null
)
val memo2 = Memo(
id = 2L,
createdAt = now,
updatedAt = now,
content = "b",
commitHash = null,
filePath = "/path/to/file2",
selectedCodeSnippet = null,
selectionStart = null,
selectionEnd = null,
visibleStart = null,
visibleEnd = null
)
val memos = listOf(memo1, memo2)

MemoService(project).removeMemos(memos)

org.mockito.kotlin.verify(memoRepository)
.removeMemosById(listOf(1L, 2L))
}

fun `test 메모 삭제 기능 - 빈 리스트는 Repository를 호출하지 않음`() {
MemoService(project).removeMemos(emptyList())

org.mockito.kotlin.verify(memoRepository, org.mockito.kotlin.never())
.removeMemosById(org.mockito.kotlin.any())
}

fun `test 메모 삭제 기능 - Repository 예외 발생해도 서비스는 throw 하지 않음`() {
val now = LocalDateTime.now()
val memo = Memo(
id = 10L,
createdAt = now,
updatedAt = now,
content = "x",
commitHash = null,
filePath = "/path/to/file",
selectedCodeSnippet = null,
selectionStart = null,
selectionEnd = null,
visibleStart = null,
visibleEnd = null
)

whenever(
memoRepository.removeMemosById(listOf(10L))
).thenThrow(RuntimeException("DB error"))

val result = runCatching {
MemoService(project).removeMemos(listOf(memo))
}
assertTrue(result.isSuccess, "예외가 발생하면 안 됩니다.")
}
}

Loading