auth to server-V28

This commit is contained in:
Eric85710 2026-05-01 15:07:43 +08:00
parent 49cf0d408a
commit e96e3d9843

View file

@ -4,15 +4,17 @@ import com.example.login_v3.data.api.TecnologiaApi
import com.example.login_v3.data.api.api_class.UserProfile import com.example.login_v3.data.api.api_class.UserProfile
import javax.inject.Inject import javax.inject.Inject
class Personal_Profile_Repository @Inject constructor( class PersonalProfileRepository @Inject constructor(
private val api: TecnologiaApi private val api: TecnologiaApi
) { ) {
suspend fun getMyProfile(): UserProfile { suspend fun getMyProfile(): UserProfile {
val response = api.getUserProfile() val response = api.getUserProfile()
if (response.isSuccessful) { if (response.isSuccessful) {
return response.body()!! // body()!! 雖然簡單,但建議確保 API 回傳格式正確
return response.body() ?: throw Exception("回傳資料為空")
} else { } else {
throw Exception("API error: ${response.code()}") // 這裡可以根據 response.code() 給出更詳細的錯誤訊息
throw Exception("讀取失敗 (${response.code()})")
} }
} }
} }