-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAppWidgetDataRepository.kt
More file actions
29 lines (26 loc) · 956 Bytes
/
AppWidgetDataRepository.kt
File metadata and controls
29 lines (26 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package to.bitkit.appwidget
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import to.bitkit.data.dto.ArticleDTO
import to.bitkit.data.dto.price.GraphPeriod
import to.bitkit.data.dto.price.PriceDTO
import to.bitkit.data.widgets.NewsService
import to.bitkit.data.widgets.PriceService
import to.bitkit.di.IoDispatcher
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class AppWidgetDataRepository @Inject constructor(
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
private val priceService: PriceService,
private val newsService: NewsService,
) {
suspend fun fetchPriceData(period: GraphPeriod = GraphPeriod.ONE_DAY): Result<PriceDTO> =
withContext(ioDispatcher) {
priceService.fetchData(period)
}
suspend fun fetchArticles(): Result<List<ArticleDTO>> =
withContext(ioDispatcher) {
newsService.fetchData()
}
}