generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7036833
commit 28d4a30
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
/build |
This file contains 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,9 @@ | ||
plugins { | ||
alias(libs.plugins.sopt.java.library) | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.model) | ||
implementation(libs.kotlinx.coroutines.core) | ||
implementation(libs.hilt.core) | ||
} |
16 changes: 16 additions & 0 deletions
16
core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt
This file contains 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,16 @@ | ||
package org.sopt.domain.repo | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import org.sopt.model.Friend | ||
|
||
interface SoptRepository { | ||
fun getAll(): Flow<List<Friend>> | ||
|
||
fun getContainInput(input: String): Flow<List<Friend>> | ||
|
||
suspend fun addFriend(friend: Friend) | ||
|
||
suspend fun deleteFriendById(id: Int) | ||
|
||
suspend fun deleteAll() | ||
} |
31 changes: 31 additions & 0 deletions
31
core/domain/src/main/java/org/sopt/domain/usecase/GetSoptUseCase.kt
This file contains 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,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, | ||
) | ||
} |