auth to server-V1

This commit is contained in:
Eric85710 2026-04-27 18:18:12 +08:00
parent f25fa44481
commit ff86c28ee0
2 changed files with 18 additions and 11 deletions

View file

@ -1,11 +1,7 @@
package com.example.login_v3.data.api package com.example.login_v3.data.api
import com.example.login_v3.data.api.api_class.ApiResponse import com.example.login_v3.data.api.api_class.*
import com.example.login_v3.data.api.api_class.FriendRequest
import com.example.login_v3.data.api.api_class.LoginRequest
import com.example.login_v3.data.api.api_class.LoginResponse
import retrofit2.Response import retrofit2.Response
import com.example.login_v3.data.api.api_class.User
import retrofit2.http.Body import retrofit2.http.Body
import retrofit2.http.GET import retrofit2.http.GET
import retrofit2.http.Header import retrofit2.http.Header
@ -14,20 +10,24 @@ import retrofit2.http.POST
interface TecnologiaApi { interface TecnologiaApi {
@GET("api/health") @GET("api/health")
// 必須包裹在 Response<> 裡面,才能呼叫 .isSuccessful
suspend fun checkHealth(): Response<Unit> suspend fun checkHealth(): Response<Unit>
// 註冊:建議路徑 api/auth/register
@POST("api/auth/register")
suspend fun register(@Body body: RegisterRequest): Response<ApiResponse>
// 登入:將回傳值包裹在 Response 中
@POST("api/auth/login") @POST("api/auth/login")
suspend fun login(@Body body: LoginRequest): LoginResponse suspend fun login(@Body body: LoginRequest): Response<LoginResponse>
// 取得個人資料:通常需要 Token
@GET("api/me") @GET("api/me")
suspend fun getMe(@Header("Authorization") token: String): User suspend fun getMe(@Header("Authorization") token: String): Response<User>
// 發送好友請求
@POST("api/friends/request") @POST("api/friends/request")
suspend fun sendFriendRequest( suspend fun sendFriendRequest(
@Header("Authorization") token: String, @Header("Authorization") token: String,
@Body body: FriendRequest @Body body: FriendRequest
): ApiResponse ): Response<ApiResponse>
// 其他 endpoint 一樣加
} }

View file

@ -9,3 +9,10 @@ data class LoginResponse(
val token: String, val token: String,
val userId: String val userId: String
) )
data class RegisterRequest(
val display_name: String,
val email: String,
val password: String,
val username: String
)