File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
app/src/main/java/com/wafflestudio/siksha2 Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ interface SikshaApi {
3434 ): NetworkResult <FetchReviewsResult >
3535
3636 @GET(" /restaurants/" )
37- suspend fun fetchRestaurants (): FetchRestaurantsResult
37+ suspend fun fetchRestaurants (): NetworkResult < FetchRestaurantsResult >
3838
3939 @POST(" /reviews/" )
4040 suspend fun leaveMenuReview (@Body req : LeaveReviewParam ): LeaveReviewResult
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class MenuRepository @Inject constructor(
4242 dailyMenusDao.insertDailyMenus(payload)
4343 }
4444 else -> {
45- // TODO: 캐싱 실패 시 별도 로직 필요한가?
45+ throw RuntimeException ( " " )
4646 }
4747 }
4848 }
Original file line number Diff line number Diff line change @@ -3,10 +3,12 @@ package com.wafflestudio.siksha2.repositories
33import com.wafflestudio.siksha2.db.RestaurantsDao
44import com.wafflestudio.siksha2.models.RestaurantInfo
55import com.wafflestudio.siksha2.network.SikshaApi
6+ import com.wafflestudio.siksha2.network.result.NetworkResult
67import com.wafflestudio.siksha2.preferences.SikshaPrefObjects
78import kotlinx.coroutines.Dispatchers
89import kotlinx.coroutines.flow.Flow
910import kotlinx.coroutines.withContext
11+ import java.io.IOException
1012import javax.inject.Inject
1113import javax.inject.Singleton
1214
@@ -22,8 +24,15 @@ class RestaurantRepository @Inject constructor(
2224
2325 suspend fun syncWithServer () {
2426 withContext(Dispatchers .IO ) {
25- val data = sikshaApi.fetchRestaurants()
26- restaurantsDao.update(data.result)
27+ when (val response = sikshaApi.fetchRestaurants()) {
28+ is NetworkResult .Success -> {
29+ val data = response.body
30+ restaurantsDao.update(data.result)
31+ }
32+ else -> {
33+ throw IOException (" " )
34+ }
35+ }
2736 }
2837 }
2938
You can’t perform that action at this time.
0 commit comments