auth to server-V71

This commit is contained in:
Eric85710 2026-05-08 16:28:42 +08:00
parent 142b6b337d
commit fcfc70c386
2 changed files with 20 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
interface TecnologiaApi {
@ -50,7 +51,10 @@ interface TecnologiaApi {
// friends
@GET("api/friends")
suspend fun getFriends(): FriendListResponse
@GET("api/friends/pending")
suspend fun getFriendsPending(): PendingFriendsResponse
@POST("api/friends/{id}/accept")
suspend fun acceptFriendRequest(
@Path("id") friendshipId: String
): Response<Unit>
}

View file

@ -21,6 +21,8 @@ class FriendsRepository @Inject constructor(
}
}
//pending list
suspend fun getPendingRequests(): Result<List<PendingFriendApiModel>> {
return try {
val response = apiService.getFriendsPending()
@ -30,4 +32,17 @@ class FriendsRepository @Inject constructor(
Result.failure(e)
}
}
suspend fun acceptFriendRequest(friendshipId: String): Result<Unit> {
return try {
val response = apiService.acceptFriendRequest(friendshipId)
if (response.isSuccessful) {
Result.success(Unit)
} else {
Result.failure(Exception("接受失敗: ${response.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}