auth to server-V101

This commit is contained in:
Eric85710 2026-05-14 15:11:09 +08:00
parent 19dfb5d55d
commit 4b3ccf1107

View file

@ -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)
}
}
}