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