Skip to content
Open
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
1 change: 1 addition & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
compileSdkMinor = 0
}

kotlin {
Expand Down
6 changes: 6 additions & 0 deletions domain/src/main/java/com/itlab/domain/model/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ data class DataSource(

@Serializable
sealed class ContentItem {
abstract val id: String

@Serializable
data class Text(
override val id: String = UUID.randomUUID().toString(),
val text: String,
val format: TextFormat = TextFormat.PLAIN,
) : ContentItem()

@Serializable
data class Image(
override val id: String = UUID.randomUUID().toString(),
val source: DataSource,
val mimeType: String,
val width: Int? = null,
Expand All @@ -43,6 +47,7 @@ sealed class ContentItem {

@Serializable
data class File(
override val id: String = UUID.randomUUID().toString(),
val source: DataSource,
val mimeType: String,
val name: String,
Expand All @@ -51,6 +56,7 @@ sealed class ContentItem {

@Serializable
data class Link(
override val id: String = UUID.randomUUID().toString(),
val url: String,
val title: String? = null,
) : ContentItem()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.aiusecase
package com.itlab.domain.usecase.aiusecase

import com.itlab.domain.ai.NoteAiService
import com.itlab.domain.model.ContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.aiusecase
package com.itlab.domain.usecase.aiusecase

import com.itlab.domain.ai.NoteAiService
import com.itlab.domain.model.ContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.itlab.domain.usecase.contentusecase

import com.itlab.domain.model.ContentItem
import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class AddContentItemUseCase(
private val notesRepository: NotesRepository,
) {
suspend operator fun invoke(
noteId: String,
item: ContentItem,
) {
require(item.id.isNotBlank()) {
"ContentItem id must be created before adding to note"
}

val note =
notesRepository.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

val updated =
note.copy(
contentItems = note.contentItems + item,
updatedAt = Clock.System.now(),
)

notesRepository.updateNote(updated)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.itlab.domain.usecase.contentusecase

import com.itlab.domain.model.ContentItem
import java.util.UUID

class CreateContentItemUseCase {
operator fun invoke(item: ContentItem): ContentItem =
when (item) {
is ContentItem.Text -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.Image -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.File -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.Link -> item.copy(id = UUID.randomUUID().toString())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.itlab.domain.usecase.contentusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class DeleteContentItemUseCase(
private val notesRepository: NotesRepository,
) {
suspend operator fun invoke(
noteId: String,
itemId: String,
) {
val note =
notesRepository.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

val updated =
note.copy(
contentItems = note.contentItems.filterNot { it.id == itemId },
updatedAt = Clock.System.now(),
)
notesRepository.updateNote(updated)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.itlab.domain.usecase.contentusecase

import com.itlab.domain.model.ContentItem
import com.itlab.domain.repository.NotesRepository

class GetContentItemUseCase(
private val notesRepository: NotesRepository,
) {
suspend operator fun invoke(
noteId: String,
itemId: String,
): ContentItem? {
val note =
notesRepository.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

return note.contentItems.find { it.id == itemId }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.folderusecase

import com.itlab.domain.model.NoteFolder
import com.itlab.domain.repository.NoteFolderRepository
import kotlinx.datetime.Clock
import java.util.UUID

class CreateFolderUseCase(
private val repo: NoteFolderRepository,
) {
suspend operator fun invoke(folder: NoteFolder): String {
// discuss
val folder = folder.copy(createdAt = Clock.System.now())
val now = Clock.System.now()
val folder =
folder.copy(
id = UUID.randomUUID().toString(),
createdAt = now,
updatedAt = now,
)
return repo.createFolder(folder)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.folderusecase

import com.itlab.domain.repository.NoteFolderRepository

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.folderusecase

import com.itlab.domain.model.NoteFolder
import com.itlab.domain.repository.NoteFolderRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.folderusecase

import com.itlab.domain.model.NoteFolder
import com.itlab.domain.repository.NoteFolderRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.folderusecase

import com.itlab.domain.model.NoteFolder
import com.itlab.domain.repository.NoteFolderRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class AddTagUseCase(
private val repo: NotesRepository,
) {
suspend operator fun invoke(
noteId: String,
tagToAdd: String,
) {
val note =
repo.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

val updated =
note.copy(
tags = note.tags + tagToAdd,
updatedAt = Clock.System.now(),
)

repo.updateNote(updated)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.itlab.domain.aiusecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class ApplySummaryUseCase(
private val repo: NotesRepository,
Expand All @@ -17,7 +18,7 @@ class ApplySummaryUseCase(
note.copy(
summary = newSummary,
updatedAt =
kotlinx.datetime.Clock.System
Clock.System
.now(),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.itlab.domain.aiusecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class ApplyTagsUseCase(
private val repo: NotesRepository,
Expand All @@ -17,7 +18,7 @@ class ApplyTagsUseCase(
note.copy(
tags = newTags,
updatedAt =
kotlinx.datetime.Clock.System
Clock.System
.now(),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.Note
import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock
import java.util.UUID

class CreateNoteUseCase(
private val repo: NotesRepository,
) {
suspend operator fun invoke(note: Note): String {
val note = note.copy(createdAt = Clock.System.now())
val now = Clock.System.now()

val note =
note.copy(
id = UUID.randomUUID().toString(),
createdAt = now,
updatedAt = now,
)
return repo.createNote(note)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock

class DeleteTagUseCase(
private val repo: NotesRepository,
) {
suspend operator fun invoke(
noteId: String,
tagToDel: String,
) {
val note =
repo.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

val updated =
note.copy(
tags = note.tags - tagToDel,
updatedAt = Clock.System.now(),
)

repo.updateNote(updated)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.ContentItem
import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock
import java.util.UUID

class DuplicateNoteUseCase(
private val repo: NotesRepository,
) {
suspend operator fun invoke(noteId: String): String {
val note =
repo.getNoteById(noteId)
?: throw IllegalArgumentException("Note not found: $noteId")

val now = Clock.System.now()
val duplicated =
note.copy(
id = UUID.randomUUID().toString(),
title = if (note.title.isBlank()) "Copy" else "${note.title} Copy",
createdAt = now,
updatedAt = now,
contentItems =
note.contentItems.map { item ->
when (item) {
is ContentItem.Text -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.Image -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.File -> item.copy(id = UUID.randomUUID().toString())
is ContentItem.Link -> item.copy(id = UUID.randomUUID().toString())
}
},
)
return repo.createNote(duplicated)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.Note
import com.itlab.domain.repository.NotesRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class GetAllFavoritesUseCase(
private val repo: NotesRepository,
) {
operator fun invoke(): Flow<List<Note>> =
repo.observeNotes().map { notes ->
notes.filter { it.isFavorite }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.Note
import com.itlab.domain.repository.NotesRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.repository.NotesRepository
import kotlinx.datetime.Clock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.Note
import com.itlab.domain.repository.NotesRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itlab.domain.usecase
package com.itlab.domain.usecase.noteusecase

import com.itlab.domain.model.Note
import com.itlab.domain.repository.NotesRepository
Expand Down
Loading
Loading