generated from AND-SOPT-ANDROID/and-sopt-android-template
-
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.
- Loading branch information
Showing
7 changed files
with
144 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.sopt.and.data | ||
|
||
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.and.BuildConfig | ||
import org.sopt.and.data.network.service.UserService | ||
import retrofit2.Retrofit | ||
|
||
object ApiFactory { | ||
private const val BASE_URL: String = BuildConfig.BASE_URL | ||
|
||
private val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
|
||
private val client = OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build() | ||
|
||
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) | ||
} | ||
|
||
object ServicePool { | ||
val userService = ApiFactory.create<UserService>() | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/sopt/and/data/model/dto/ResponseUserHobbyDto.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,17 @@ | ||
package org.sopt.and.data.model.dto | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseUserHobbyDto( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
@Serializable | ||
data class Result( | ||
@SerialName("hobby") | ||
val hobby: String | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/sopt/and/data/model/dto/ResponseUserSignUpDto.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,17 @@ | ||
package org.sopt.and.data.model.dto | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseUserSignUpDto( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
@Serializable | ||
data class Result( | ||
@SerialName("no") | ||
val no: Int | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/sopt/and/data/model/dto/ResponseUserTokenDto.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,17 @@ | ||
package org.sopt.and.data.model.dto | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseUserTokenDto( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
@Serializable | ||
data class Result( | ||
@SerialName("token") | ||
val token: String | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/and/data/model/request/UserLoginRequest.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,13 @@ | ||
package org.sopt.and.data.model.request | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserLoginRequest( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/and/data/model/request/UserSignUpRequest.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,15 @@ | ||
package org.sopt.and.data.model.request | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserSignUpRequest( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String | ||
) |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/sopt/and/data/network/service/UserService.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,29 @@ | ||
package org.sopt.and.data.network.service | ||
|
||
import org.sopt.and.data.model.dto.ResponseUserHobbyDto | ||
import org.sopt.and.data.model.dto.ResponseUserSignUpDto | ||
import org.sopt.and.data.model.dto.ResponseUserTokenDto | ||
import org.sopt.and.data.model.request.UserLoginRequest | ||
import org.sopt.and.data.model.request.UserSignUpRequest | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.POST | ||
|
||
interface UserService { | ||
@POST("/user") | ||
fun postUserSignUp( | ||
@Body body: UserSignUpRequest | ||
): Call<ResponseUserSignUpDto> | ||
|
||
@POST("/login") | ||
fun postUserLogin( | ||
@Body body: UserLoginRequest | ||
): Call<ResponseUserTokenDto> | ||
|
||
@GET("/user/my-hobby") | ||
fun getUserHobby( | ||
@Header("token") token: String, | ||
): Call<ResponseUserHobbyDto> | ||
} |