From 28d4a300204bc1cebd7b1014495bc6c0019cc375 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Sat, 13 Apr 2024 17:38:27 +0900 Subject: [PATCH] [feat] #4 core domain --- core/domain/.gitignore | 1 + core/domain/build.gradle.kts | 9 ++++++ .../org/sopt/domain/repo/SoptRepository.kt | 16 ++++++++++ .../org/sopt/domain/usecase/GetSoptUseCase.kt | 31 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 core/domain/.gitignore create mode 100644 core/domain/build.gradle.kts create mode 100644 core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt create mode 100644 core/domain/src/main/java/org/sopt/domain/usecase/GetSoptUseCase.kt diff --git a/core/domain/.gitignore b/core/domain/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/core/domain/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/domain/build.gradle.kts b/core/domain/build.gradle.kts new file mode 100644 index 0000000..5852895 --- /dev/null +++ b/core/domain/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + alias(libs.plugins.sopt.java.library) +} + +dependencies { + implementation(projects.core.model) + implementation(libs.kotlinx.coroutines.core) + implementation(libs.hilt.core) +} \ No newline at end of file diff --git a/core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt b/core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt new file mode 100644 index 0000000..5aa7352 --- /dev/null +++ b/core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt @@ -0,0 +1,16 @@ +package org.sopt.domain.repo + +import kotlinx.coroutines.flow.Flow +import org.sopt.model.Friend + +interface SoptRepository { + fun getAll(): Flow> + + fun getContainInput(input: String): Flow> + + suspend fun addFriend(friend: Friend) + + suspend fun deleteFriendById(id: Int) + + suspend fun deleteAll() +} \ No newline at end of file diff --git a/core/domain/src/main/java/org/sopt/domain/usecase/GetSoptUseCase.kt b/core/domain/src/main/java/org/sopt/domain/usecase/GetSoptUseCase.kt new file mode 100644 index 0000000..f587520 --- /dev/null +++ b/core/domain/src/main/java/org/sopt/domain/usecase/GetSoptUseCase.kt @@ -0,0 +1,31 @@ +package org.sopt.domain.usecase + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.flow.debounce +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flow +import org.sopt.domain.repo.SoptRepository +import javax.inject.Inject + +class GetSoptUseCase @Inject constructor( + private val soptRepository: SoptRepository, +) { + @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) + operator fun invoke(param: Param) = if (param.query.isBlank()) { + soptRepository.getAll() + } else { + soptRepository.getContainInput(param.query) + .debounce(200) + .flatMapLatest { + flow { + emit(it) + } + } + } + + + data class Param( + val query: String, + ) +} \ No newline at end of file