auth to server-V101
This commit is contained in:
parent
19dfb5d55d
commit
4b3ccf1107
1 changed files with 24 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.example.login_v3.data.repository.dm
|
||||||
|
|
||||||
|
import com.example.login_v3.data.api.TecnologiaApi
|
||||||
|
import com.example.login_v3.data.api.api_class.RoomListResponse
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton // 如果你希望整個 App 週期內只存在一個實體
|
||||||
|
class ChatRoomsRepository @Inject constructor(
|
||||||
|
private val api: TecnologiaApi
|
||||||
|
) {
|
||||||
|
suspend fun fetchRooms(): Result<RoomListResponse> {
|
||||||
|
return try {
|
||||||
|
val response = api.getChatRooms()
|
||||||
|
if (response.isSuccessful && response.body() != null) {
|
||||||
|
Result.success(response.body()!!)
|
||||||
|
} else {
|
||||||
|
Result.failure(Exception("Error code: ${response.code()}"))
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Result.failure(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue