-
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.
Code review [#25] P9, P14 - added abstract UseCase
- Loading branch information
Showing
11 changed files
with
104 additions
and
75 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
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
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
14 changes: 0 additions & 14 deletions
14
domain/src/main/java/com/edwin/domain/usecase/GetAddressFromGeocoderUseCase.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
domain/src/main/java/com/edwin/domain/usecase/GetFusedLocationUseCase.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
domain/src/main/java/com/edwin/domain/usecase/GetWeatherDetailsUseCase.kt
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
package com.edwin.domain.usecase | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
|
||
abstract class UseCase<out Type, in Params> { | ||
|
||
abstract suspend fun run(params: Params): Type | ||
|
||
operator fun invoke(params: Params): Flow<Result<Type>> { | ||
return flow { | ||
val result = try { | ||
Result.success(run(params)) | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
emit(result) | ||
}.flowOn(Dispatchers.IO) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
domain/src/main/java/com/edwin/domain/usecase/map/GetAddressFromGeocoderUseCase.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,19 @@ | ||
package com.edwin.domain.usecase.map | ||
|
||
import android.location.Address | ||
import com.edwin.domain.WeatherRepository | ||
import com.edwin.domain.usecase.UseCase | ||
|
||
class GetAddressFromGeocoderUseCase(private val weatherRepository: WeatherRepository) : | ||
UseCase<Address, GetAddressFromGeocoderUseCase.Params>() { | ||
|
||
override suspend fun run(params: Params): Address = weatherRepository.getAddress( | ||
params.latitude, params.longitude | ||
) | ||
|
||
data class Params( | ||
val latitude: Double, | ||
val longitude: Double | ||
) | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/com/edwin/domain/usecase/map/GetFusedLocationUseCase.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,11 @@ | ||
package com.edwin.domain.usecase.map | ||
|
||
import android.location.Location | ||
import com.edwin.domain.WeatherRepository | ||
import com.edwin.domain.usecase.UseCase | ||
|
||
class GetFusedLocationUseCase(private val weatherRepository: WeatherRepository) : | ||
UseCase<Location, Unit>() { | ||
|
||
override suspend fun run(params: Unit): Location = weatherRepository.getFusedLocation() | ||
} |
20 changes: 20 additions & 0 deletions
20
domain/src/main/java/com/edwin/domain/usecase/weather/GetWeatherDetailsUseCase.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,20 @@ | ||
package com.edwin.domain.usecase.weather | ||
|
||
import com.edwin.domain.WeatherRepository | ||
import com.edwin.domain.model.WeatherDetails | ||
import com.edwin.domain.usecase.UseCase | ||
|
||
class GetWeatherDetailsUseCase(private val weatherRepository: WeatherRepository) : | ||
UseCase<WeatherDetails?, GetWeatherDetailsUseCase.Params>() { | ||
|
||
override suspend fun run(params: Params): WeatherDetails? = | ||
weatherRepository.getWeatherResponse( | ||
params.latitude, params.longitude | ||
) | ||
|
||
data class Params( | ||
val latitude: Float, | ||
val longitude: Float | ||
) | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
domain/src/main/java/com/edwin/domain/util/UseCaseWrapper.kt
This file was deleted.
Oops, something went wrong.