Профиль, редактирование без аватара
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user