Skip to content

Commit

Permalink
Add domain and interactor modules
Browse files Browse the repository at this point in the history
  • Loading branch information
shounakmulay committed Oct 22, 2021
1 parent 6473c7f commit 9fe32db
Show file tree
Hide file tree
Showing 88 changed files with 1,060 additions and 50 deletions.
3 changes: 3 additions & 0 deletions app/app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ android {
dependencies {
implementation project(":service-di")
implementation project(":repo-di")
implementation project(":domain-di")
implementation project(":interactor-di")
implementation project(":presentation-di")

def ext = rootProject.ext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wednesday.template

import android.app.Application
import com.wednesday.template.domain.domainModule
import com.wednesday.template.interactor.interactorModule
import com.wednesday.template.repo.repoModule
import com.wednesday.template.service.serviceModule
import org.koin.android.ext.koin.androidContext
Expand All @@ -20,7 +22,9 @@ class AndroidTemplateApplication : Application() {
androidContext(applicationContext)
modules(
serviceModule,
repoModule
repoModule,
domainModule,
interactorModule,
)
}
}
Expand Down
11 changes: 5 additions & 6 deletions domain-di/domain-di.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ apply from: "$rootProject.projectDir/android.gradle"
apply from: "$rootProject.projectDir/lint.gradle"

dependencies {
implementation project(":domain")
implementation project(":domain-impl")

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def ext = rootProject.ext

implementation ext.koin.core
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wednesday.template.domain

import com.wednesday.template.domain.weather.GetFavouriteCitiesFlowUseCase
import com.wednesday.template.domain.weather.GetFavouriteCitiesFlowUseCaseImpl
import com.wednesday.template.domain.weather.RemoveCityFavouriteUseCase
import com.wednesday.template.domain.weather.RemoveCityFavouriteUseCaseImpl
import com.wednesday.template.domain.weather.SearchCitiesUseCase
import com.wednesday.template.domain.weather.SearchCitiesUseCaseImpl
import com.wednesday.template.domain.weather.SetCityFavouriteUseCase
import com.wednesday.template.domain.weather.SetCityFavouriteUseCaseImpl
import org.koin.dsl.module

val domainModule = module {
// Weather
single<GetFavouriteCitiesFlowUseCase> { GetFavouriteCitiesFlowUseCaseImpl(get()) }

single<SetCityFavouriteUseCase> { SetCityFavouriteUseCaseImpl(get()) }

single<RemoveCityFavouriteUseCase> { RemoveCityFavouriteUseCaseImpl(get()) }

single<SearchCitiesUseCase> { SearchCitiesUseCaseImpl(get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wednesday.template.domain.base

sealed class Result<out T> {

class Success<T>(val data: T) : Result<T>()

class Error(val exception: Exception) : Result<Nothing>()
}
15 changes: 9 additions & 6 deletions domain-impl/domain-impl.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ apply from: "$rootProject.projectDir/android.gradle"
apply from: "$rootProject.projectDir/lint.gradle"

dependencies {
implementation project(":domain")
implementation project(":domain-entity")
implementation project(":repo")

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def ext = rootProject.ext

implementation ext.kotlin.stdLib
implementation ext.coroutines.core

implementation ext.logging.timber
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.repo.weather.WeatherRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onEach
import timber.log.Timber

class GetFavouriteCitiesFlowUseCaseImpl(
private val weatherRepository: WeatherRepository
): GetFavouriteCitiesFlowUseCase {

override fun invokeInternal(param: Unit): Flow<List<City>> {
Timber.tag(TAG).d("invokeInternal")
return weatherRepository.getFavouriteCitiesFlow()
.onEach { Timber.tag(TAG).d("invokeInternal: emit = $it") }
}

companion object {
private const val TAG = "GetFavouriteCitiesFlowUseCaseImpl"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.repo.weather.WeatherRepository
import timber.log.Timber

class RemoveCityFavouriteUseCaseImpl(
private val weatherRepository: WeatherRepository
) : RemoveCityFavouriteUseCase {

override suspend fun invokeInternal(param: City) {
Timber.tag(TAG).d("invokeInternal: param = $param")
return weatherRepository.removeCityAsFavourite(param)
}

companion object {
private const val TAG = "RemoveCityFavouriteUseCaseImpl"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.repo.weather.WeatherRepository
import timber.log.Timber

class SearchCitiesUseCaseImpl(
private val weatherRepository: WeatherRepository
): SearchCitiesUseCase {

override suspend fun invokeInternal(param: String): List<City> {
Timber.tag(TAG).d("invokeInternal: param = $param")
return weatherRepository.searchCities(param)
}

companion object {
private const val TAG = "SearchCitiesUseCaseImpl"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.repo.weather.WeatherRepository
import timber.log.Timber

class SetCityFavouriteUseCaseImpl(
private val weatherRepository: WeatherRepository
) : SetCityFavouriteUseCase {

override suspend fun invokeInternal(param: City) {
Timber.tag(TAG).d("invokeInternal: param = $param")
return weatherRepository.setCityAsFavourite(param)
}

companion object {
private const val TAG = "SetCityFavouriteUseCaseImpl"
}
}
11 changes: 5 additions & 6 deletions domain/domain.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ apply from: "$rootProject.projectDir/android.gradle"
apply from: "$rootProject.projectDir/lint.gradle"

dependencies {
implementation project(":domain-entity")

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def ext = rootProject.ext

implementation ext.kotlin.stdLib
implementation ext.coroutines.core
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wednesday.template.domain.base

import kotlinx.coroutines.flow.Flow

interface BaseFlowUseCase<IN, OUT> {

operator fun invoke(param: IN): Flow<OUT> = invokeInternal(param)

fun invokeInternal(param: IN): Flow<OUT>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wednesday.template.domain.base

interface BaseSuspendUseCase<IN, OUT> {

suspend operator fun invoke(param: IN): Result<OUT> {
return try {
Result.Success(invokeInternal(param))
} catch (e: Exception) {
Result.Error(e)
}
}

suspend fun invokeInternal(param: IN): OUT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wednesday.template.domain.base

interface BaseUseCase<IN, OUT> {

operator fun invoke(param: IN): Result<OUT> {
return try {
Result.Success(invokeInternal(param))
} catch (e: Exception) {
Result.Error(e)
}
}

fun invokeInternal(param: IN): OUT
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.domain.base.BaseFlowUseCase

interface GetFavouriteCitiesFlowUseCase: BaseFlowUseCase<Unit, List<City>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.domain.base.BaseSuspendUseCase

interface RemoveCityFavouriteUseCase: BaseSuspendUseCase<City, Unit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.domain.base.BaseSuspendUseCase

interface SearchCitiesUseCase: BaseSuspendUseCase<String, List<City>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wednesday.template.domain.weather

import com.wednesday.template.domain.base.BaseSuspendUseCase

interface SetCityFavouriteUseCase: BaseSuspendUseCase<City, Unit>
1 change: 1 addition & 0 deletions interactor-di/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Empty file.
15 changes: 15 additions & 0 deletions interactor-di/interactor-di.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

apply from: "$rootProject.projectDir/android.gradle"

dependencies {
implementation project(":interactor")
implementation project(":interactor-impl")

def ext = rootProject.ext

implementation ext.koin.core
}
21 changes: 21 additions & 0 deletions interactor-di/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wednesday.template.interactor

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.wednesday.template.interactor.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions interactor-di/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wednesday.template.interactor_di">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wednesday.template.interactor

import com.wednesday.template.interactor.base.CoroutineContextController
import com.wednesday.template.interactor.base.CoroutineContextControllerImpl
import com.wednesday.template.interactor.weather.FavouriteWeatherInteractor
import com.wednesday.template.interactor.weather.SearchCityInteractor
import com.wednesday.template.interactor.weather.favourite.FavouriteWeatherInteractorImpl
import com.wednesday.template.interactor.weather.UICityMapper
import com.wednesday.template.interactor.weather.UICityMapperImpl
import com.wednesday.template.interactor.weather.search.SearchCityInteractorImpl
import org.koin.dsl.module

val interactorModule = module {
single<CoroutineContextController> { CoroutineContextControllerImpl() }

// Weather
single<UICityMapper> { UICityMapperImpl() }

factory<FavouriteWeatherInteractor> { FavouriteWeatherInteractorImpl(get(), get(), get(), get(), get()) }

factory<SearchCityInteractor> { SearchCityInteractorImpl(get(), get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wednesday.template.interactor

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
1 change: 1 addition & 0 deletions interactor-impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Empty file.
Loading

0 comments on commit 9fe32db

Please sign in to comment.