Add VisitCardWrapper
This commit is contained in:
parent
8c5e8a5229
commit
04073743f5
@ -0,0 +1,6 @@
|
|||||||
|
package com.nto.data.models.cards
|
||||||
|
|
||||||
|
data class VisitCardWrapper(
|
||||||
|
val data: List<VisitCardDTO>?,
|
||||||
|
val isUnauthorized: Boolean = false
|
||||||
|
)
|
@ -2,10 +2,13 @@ package com.nto.data.repository
|
|||||||
|
|
||||||
import com.nto.data.models.LoginResult
|
import com.nto.data.models.LoginResult
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardWrapper
|
||||||
|
|
||||||
interface DataRepository {
|
interface DataRepository {
|
||||||
suspend fun auth(login: String, password: String): LoginResult
|
suspend fun auth(login: String, password: String): LoginResult
|
||||||
suspend fun saveToken(token: String)
|
suspend fun saveToken(token: String)
|
||||||
suspend fun getToken(): String
|
suspend fun getToken(): String
|
||||||
suspend fun getInfo(): UserDTO
|
suspend fun getInfo(): UserDTO
|
||||||
|
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.content.Context.MODE_PRIVATE
|
import android.content.Context.MODE_PRIVATE
|
||||||
import com.nto.data.models.LoginResult
|
import com.nto.data.models.LoginResult
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardWrapper
|
||||||
import com.nto.data.utils.Provider
|
import com.nto.data.utils.Provider
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import okhttp3.Credentials
|
import okhttp3.Credentials
|
||||||
@ -34,4 +35,13 @@ 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 {
|
||||||
|
val result = Provider.provideRetrofit().getVisits(getToken()).execute()
|
||||||
|
return if (result.isSuccessful) {
|
||||||
|
VisitCardWrapper(result.body()!!)
|
||||||
|
} else {
|
||||||
|
VisitCardWrapper(null, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.nto.data.utils
|
package com.nto.data.utils
|
||||||
|
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardDTO
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -12,4 +13,7 @@ interface RetrofitApi {
|
|||||||
|
|
||||||
@GET("employee/info")
|
@GET("employee/info")
|
||||||
fun getInfo(@Header("Authorization") token: String): Call<UserDTO>
|
fun getInfo(@Header("Authorization") token: String): Call<UserDTO>
|
||||||
|
|
||||||
|
@GET("visits/{login}/visits")
|
||||||
|
fun getVisits(@Header("Authorization") token: String): Call<List<VisitCardDTO>>
|
||||||
}
|
}
|
@ -57,10 +57,9 @@ fun ProfileScreen(
|
|||||||
) {
|
) {
|
||||||
val state = viewModel.state.collectAsState().value
|
val state = viewModel.state.collectAsState().value
|
||||||
|
|
||||||
val scannerLauncher = rememberLauncherForActivityResult(
|
val scannerLauncher = rememberLauncherForActivityResult(contract = ScanContract(),
|
||||||
contract = ScanContract(),
|
onResult = { result -> Log.i(TAG, "scanned code: ${result.contents}") })
|
||||||
onResult = { result -> Log.i(TAG, "scanned code: ${result.contents}") }
|
|
||||||
)
|
|
||||||
val scanOptions = ScanOptions()
|
val scanOptions = ScanOptions()
|
||||||
scanOptions.setPrompt("")
|
scanOptions.setPrompt("")
|
||||||
scanOptions.setBeepEnabled(false)
|
scanOptions.setBeepEnabled(false)
|
||||||
@ -70,7 +69,7 @@ fun ProfileScreen(
|
|||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
if (state.isUnauthorized) {
|
if (state.isUnauthorized) {
|
||||||
//navController.navigate(Destinations.Login)
|
navController.navigate(Destinations.Login)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +190,7 @@ fun ProfileScreen(
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(10.dp))
|
Spacer(modifier = Modifier.height(10.dp))
|
||||||
Text(
|
Text(
|
||||||
state.job,
|
state.job, style = NTOTheme.typography.placeholder, color = TextGray
|
||||||
style = NTOTheme.typography.placeholder,
|
|
||||||
color = TextGray
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user