Tweak backend methods
This commit is contained in:
parent
0d24787c17
commit
7afe153706
@ -2,5 +2,5 @@ package com.nto.data.models.cards
|
||||
|
||||
data class VisitCardWrapper(
|
||||
val data: List<VisitCardDTO>?,
|
||||
val isUnauthorized: Boolean = false
|
||||
val isError: Boolean = false,
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ interface DataRepository {
|
||||
suspend fun getToken(): String
|
||||
suspend fun getLogin(): String
|
||||
suspend fun getInfo(): UserDTO
|
||||
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||
suspend fun getVisits(id: String): VisitCardWrapper
|
||||
suspend fun open(): RequestResult
|
||||
suspend fun logout()
|
||||
suspend fun invertLock(login: String, status: Boolean): RequestResult
|
||||
|
@ -41,8 +41,8 @@ class DataRepositoryImpl @Inject constructor(@ApplicationContext private val con
|
||||
else UserDTO(isError = true, isUnauthorized = result.code() == 403)
|
||||
}
|
||||
|
||||
override suspend fun getVisits(id: String?): VisitCardWrapper {
|
||||
val result = Provider.provideRetrofit().getVisits(getToken()).execute()
|
||||
override suspend fun getVisits(id: String): VisitCardWrapper {
|
||||
val result = Provider.provideRetrofit().getVisits(getToken(), id.ifBlank { getLogin() }).execute()
|
||||
return if (result.isSuccessful) {
|
||||
VisitCardWrapper(result.body()!!)
|
||||
} else {
|
||||
|
@ -8,6 +8,7 @@ import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface RetrofitApi {
|
||||
@ -18,7 +19,7 @@ interface RetrofitApi {
|
||||
fun getInfo(@Header("Authorization") token: String): Call<UserDTO>
|
||||
|
||||
@GET("visits/{login}/visits")
|
||||
fun getVisits(@Header("Authorization") token: String): Call<List<VisitCardDTO>>
|
||||
fun getVisits(@Header("Authorization") token: String, @Path("login") login:String): Call<List<VisitCardDTO>>
|
||||
|
||||
@GET("visit/open")
|
||||
fun open(@Header("Authorization") token: String): Call<ResponseBody>
|
||||
|
@ -36,7 +36,7 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
||||
return try {
|
||||
return dataRepositoryImpl.getInfo()
|
||||
} catch (e: IOException) {
|
||||
UserDTO(isError = true, isUnauthorized = true) //TODO
|
||||
UserDTO(isError = true, isUnauthorized = true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
||||
return try {
|
||||
dataRepositoryImpl.getVisits(id)
|
||||
} catch (e: IOException) {
|
||||
VisitCardWrapper(null, isUnauthorized = true) //TODO
|
||||
VisitCardWrapper(null, isError = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.nto.domain.usecase
|
||||
|
||||
import com.nto.data.models.UserDTO
|
||||
import com.nto.data.models.cards.VisitCardWrapper
|
||||
import com.nto.domain.repository.DomainRepositoryImpl
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -11,4 +12,7 @@ class ProfileUseCase @Inject constructor(private val domainRepositoryImpl: Domai
|
||||
suspend fun logout(){
|
||||
return domainRepositoryImpl.logout()
|
||||
}
|
||||
suspend fun getVisits(): VisitCardWrapper {
|
||||
return domainRepositoryImpl.getVisits("")
|
||||
}
|
||||
}
|
@ -49,6 +49,7 @@ class ProfileViewModel @Inject constructor(
|
||||
fun updateInfo() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val result = useCase.getInfo()
|
||||
//val visits = useCase.get
|
||||
_state.tryEmit(ProfileState().apply { deserialize(result, context) })
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user