Setup domain layer
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
|
import de.fayard.refreshVersions.core.versionFor
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
id("kotlin-android")
|
id("kotlin-android")
|
||||||
|
kotlin("plugin.serialization") version "1.5.21"
|
||||||
kotlin("kapt")
|
kotlin("kapt")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +39,11 @@ dependencies {
|
|||||||
api(platform(Libs.kotlin_coroutine_bom))
|
api(platform(Libs.kotlin_coroutine_bom))
|
||||||
api(Libs.kotlin_coroutine_core)
|
api(Libs.kotlin_coroutine_core)
|
||||||
|
|
||||||
|
api(Libs.ktor_client_core)
|
||||||
|
api(Libs.ktor_serialization)
|
||||||
|
|
||||||
|
api(Libs.room_runtime)
|
||||||
|
|
||||||
testImplementation(Libs.junit_jupiter_api)
|
testImplementation(Libs.junit_jupiter_api)
|
||||||
testImplementation(Libs.junit_jupiter_engine)
|
testImplementation(Libs.junit_jupiter_engine)
|
||||||
|
|
||||||
|
|||||||
+52
@@ -1,6 +1,58 @@
|
|||||||
package com.ericampire.android.androidstudycase.domain.di
|
package com.ericampire.android.androidstudycase.domain.di
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.AnimatorRepository
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.BlogRepository
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.LottieFileRepository
|
||||||
|
import com.ericampire.android.androidstudycase.domain.usecase.*
|
||||||
|
import com.ericampire.android.androidstudycase.util.IoDispatcher
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
object UseCaseModule {
|
object UseCaseModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideAnimatorUseCase(
|
||||||
|
repository: AnimatorRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
): FindFeaturedAnimatorUseCase {
|
||||||
|
return FindFeaturedAnimatorUseCase(repository, dispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideFindFeaturedBlogUseCase(
|
||||||
|
repository: BlogRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
): FindFeaturedBlogUseCase {
|
||||||
|
return FindFeaturedBlogUseCase(repository, dispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideFindFeaturedLottieFileUseCase(
|
||||||
|
repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
): FindFeaturedLottieFileUseCase {
|
||||||
|
return FindFeaturedLottieFileUseCase(repository, dispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideFindRecentLottieFileUseCase(
|
||||||
|
repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
): FindRecentLottieFileUseCase {
|
||||||
|
return FindRecentLottieFileUseCase(repository, dispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideFindPopularLottieFileUseCase(
|
||||||
|
repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
): FindPopularLottieFileUseCase {
|
||||||
|
return FindPopularLottieFileUseCase(repository, dispatcher)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.entity
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@Entity
|
||||||
|
data class Animator(
|
||||||
|
@PrimaryKey
|
||||||
|
val name: String = "",
|
||||||
|
val avatarUrl: String = "",
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FeaturedAnimators(val results: List<Animator>)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class AnimatorData(
|
||||||
|
val featuredAnimators: FeaturedAnimators
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class AnimatorApiResponse(
|
||||||
|
@SerialName("data") val animatorAnimatorData: AnimatorData
|
||||||
|
)
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.entity
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import kotlinx.serialization.Contextual
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BlogPage(
|
||||||
|
val currentPage: Int,
|
||||||
|
val from: Int,
|
||||||
|
val perPage: Int,
|
||||||
|
val blogs: List<Blog>,
|
||||||
|
val to: Int,
|
||||||
|
val total: Int,
|
||||||
|
val totalPages: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BlogData(
|
||||||
|
@SerialName("blogs") val blogPage: BlogPage
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BlogApiResponse(
|
||||||
|
@SerialName("data") val blogBlogData: BlogData
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@Entity
|
||||||
|
data class Blog(
|
||||||
|
@Contextual val postedAt: Date,
|
||||||
|
@PrimaryKey val imageUrl: String,
|
||||||
|
val title: String
|
||||||
|
)
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.entity
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import kotlinx.serialization.Contextual
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import java.util.*
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.JsonNames
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LottieFilesApiResponse(
|
||||||
|
@SerialName("data")
|
||||||
|
val lottieFilesLottieFilesData: LottieFilesData
|
||||||
|
)
|
||||||
|
|
||||||
|
@ExperimentalSerializationApi
|
||||||
|
@Serializable
|
||||||
|
data class LottieFilesData(
|
||||||
|
@JsonNames("recent", "popular")
|
||||||
|
val page: LottieFilesPage
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LottieFilesPage(
|
||||||
|
val currentPage: Int,
|
||||||
|
val from: Int,
|
||||||
|
val perPage: Int,
|
||||||
|
val results: List<Lottiefile>,
|
||||||
|
val to: Int,
|
||||||
|
val total: Int,
|
||||||
|
val totalPages: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@Entity
|
||||||
|
class Lottiefile(
|
||||||
|
@PrimaryKey val id: Long,
|
||||||
|
val bgColor: String,
|
||||||
|
val lottieUrl: String,
|
||||||
|
val gifUrl: String,
|
||||||
|
val videoUrl: String,
|
||||||
|
val imageUrl: String,
|
||||||
|
val name: String,
|
||||||
|
@Contextual val createdAt: Date,
|
||||||
|
val createdBy: Animator
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.ericampire.android.androidstudycase.domain.entity
|
|
||||||
|
|
||||||
|
|
||||||
data class User(
|
|
||||||
val uid: String = "",
|
|
||||||
|
|
||||||
)
|
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.repository
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Animator
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
|
||||||
|
interface AnimatorRepository {
|
||||||
|
fun findAll(): Flow<Result<List<Animator>>>
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.repository
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Animator
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Blog
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface BlogRepository {
|
||||||
|
fun findAll(): Flow<Result<List<Blog>>>
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.repository
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Lottiefile
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface LottieFileRepository {
|
||||||
|
fun findRecent(): Flow<Result<List<Lottiefile>>>
|
||||||
|
fun findPopular(): Flow<Result<List<Lottiefile>>>
|
||||||
|
fun findFeatured(): Flow<Result<List<Lottiefile>>>
|
||||||
|
}
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
package com.ericampire.android.androidstudycase.domain.repository
|
|
||||||
|
|
||||||
|
|
||||||
interface UserRepository {
|
|
||||||
|
|
||||||
}
|
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.usecase
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Animator
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Blog
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.AnimatorRepository
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.BlogRepository
|
||||||
|
import com.ericampire.android.androidstudycase.util.IoDispatcher
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import com.ericampire.android.androidstudycase.util.usecase.FlowUseCase
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class FindFeaturedBlogUseCase @Inject constructor(
|
||||||
|
private val repository: BlogRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
) : FlowUseCase<Unit, List<Blog>>(dispatcher) {
|
||||||
|
override fun execute(parameters: Unit): Flow<Result<List<Blog>>> {
|
||||||
|
return repository.findAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.usecase
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Animator
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.AnimatorRepository
|
||||||
|
import com.ericampire.android.androidstudycase.util.IoDispatcher
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import com.ericampire.android.androidstudycase.util.usecase.FlowUseCase
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class FindFeaturedAnimatorUseCase @Inject constructor(
|
||||||
|
private val repository: AnimatorRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
) : FlowUseCase<Unit, List<Animator>>(dispatcher) {
|
||||||
|
override fun execute(parameters: Unit): Flow<Result<List<Animator>>> {
|
||||||
|
return repository.findAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package com.ericampire.android.androidstudycase.domain.usecase
|
||||||
|
|
||||||
|
import com.ericampire.android.androidstudycase.domain.entity.Lottiefile
|
||||||
|
import com.ericampire.android.androidstudycase.domain.repository.LottieFileRepository
|
||||||
|
import com.ericampire.android.androidstudycase.util.IoDispatcher
|
||||||
|
import com.ericampire.android.androidstudycase.util.Result
|
||||||
|
import com.ericampire.android.androidstudycase.util.usecase.FlowUseCase
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class FindRecentLottieFileUseCase @Inject constructor(
|
||||||
|
private val repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
) : FlowUseCase<Unit, List<Lottiefile>>(dispatcher) {
|
||||||
|
override fun execute(parameters: Unit): Flow<Result<List<Lottiefile>>> {
|
||||||
|
return repository.findRecent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FindPopularLottieFileUseCase @Inject constructor(
|
||||||
|
private val repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
) : FlowUseCase<Unit, List<Lottiefile>>(dispatcher) {
|
||||||
|
override fun execute(parameters: Unit): Flow<Result<List<Lottiefile>>> {
|
||||||
|
return repository.findPopular()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FindFeaturedLottieFileUseCase @Inject constructor(
|
||||||
|
private val repository: LottieFileRepository,
|
||||||
|
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||||
|
) : FlowUseCase<Unit, List<Lottiefile>>(dispatcher) {
|
||||||
|
override fun execute(parameters: Unit): Flow<Result<List<Lottiefile>>> {
|
||||||
|
return repository.findFeatured()
|
||||||
|
}
|
||||||
|
}
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
package com.ericampire.android.androidstudycase.domain.usecase
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user