-
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.
[ADD] : network neighborhoodLife api #11
- Loading branch information
Showing
9 changed files
with
104 additions
and
14 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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/org/sopt/carrot/data/api/RetrofitManager.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,33 @@ | ||
package org.sopt.carrot.data.api | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.carrot.BuildConfig | ||
import retrofit2.Retrofit | ||
|
||
object RetrofitManager { | ||
private const val BASE_URL = BuildConfig.BASE_URL | ||
|
||
private val httpLoggingInterceptor = HttpLoggingInterceptor() | ||
.setLevel(HttpLoggingInterceptor.Level.BODY) | ||
|
||
private val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(httpLoggingInterceptor) | ||
.build() | ||
|
||
val retrofit: Retrofit = | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
inline fun <reified T> create(): T = retrofit.create<T>(T::class.java) | ||
} | ||
|
||
object RetrofitServicePool { | ||
val carrotService = RetrofitManager.create<CarrotService>() | ||
} |
17 changes: 11 additions & 6 deletions
17
app/src/main/java/org/sopt/carrot/data/datasource/remote/NeighborhoodLifeRemoteDatasource.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,19 @@ | ||
package org.sopt.carrot.data.datasource.remote | ||
|
||
import org.sopt.carrot.data.api.NeighborhoodLifeService | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.withContext | ||
import org.sopt.carrot.data.api.CarrotService | ||
import org.sopt.carrot.data.model.neighborhoodlife.LivesDataResponse | ||
import org.sopt.carrot.data.model.neighborhoodlife.LivesResponse | ||
import retrofit2.Response | ||
|
||
class NeighborhoodLifeRemoteDatasource( | ||
private val neighborhoodLifeService: NeighborhoodLifeService | ||
private val carrotService: CarrotService | ||
) { | ||
suspend fun getLives(category: String): List<LivesDataResponse> { | ||
return neighborhoodLifeService.getLives(category).data | ||
suspend fun getLives(): List<LivesDataResponse> { | ||
return withContext(Dispatchers.IO) { | ||
async { | ||
carrotService.getLives().data | ||
}.await() | ||
} | ||
} | ||
} |
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: 14 additions & 0 deletions
14
...n/java/org/sopt/carrot/presentation/neighborhoodlife/NeighborhoodLifeViewModelProvider.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 org.sopt.carrot.presentation.neighborhoodlife | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import org.sopt.carrot.data.repo.NeighborhoodLifeRepository | ||
|
||
class NeighborhoodLifeViewModelProvider( | ||
private val neighborhoodLifeRepository: NeighborhoodLifeRepository | ||
) : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return modelClass.getConstructor(NeighborhoodLifeRepository::class.java) | ||
.newInstance(neighborhoodLifeRepository) | ||
} | ||
} |
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