auth to server-V27
This commit is contained in:
parent
cebf25a11c
commit
49cf0d408a
3 changed files with 39 additions and 2 deletions
|
|
@ -21,8 +21,8 @@ interface TecnologiaApi {
|
|||
suspend fun login(@Body body: LoginRequest): Response<LoginResponse>
|
||||
|
||||
// 取得個人資料:通常需要 Token
|
||||
@GET("api/me")
|
||||
suspend fun getMe(@Header("Authorization") token: String): Response<User>
|
||||
@GET("me")
|
||||
suspend fun getUserProfile(): Response<UserProfile>
|
||||
|
||||
// 發送好友請求
|
||||
@POST("api/friends/request")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.example.login_v3.data.api.api_class
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class UserProfile(
|
||||
val user_id: String,
|
||||
val username: String,
|
||||
val display_name: String,
|
||||
val email: String,
|
||||
val avatar_url: String?,
|
||||
val banner_url: String?,
|
||||
val bio: String?,
|
||||
val status: String,
|
||||
val is_active: Boolean,
|
||||
val is_verified: Boolean,
|
||||
val last_login: String,
|
||||
val created_at: String
|
||||
)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.example.login_v3.data.repository.basic
|
||||
|
||||
import com.example.login_v3.data.api.TecnologiaApi
|
||||
import com.example.login_v3.data.api.api_class.UserProfile
|
||||
import javax.inject.Inject
|
||||
|
||||
class Personal_Profile_Repository @Inject constructor(
|
||||
private val api: TecnologiaApi
|
||||
) {
|
||||
suspend fun getMyProfile(): UserProfile {
|
||||
val response = api.getUserProfile()
|
||||
if (response.isSuccessful) {
|
||||
return response.body()!!
|
||||
} else {
|
||||
throw Exception("API error: ${response.code()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue