Tweak backend methods
This commit is contained in:
parent
64dddb4495
commit
8dae85d136
@ -8,8 +8,8 @@ enum class Position {
|
||||
|
||||
data class UserDTO(
|
||||
val firstName: String = "",
|
||||
val secondName: String = "",
|
||||
val thirdName: String = "",
|
||||
val lastName: String = "",
|
||||
val patronymic: String = "",
|
||||
val position: Position = Position.DEVELOPER,
|
||||
val lastVisit: LocalDateTime = LocalDateTime.now(),
|
||||
val isError: Boolean = false,
|
||||
|
@ -10,7 +10,7 @@ interface DataRepository {
|
||||
suspend fun saveToken(token: String, login: String)
|
||||
suspend fun getToken(): String
|
||||
suspend fun getLogin(): String
|
||||
suspend fun getInfo(): UserDTO
|
||||
suspend fun getInfo(login: String): UserDTO
|
||||
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||
suspend fun open(): RequestResult
|
||||
suspend fun logout()
|
||||
|
@ -35,8 +35,8 @@ class DataRepositoryImpl @Inject constructor(@ApplicationContext private val con
|
||||
return context.getSharedPreferences("auth", MODE_PRIVATE).getString("login", "")!!
|
||||
}
|
||||
|
||||
override suspend fun getInfo(): UserDTO {
|
||||
val result = Provider.provideRetrofit().getInfo(getToken()).execute()
|
||||
override suspend fun getInfo(login: String): UserDTO {
|
||||
val result = Provider.provideRetrofit().getInfo(token = getToken(), login = login).execute()
|
||||
return if (result.isSuccessful) result.body()!!
|
||||
else UserDTO(isError = true, isUnauthorized = result.code() == 403)
|
||||
}
|
||||
|
@ -8,14 +8,15 @@ 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 {
|
||||
@GET("employee/auth")
|
||||
fun auth(@Header("Authorization") token: String): Call<ResponseBody>
|
||||
|
||||
@GET("employee/info")
|
||||
fun getInfo(@Header("Authorization") token: String): Call<UserDTO>
|
||||
@GET("employee/{login}/info")
|
||||
fun getInfo(@Header("Authorization") token: String, @Path("login") login: String): Call<UserDTO>
|
||||
|
||||
@GET("visits/{login}/visits")
|
||||
fun getVisits(@Header("Authorization") token: String): Call<List<VisitCardDTO>>
|
||||
|
@ -9,7 +9,8 @@ interface DomainRepository {
|
||||
suspend fun auth(email: String, password: String): LoginResult
|
||||
suspend fun saveToken(token: String, login: String)
|
||||
suspend fun getToken(): String?
|
||||
suspend fun getInfo(): UserDTO
|
||||
suspend fun getLogin(): String
|
||||
suspend fun getInfo(login: String): UserDTO
|
||||
suspend fun getVisits(id: String): VisitCardWrapper
|
||||
suspend fun open(): RequestResult
|
||||
suspend fun logout()
|
||||
|
@ -32,9 +32,13 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getInfo(): UserDTO {
|
||||
override suspend fun getLogin(): String {
|
||||
return dataRepositoryImpl.getLogin()
|
||||
}
|
||||
|
||||
override suspend fun getInfo(login: String): UserDTO {
|
||||
return try {
|
||||
return dataRepositoryImpl.getInfo()
|
||||
return dataRepositoryImpl.getInfo(login.ifBlank { getLogin() })
|
||||
} catch (e: IOException) {
|
||||
UserDTO(isError = true, isUnauthorized = true) //TODO
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import javax.inject.Inject
|
||||
|
||||
class ProfileUseCase @Inject constructor(private val domainRepositoryImpl: DomainRepositoryImpl) {
|
||||
suspend fun getInfo(): UserDTO{
|
||||
return domainRepositoryImpl.getInfo()
|
||||
return domainRepositoryImpl.getInfo("")
|
||||
}
|
||||
suspend fun logout(){
|
||||
return domainRepositoryImpl.logout()
|
||||
|
@ -9,9 +9,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.nto.presentation.composable.Navigation
|
||||
import com.nto.presentation.screens.splashScreen.SplashScreenViewModel
|
||||
|
@ -5,7 +5,6 @@ import com.nto.data.models.Position
|
||||
import com.nto.data.models.UserDTO
|
||||
import com.nto.data.models.cards.VisitCardDTO
|
||||
import com.nto.presentation.R
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
data class ProfileState(
|
||||
@ -20,12 +19,12 @@ data class ProfileState(
|
||||
fun deserialize(o: UserDTO, context: Context) {
|
||||
val dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
this.firstName = o.firstName
|
||||
this.secondName = o.secondName
|
||||
this.thirdName = o.thirdName
|
||||
this.secondName = o.lastName
|
||||
this.thirdName = o.patronymic
|
||||
this.lastOpen = try {
|
||||
o.lastVisit.format(dateFormat)
|
||||
} catch (e: NullPointerException) {
|
||||
"Exception!"
|
||||
context.getString(R.string.label_last_visit_none)
|
||||
}
|
||||
this.job = translatePosition(o.position, context)
|
||||
this.isUnauthorized = o.isUnauthorized
|
||||
|
@ -22,4 +22,5 @@
|
||||
<string name="code_scanned_error">Enter was cancelled</string>
|
||||
<string name="code_scanned_warning">Something went wrong</string>
|
||||
<string name="close">Close</string>
|
||||
<string name="label_last_visit_none">None</string>
|
||||
</resources>
|
@ -23,4 +23,5 @@
|
||||
<string name="code_scanned_error">Вход был отменён</string>
|
||||
<string name="code_scanned_warning">Что-то пошло не так</string>
|
||||
<string name="close">Закрыть</string>
|
||||
<string name="label_last_visit_none">Нет</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user