-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/week4 essential #9
base: develop
Are you sure you want to change the base?
Changes from 5 commits
9998234
15ed22d
7ca105e
108913b
eb1e6b0
a45a98e
17d2e78
7d7c35a
387932c
aa1f61b
d29b3a3
e781f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import android.util.Log | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.Interceptor | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.dosopttemplate.BuildConfig | ||
import retrofit2.Retrofit | ||
|
||
object ApiFactory { | ||
lateinit var url: String | ||
private fun getLogOkHttpClient(): Interceptor { | ||
val loggingInterceptor = HttpLoggingInterceptor { message -> | ||
Log.d("Retrofit2", "CONNECTION INFO -> $message") | ||
} | ||
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY | ||
return loggingInterceptor | ||
} | ||
|
||
val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(getLogOkHttpClient()) | ||
.build() | ||
|
||
val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(url) | ||
.client(okHttpClient) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
|
||
inline fun <reified T> create(url: String): T { | ||
this.url = url | ||
return retrofit.create<T>(T::class.java) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. urlμμ±μ ꡬλΆνμ¬ μμ±νλκ±° μ’μκ±° κ°μ΅λλ€! |
||
} | ||
|
||
object ServicePool { | ||
private const val BASE_URL = BuildConfig.AUTH_BASE_URL | ||
private const val REQRES_BASE_URL = BuildConfig.REQRES_BASE_URL | ||
|
||
val authService = ApiFactory.create<AuthService>(BASE_URL) | ||
val followerService = ApiFactory.create<FollowerService>(REQRES_BASE_URL) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("api/v1/members/sign-in") | ||
fun login( | ||
@Body request: RequestLoginDto, | ||
): Call<ResponseLoginDto> | ||
|
||
@POST("api/v1/members") | ||
fun signUp( | ||
@Body request: RequestSignUpDto, | ||
): Call<Unit> | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
|
||
interface FollowerService { | ||
@GET("https://reqres.in/api/users?page=2") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ μ¬κΈ°μ urlμ΄ μ λΆ λ€μ΄κ°μκΉμ? ? μ΄ μλ κ²½μ° μ¬μ©νλ μ΄λ Έν μ΄μ μ΄ μμ΅λλ€. μ§κΈμ 2λ² νμ΄μ§λ§ κ³ μ μΌλ‘ λ°μμ€κ³ μλ€μ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ€μ‘...! |
||
fun getFollowerList(): Call<ResponseGetFollwerDto> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestLoginDto( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestSignUpDto( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("nickname") | ||
val nickname: String, | ||
@SerialName("password") | ||
val password: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseData( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("email") | ||
val email: String, | ||
@SerialName("first_name") | ||
val first_name: String, | ||
@SerialName("last_name") | ||
val last_name: String, | ||
@SerialName("avatar") | ||
val avatar: String, | ||
) | ||
|
||
@Serializable | ||
data class ResponseSupport( | ||
@SerialName("url") | ||
val url: String, | ||
@SerialName("text") | ||
val text: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseGetFollwerDto( | ||
@SerialName("page") | ||
val page: Int, | ||
@SerialName("per_page") | ||
val per_page: Int, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Camel, snake μ€ νλλ§ κ³¨λΌμ μ μ©ν΄λ³ΌκΉμ? λ€λ₯Έ data classλ μΉ΄λ©μ΄λ€μ! |
||
@SerialName("total") | ||
val total: Int, | ||
@SerialName("total_pages") | ||
val total_pages: Int, | ||
@SerialName("data") | ||
val data: List<ResponseData>, | ||
@SerialName("support") | ||
val support: ResponseSupport | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ³κ±΄μλλ° μμλμ κ°λ μ±μ΄ μμ’μ보μ¬μ γ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μμ νκ² μ΅λλ€! |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseLoginDto( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("nickname") | ||
val nickname: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.dosopttemplate.API | ||
|
||
sealed class SignupResponse { | ||
data class ResponseSignUpDto( | ||
val location: String | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ ν΄μ£ΌμΈμ~