Compare commits
No commits in common. "master" and "nikolays" have entirely different histories.
@ -2,5 +2,5 @@ package com.nto.data.models.cards
|
|||||||
|
|
||||||
data class VisitCardWrapper(
|
data class VisitCardWrapper(
|
||||||
val data: List<VisitCardDTO>?,
|
val data: List<VisitCardDTO>?,
|
||||||
val isError: Boolean = false,
|
val isUnauthorized: Boolean = false
|
||||||
)
|
)
|
||||||
|
@ -11,7 +11,7 @@ interface DataRepository {
|
|||||||
suspend fun getToken(): String
|
suspend fun getToken(): String
|
||||||
suspend fun getLogin(): String
|
suspend fun getLogin(): String
|
||||||
suspend fun getInfo(login: String): UserDTO
|
suspend fun getInfo(login: String): UserDTO
|
||||||
suspend fun getVisits(id: String): VisitCardWrapper
|
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||||
suspend fun open(): RequestResult
|
suspend fun open(): RequestResult
|
||||||
suspend fun logout()
|
suspend fun logout()
|
||||||
suspend fun invertLock(login: String, status: Boolean): RequestResult
|
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)
|
else UserDTO(isError = true, isUnauthorized = result.code() == 403)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getVisits(id: String): VisitCardWrapper {
|
override suspend fun getVisits(id: String?): VisitCardWrapper {
|
||||||
val result = Provider.provideRetrofit().getVisits(getToken(), id.ifBlank { getLogin() }).execute()
|
val result = Provider.provideRetrofit().getVisits(getToken()).execute()
|
||||||
return if (result.isSuccessful) {
|
return if (result.isSuccessful) {
|
||||||
VisitCardWrapper(result.body()!!)
|
VisitCardWrapper(result.body()!!)
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,7 +19,7 @@ interface RetrofitApi {
|
|||||||
fun getInfo(@Header("Authorization") token: String, @Path("login") login: String): Call<UserDTO>
|
fun getInfo(@Header("Authorization") token: String, @Path("login") login: String): Call<UserDTO>
|
||||||
|
|
||||||
@GET("visits/{login}/visits")
|
@GET("visits/{login}/visits")
|
||||||
fun getVisits(@Header("Authorization") token: String, @Path("login") login:String): Call<List<VisitCardDTO>>
|
fun getVisits(@Header("Authorization") token: String): Call<List<VisitCardDTO>>
|
||||||
|
|
||||||
@GET("visit/open")
|
@GET("visit/open")
|
||||||
fun open(@Header("Authorization") token: String): Call<ResponseBody>
|
fun open(@Header("Authorization") token: String): Call<ResponseBody>
|
||||||
|
@ -40,7 +40,7 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
|||||||
return try {
|
return try {
|
||||||
return dataRepositoryImpl.getInfo(login.ifBlank { getLogin() })
|
return dataRepositoryImpl.getInfo(login.ifBlank { getLogin() })
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
UserDTO(isError = true, isUnauthorized = true)
|
UserDTO(isError = true, isUnauthorized = true) //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
|||||||
return try {
|
return try {
|
||||||
dataRepositoryImpl.getVisits(id)
|
dataRepositoryImpl.getVisits(id)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
VisitCardWrapper(null, isError = true)
|
VisitCardWrapper(null, isUnauthorized = true) //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.nto.domain.usecase
|
package com.nto.domain.usecase
|
||||||
|
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
import com.nto.data.models.cards.VisitCardWrapper
|
|
||||||
import com.nto.domain.repository.DomainRepositoryImpl
|
import com.nto.domain.repository.DomainRepositoryImpl
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -12,7 +11,4 @@ class ProfileUseCase @Inject constructor(private val domainRepositoryImpl: Domai
|
|||||||
suspend fun logout(){
|
suspend fun logout(){
|
||||||
return domainRepositoryImpl.logout()
|
return domainRepositoryImpl.logout()
|
||||||
}
|
}
|
||||||
suspend fun getVisits(): VisitCardWrapper {
|
|
||||||
return domainRepositoryImpl.getVisits("")
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ data class ProfileState(
|
|||||||
var lastOpen: String = "",
|
var lastOpen: String = "",
|
||||||
var job: String = "",
|
var job: String = "",
|
||||||
var isUnauthorized: Boolean = false,
|
var isUnauthorized: Boolean = false,
|
||||||
var visits: List<VisitCardDTO> = listOf()
|
val visits: List<VisitCardDTO> = listOf()
|
||||||
) {
|
) {
|
||||||
fun deserialize(o: UserDTO, context: Context) {
|
fun deserialize(o: UserDTO, context: Context) {
|
||||||
val dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
val dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -38,13 +38,7 @@ class ProfileViewModel @Inject constructor(
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
_isLoading = true
|
_isLoading = true
|
||||||
val result = useCase.getInfo()
|
val result = useCase.getInfo()
|
||||||
val visitsResult = useCase.getVisits()
|
_state.tryEmit(ProfileState().apply { deserialize(result, context) })
|
||||||
_state.tryEmit(ProfileState().apply {
|
|
||||||
deserialize(result, context)
|
|
||||||
if(!visitsResult.isError) {
|
|
||||||
visits = visitsResult.data!!
|
|
||||||
}
|
|
||||||
})
|
|
||||||
_isLoading = false
|
_isLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user