63 lines
2.0 KiB
Kotlin
63 lines
2.0 KiB
Kotlin
package contacts.data.remote.api
|
|
|
|
import retrofit2.http.*
|
|
|
|
interface ContactApi {
|
|
@GET("contacts")
|
|
suspend fun getContacts(): List<ContactDto>
|
|
|
|
@POST("contacts/request")
|
|
suspend fun addContact(@Body request: AddContactRequest): Any
|
|
|
|
@DELETE("contacts/{userId}")
|
|
suspend fun removeContact(@Path("userId") userId: String)
|
|
|
|
@GET("profiles/search")
|
|
suspend fun searchUsers(@Query("q") query: String): List<ContactDto>
|
|
|
|
@GET("contacts/requests")
|
|
suspend fun getFriendRequests(): List<FriendRequestDto>
|
|
|
|
@POST("contacts/{friendshipId}/accept")
|
|
suspend fun acceptRequest(@Path("friendshipId") friendshipId: String): Any
|
|
|
|
@POST("contacts/{friendshipId}/decline")
|
|
suspend fun declineRequest(@Path("friendshipId") friendshipId: String): Any
|
|
}
|
|
|
|
data class FriendRequestDto(
|
|
val id: String,
|
|
val user: ContactDto,
|
|
val createdAt: String,
|
|
val isOutgoing: Boolean
|
|
)
|
|
|
|
data class ContactDto(
|
|
@com.google.gson.annotations.SerializedName("id")
|
|
val id: String,
|
|
@com.google.gson.annotations.SerializedName("userName")
|
|
val userName: String?,
|
|
@com.google.gson.annotations.SerializedName("username")
|
|
val username: String?,
|
|
@com.google.gson.annotations.SerializedName("displayName")
|
|
val displayName: String?,
|
|
@com.google.gson.annotations.SerializedName("avatarUrl")
|
|
val avatarUrl: String?,
|
|
@com.google.gson.annotations.SerializedName("avatar")
|
|
val avatar: String?,
|
|
@com.google.gson.annotations.SerializedName("isOnline")
|
|
val isOnline: Boolean,
|
|
@com.google.gson.annotations.SerializedName("lastSeen")
|
|
val lastSeen: String?,
|
|
@com.google.gson.annotations.SerializedName("friendshipId")
|
|
val friendshipId: String? = null
|
|
) {
|
|
val effectiveUsername: String get() = username ?: userName ?: "unknown"
|
|
val effectiveAvatarUrl: String? get() = avatarUrl ?: avatar
|
|
}
|
|
|
|
data class AddContactRequest(
|
|
@com.google.gson.annotations.SerializedName("contactId")
|
|
val contactId: String
|
|
)
|