refactoring
This commit is contained in:
parent
69ddacabcf
commit
bbc19ecd48
@ -18,12 +18,12 @@ public interface ApiService {
|
|||||||
@GET("/api/{LOGIN}/auth")
|
@GET("/api/{LOGIN}/auth")
|
||||||
suspend fun auth(@Path("LOGIN") login: String): ResponseBody
|
suspend fun auth(@Path("LOGIN") login: String): ResponseBody
|
||||||
|
|
||||||
@GET("/api/info")
|
@GET("/api/info/")
|
||||||
suspend fun info(@Header("Authorization") token: String): Response<User>
|
suspend fun info(@Header("Authorization") token: String): Response<User>
|
||||||
|
|
||||||
@PATCH("/api/open")
|
@PATCH("/api/open/")
|
||||||
suspend fun open(@Header("Authorization") token: String, @Body data: Door): Response<DoorResponse>
|
suspend fun open(@Header("Authorization") token: String, @Body data: Long): Response<DoorResponse>
|
||||||
|
|
||||||
@POST("/api/login")
|
@POST("/api/login/")
|
||||||
suspend fun login(@Body data: Auth): Response<AuthResponse>
|
suspend fun login(@Body data: Auth): Response<AuthResponse>
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
package com.example.nto_minipigs.Retrofit.Models
|
package com.example.nto_minipigs.Retrofit.Models
|
||||||
|
|
||||||
data class Door(
|
data class Door(
|
||||||
val id: String
|
val id: Long
|
||||||
)
|
)
|
@ -46,7 +46,7 @@ fun QRScreen(navController: NavController, viewModel: QRViewModel, dataStore: Us
|
|||||||
scanFlag = true
|
scanFlag = true
|
||||||
this.pause()
|
this.pause()
|
||||||
|
|
||||||
viewModel.Fetch(barCodeOrQr, login, password)
|
viewModel.Fetch(barCodeOrQr.toLong(), login, password)
|
||||||
navController.navigate(QRResult)
|
navController.navigate(QRResult)
|
||||||
}
|
}
|
||||||
//If you don't put this scanFlag = false, it will never work again.
|
//If you don't put this scanFlag = false, it will never work again.
|
||||||
|
@ -16,15 +16,14 @@ class QRViewModel: ViewModel() {
|
|||||||
private val _data = MutableLiveData<NetworkResponse<DoorResponse>>()
|
private val _data = MutableLiveData<NetworkResponse<DoorResponse>>()
|
||||||
val data : LiveData<NetworkResponse<DoorResponse>> = _data
|
val data : LiveData<NetworkResponse<DoorResponse>> = _data
|
||||||
|
|
||||||
fun Fetch(id: String, login:String, password:String) {
|
fun Fetch(id: Long, login:String, password:String) {
|
||||||
_data.value = NetworkResponse.Loading
|
_data.value = NetworkResponse.Loading
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if(id != null) {
|
if(id != null) {
|
||||||
try {
|
try {
|
||||||
val request = Door(id)
|
|
||||||
var basic = Credentials.basic(login.toString(), password.toString())
|
var basic = Credentials.basic(login.toString(), password.toString())
|
||||||
val response = serviceApi.open(basic, request)
|
val response = serviceApi.open(basic, id)
|
||||||
if(response.isSuccessful) {
|
if(response.isSuccessful) {
|
||||||
response.body()?.let {
|
response.body()?.let {
|
||||||
_data.value = NetworkResponse.Success(it)
|
_data.value = NetworkResponse.Success(it)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user