Skip to content

Commit

Permalink
Added get remote alerts and local saved alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanarodr committed May 4, 2024
1 parent e5c3a71 commit 8b8cf6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import br.com.stonks.feature.stocks.repository.remote.response.StockAlertRespons

internal interface StockRepository {

suspend fun getRemoteStockAlerts(): Result<List<StockAlertResponse>>

suspend fun listStockAlerts(): Result<List<StockAlertResponse>>

suspend fun getStockAlert(alertId: Long): Result<StockAlertResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ internal class StockRepositoryImpl(
private val stockAlertResponseToEntityMapper: StockAlertResponseToEntityMapper,
) : StockRepository {

override suspend fun getRemoteStockAlerts(): Result<List<StockAlertResponse>> {
return stockRemoteDataSource.getStockAlerts()
}

override suspend fun listStockAlerts(): Result<List<StockAlertResponse>> {
return stockRemoteDataSource.getStockAlerts().onSuccess { result ->
result.forEach {
stockLocalDataSource.insertStockAlert(
entity = stockAlertResponseToEntityMapper.mapper(it),
)
return stockLocalDataSource.listStockAlerts().mapCatching { results ->
results.map {
stockAlertEntityToResponseMapper.mapper(it)
}
}
}
Expand Down

0 comments on commit 8b8cf6a

Please sign in to comment.