Skip to content

Commit

Permalink
[feat] #4 core domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook123 committed Apr 13, 2024
1 parent 7036833 commit 28d4a30
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
9 changes: 9 additions & 0 deletions core/domain/build.gradle.kts
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 core/domain/src/main/java/org/sopt/domain/repo/SoptRepository.kt
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()
}
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,
)
}

0 comments on commit 28d4a30

Please sign in to comment.