-
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.
[feature/api_get_university] BaseResponse 적용 (#83)
- Loading branch information
Showing
5 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
data/src/main/java/com/everymeal/data/datasource/remote/onboarding/OnboardingDataSource.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.everymeal.data.datasource.remote.onboarding | ||
|
||
import com.everymeal.data.model.onboarding.GetUniversityData | ||
import com.everymeal.data.model.onboarding.UniversityData | ||
|
||
interface OnboardingDataSource { | ||
suspend fun getUniversity(): Result<GetUniversityData> | ||
suspend fun getUniversity(): Result<List<UniversityData>> | ||
} |
7 changes: 4 additions & 3 deletions
7
...src/main/java/com/everymeal/data/datasource/remote/onboarding/OnboardingDataSourceImpl.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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package com.everymeal.data.datasource.remote.onboarding | ||
|
||
import com.everymeal.data.model.onboarding.GetUniversityData | ||
import com.everymeal.data.model.onboarding.UniversityData | ||
import com.everymeal.data.model.unwrapData | ||
import com.everymeal.data.service.onboarding.OnboardingApi | ||
import javax.inject.Inject | ||
|
||
class OnboardingDataSourceImpl @Inject constructor( | ||
private val onboardingApi: OnboardingApi | ||
) : OnboardingDataSource { | ||
|
||
override suspend fun getUniversity(): Result<GetUniversityData> { | ||
return runCatching { onboardingApi.getUniversity() } | ||
override suspend fun getUniversity(): Result<List<UniversityData>> { | ||
return runCatching { onboardingApi.getUniversity() }.unwrapData() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
data/src/main/java/com/everymeal/data/model/BaseResponse.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,14 @@ | ||
package com.everymeal.data.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BaseResponse<T>( | ||
val localDateTime: String, | ||
val message: String, | ||
val data: T, | ||
) | ||
|
||
fun <T> Result<BaseResponse<T>>.unwrapData(): Result<T> { | ||
return this.map { it.data } | ||
} |
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
6 changes: 3 additions & 3 deletions
6
data/src/main/java/com/everymeal/data/service/onboarding/OnboardingApi.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package com.everymeal.data.service.onboarding | ||
|
||
import com.everymeal.data.model.onboarding.GetUniversityData | ||
import retrofit2.Response | ||
import com.everymeal.data.model.BaseResponse | ||
import com.everymeal.data.model.onboarding.UniversityData | ||
import retrofit2.http.GET | ||
|
||
interface OnboardingApi { | ||
|
||
@GET("/api/v1/universities") | ||
suspend fun getUniversity(): GetUniversityData | ||
suspend fun getUniversity(): BaseResponse<List<UniversityData>> | ||
} |