auth to server-V27

This commit is contained in:
Eric85710 2026-05-01 15:05:03 +08:00
parent cebf25a11c
commit 49cf0d408a
3 changed files with 39 additions and 2 deletions

View file

@ -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")

View file

@ -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
)

View file

@ -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()}")
}
}
}