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