-
Notifications
You must be signed in to change notification settings - Fork 0
[Week6] 기존 과제 코루틴으로 변경하기 #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
9d86dc9
d9f2d6d
446880d
6cf63e6
1ac8a9d
741dd20
c436c9a
27cfb3e
912e9f2
afc9084
03bd6b7
4bdcd3c
fb976a0
81e778a
d9d7d31
57c42fa
19a87b0
97ce311
8310a5e
948af71
9285ff1
5525cad
a5c5b6c
5a633e1
66ce411
3cb5622
dffccb0
b03f93c
59497c1
090d581
a238248
c709bd7
3790041
b79fe68
197a372
b50da7d
c93f437
2615659
6ff34dc
84064aa
f9a27e8
8c4ce65
ac97b36
ccf5756
b2b91b1
92e738e
2105eea
bad0157
d7c1c3e
b5ef5ff
20277b2
e7ebb2c
d96d89c
33b6d0c
fd033d0
44d7479
5e141b4
6225039
863199e
3316d52
11efdde
7607f5f
f8dc07b
bd54daa
0b35581
d5bb0ba
92b2a94
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,37 @@ | ||
| package com.sopt.dive.data | ||
|
|
||
| import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
| import com.sopt.dive.BuildConfig | ||
| import kotlinx.serialization.json.Json | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.logging.HttpLoggingInterceptor | ||
| import retrofit2.Retrofit | ||
|
|
||
| object ApiFactory { | ||
| private val BASE_URL: String = BuildConfig.BASE_URL | ||
|
|
||
| private val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
| level = HttpLoggingInterceptor.Level.BODY | ||
| } | ||
|
|
||
| private val client = OkHttpClient.Builder() | ||
| .addInterceptor(loggingInterceptor) | ||
| .build() | ||
|
|
||
| private val json = Json { | ||
| explicitNulls = false | ||
| } | ||
|
|
||
| val retrofit: Retrofit by lazy { | ||
| Retrofit.Builder() | ||
| .baseUrl(BASE_URL) | ||
| .client(client) | ||
| .addConverterFactory( | ||
| json.asConverterFactory("application/json".toMediaType()) | ||
| ) | ||
| .build() | ||
| } | ||
|
|
||
| inline fun <reified T> create(): T = retrofit.create(T::class.java) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.sopt.dive.data | ||
|
|
||
| import com.sopt.dive.data.api.AuthService | ||
| import com.sopt.dive.data.api.UserService | ||
|
|
||
| object ServicePool { | ||
| val userService: UserService by lazy { | ||
| ApiFactory.create<UserService>() | ||
| } | ||
|
|
||
| val authService: AuthService by lazy { | ||
| ApiFactory.create<AuthService>() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.sopt.dive.data.api | ||
|
|
||
| import com.sopt.dive.data.dto.LoginDataDto | ||
| import com.sopt.dive.data.dto.RequestLoginDto | ||
| import com.sopt.dive.data.dto.ResponseSuccessDto | ||
| import retrofit2.Response | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.POST | ||
|
|
||
| interface AuthService { | ||
| @POST("api/v1/auth/login") | ||
| suspend fun login( | ||
| @Body request: RequestLoginDto | ||
| ): Response<ResponseSuccessDto<LoginDataDto>> | ||
|
Member
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. 이번 합세에서 배웠을 지 모르겠지만 BaseResponse 를 사용해 봅시다~ wrapping이 너무 많이 되어있네요! |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.sopt.dive.data.api | ||
|
|
||
| import com.sopt.dive.data.dto.RequestSignupDto | ||
| import com.sopt.dive.data.dto.ResponseSuccessDto | ||
| import com.sopt.dive.data.dto.ResponseUserDto | ||
| import retrofit2.Response | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.POST | ||
| import retrofit2.http.Path | ||
|
|
||
| interface UserService { | ||
| @POST("api/v1/users") | ||
| suspend fun signup( | ||
| @Body request: RequestSignupDto | ||
| ): Response<ResponseSuccessDto<ResponseUserDto>> | ||
|
|
||
| @GET("api/v1/users/{id}") | ||
| fun fetchUserInfo( | ||
|
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. suspend 키워드 빠진 거 같아요! |
||
| @Path("id") id: Int, | ||
| ): Response<ResponseSuccessDto<ResponseUserDto>> | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| 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,22 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class RequestSignupDto( | ||
| @SerialName("username") | ||
| val username: String, | ||
|
|
||
| @SerialName("password") | ||
| val password: String, | ||
|
|
||
| @SerialName("name") | ||
| val name: String, | ||
|
|
||
| @SerialName("email") | ||
| val email: String, | ||
|
|
||
| @SerialName("age") | ||
| val age: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class ResponseErrorDto( | ||
|
|
||
| @SerialName("success") | ||
| val success: Boolean = false, | ||
|
|
||
| @SerialName("code") | ||
| val code: String, | ||
|
|
||
| @SerialName("message") | ||
| val message: String, | ||
|
|
||
| @SerialName("data") | ||
| val data: ErrorDataDto? | ||
|
|
||
| ) | ||
|
|
||
| @Serializable | ||
| data class ErrorDataDto( | ||
|
|
||
| @SerialName("code") | ||
| val code: String, | ||
|
|
||
| @SerialName("message") | ||
| val message: String, | ||
|
|
||
| @SerialName("errors") | ||
| val errors: List<FieldErrorDto>? | ||
|
|
||
| ) | ||
|
|
||
| @Serializable | ||
| data class FieldErrorDto( | ||
|
|
||
| @SerialName("field") | ||
| val field: String, | ||
|
|
||
| @SerialName("value") | ||
| val value: String, | ||
|
|
||
| @SerialName("reason") | ||
| val reason: String | ||
|
|
||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class LoginDataDto( | ||
| @SerialName("userId") | ||
| val userId: Int, | ||
|
|
||
| @SerialName("message") | ||
| val message: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class ResponseSuccessDto<T>( | ||
| @SerialName("success") val success: Boolean, | ||
| @SerialName("code") val code: String, | ||
| @SerialName("message") val message: String, | ||
| @SerialName("data") val data: T? | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.sopt.dive.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| enum class Status { ACTIVE } | ||
|
Member
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. 혹시 따로 이렇게 1개의 status를 data에서 만들어 준 이유가 있을까요? |
||
|
|
||
| @Serializable | ||
| data class ResponseUserDto( | ||
| @SerialName("id") | ||
| val id: Long, | ||
|
|
||
| @SerialName("username") | ||
| val username: String, | ||
|
|
||
| @SerialName("name") | ||
| val name: String, | ||
|
|
||
| @SerialName("email") | ||
| val email: String, | ||
|
|
||
| @SerialName("age") | ||
| val age: Int, | ||
|
|
||
| @SerialName("status") | ||
| val status: Status | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.sopt.dive.model | ||
|
|
||
| import android.os.Parcelable | ||
| import kotlinx.parcelize.Parcelize | ||
|
|
||
| @Parcelize | ||
| data class HomeProfileInfo( | ||
| val userName: String, | ||
| val title: String, | ||
| val content: String | ||
| ) : Parcelable |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.sopt.dive.model | ||
|
|
||
| import android.os.Parcelable | ||
| import kotlinx.parcelize.Parcelize | ||
|
|
||
| @Parcelize | ||
| data class User( | ||
| val id: String, | ||
| val pw: String, | ||
| val name: String, | ||
| val email: String, | ||
| val age: Int | ||
| ) : Parcelable |
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.
p2: 현재 방식은 버전을 명시하지 않고 사용하기에 프로젝트 버전 관리를 하기 어려워요 이친구도
versions.toml에 plugins 에 정의해서 사용해 보는 것두 추천드립니다 ㅎkotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlinParcelize" }