Files
forkmessager/client-mobile/contacts/data/repository/ContactRepositoryImpl.kt
2026-04-16 15:41:22 +03:00

75 lines
2.6 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package contacts.data.repository
import contacts.data.remote.api.ContactApi
import contacts.data.remote.api.ContactDto
import contacts.domain.repository.ContactRepository
import javax.inject.Inject
class ContactRepositoryImpl @Inject constructor(
private val api: ContactApi
) : ContactRepository {
override suspend fun getContacts(): Result<List<ContactDto>> {
return try {
Result.success(api.getContacts())
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun addContact(userId: String): Result<ContactDto> {
return try {
val response = api.addContact(contacts.data.remote.api.AddContactRequest(userId))
// Бэкенд возвращает статус или пустой ответ для запроса,
// так как это "запрос в друзья". Мы возвращаем Result.success с пустым DTO или
// по-хорошему надо обновить доменную модель, но для начала вернем заглушку.
Result.success(ContactDto(id = userId, userName = null, username = null, displayName = null, avatarUrl = null, avatar = null, isOnline = false, lastSeen = null))
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun removeContact(userId: String): Result<Unit> {
return try {
api.removeContact(userId)
Result.success(Unit)
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun searchUsers(query: String): Result<List<ContactDto>> {
return try {
Result.success(api.searchUsers(query))
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun getFriendRequests(): Result<List<contacts.data.remote.api.FriendRequestDto>> {
return try {
Result.success(api.getFriendRequests())
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun acceptRequest(friendshipId: String): Result<Unit> {
return try {
api.acceptRequest(friendshipId)
Result.success(Unit)
} catch (e: Exception) {
Result.failure(e)
}
}
override suspend fun declineRequest(friendshipId: String): Result<Unit> {
return try {
api.declineRequest(friendshipId)
Result.success(Unit)
} catch (e: Exception) {
Result.failure(e)
}
}
}