Merge remote-tracking branch 'origin/nymos-dev'
This commit is contained in:
commit
4110c2118f
data/src/main/java/com/nto/data/repository
domain/src/main/java/com/nto/domain/repository
presentation/src/main
@ -7,8 +7,9 @@ import com.nto.data.models.cards.VisitCardWrapper
|
||||
|
||||
interface DataRepository {
|
||||
suspend fun auth(login: String, password: String): LoginResult
|
||||
suspend fun saveToken(token: String)
|
||||
suspend fun saveToken(token: String, login: String)
|
||||
suspend fun getToken(): String
|
||||
suspend fun getLogin(): String
|
||||
suspend fun getInfo(): UserDTO
|
||||
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||
}
|
@ -17,18 +17,22 @@ class DataRepositoryImpl @Inject constructor(@ApplicationContext private val con
|
||||
val result = Provider.provideRetrofit().auth(
|
||||
token
|
||||
).execute()
|
||||
if (result.isSuccessful) saveToken(token)
|
||||
if (result.isSuccessful) saveToken(token, login)
|
||||
return LoginResult(result.isSuccessful, result.message())
|
||||
}
|
||||
|
||||
override suspend fun saveToken(token: String) {
|
||||
context.getSharedPreferences("auth", MODE_PRIVATE).edit().putString("token", token).apply()
|
||||
override suspend fun saveToken(token: String, login: String) {
|
||||
context.getSharedPreferences("auth", MODE_PRIVATE).edit().putString("token", token).putString("login", login).apply()
|
||||
}
|
||||
|
||||
override suspend fun getToken(): String {
|
||||
return context.getSharedPreferences("auth", MODE_PRIVATE).getString("token", "")!!
|
||||
}
|
||||
|
||||
override suspend fun getLogin(): String {
|
||||
return context.getSharedPreferences("auth", MODE_PRIVATE).getString("login", "")!!
|
||||
}
|
||||
|
||||
override suspend fun getInfo(): UserDTO {
|
||||
val result = Provider.provideRetrofit().getInfo(getToken()).execute()
|
||||
return if (result.isSuccessful) result.body()!!
|
||||
|
@ -2,10 +2,12 @@ package com.nto.domain.repository
|
||||
|
||||
import com.nto.data.models.LoginResult
|
||||
import com.nto.data.models.UserDTO
|
||||
import com.nto.data.models.cards.VisitCardWrapper
|
||||
|
||||
interface DomainRepository {
|
||||
suspend fun auth(email: String, password: String): LoginResult
|
||||
suspend fun saveToken(token: String)
|
||||
suspend fun getToken(): String
|
||||
suspend fun saveToken(token: String, login: String)
|
||||
suspend fun getToken(): String?
|
||||
suspend fun getInfo(): UserDTO
|
||||
suspend fun getVisits(id: String): VisitCardWrapper
|
||||
}
|
@ -2,6 +2,7 @@ package com.nto.domain.repository
|
||||
|
||||
import com.nto.data.models.LoginResult
|
||||
import com.nto.data.models.UserDTO
|
||||
import com.nto.data.models.cards.VisitCardWrapper
|
||||
import com.nto.data.repository.DataRepositoryImpl
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
@ -11,23 +12,39 @@ class DomainRepositoryImpl @Inject constructor(private val dataRepositoryImpl: D
|
||||
override suspend fun auth(email: String, password: String): LoginResult {
|
||||
return try {
|
||||
dataRepositoryImpl.auth(
|
||||
login = email,
|
||||
password = password
|
||||
login = email, password = password
|
||||
)
|
||||
} catch (e: IOException) {
|
||||
LoginResult(false, "IO exception was thrown: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun saveToken(token: String) {
|
||||
dataRepositoryImpl.saveToken(token)
|
||||
override suspend fun saveToken(token: String, login: String) {
|
||||
dataRepositoryImpl.saveToken(token, login)
|
||||
}
|
||||
|
||||
override suspend fun getToken(): String {
|
||||
return dataRepositoryImpl.getToken()
|
||||
override suspend fun getToken(): String? {
|
||||
return try {
|
||||
dataRepositoryImpl.getToken()
|
||||
} catch (e: IOException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getInfo(): UserDTO{
|
||||
override suspend fun getInfo(): UserDTO {
|
||||
return try {
|
||||
return dataRepositoryImpl.getInfo()
|
||||
} catch (e: IOException) {
|
||||
UserDTO(isError = true)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getVisits(id: String): VisitCardWrapper {
|
||||
return try {
|
||||
dataRepositoryImpl.getVisits(id)
|
||||
} catch (e: IOException) {
|
||||
VisitCardWrapper(null, isUnauthorized = true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application
|
||||
android:name=".di.App"
|
||||
android:allowBackup="true"
|
||||
|
@ -87,7 +87,8 @@ fun DecoratedButton(
|
||||
true -> Disabled
|
||||
false -> Default
|
||||
}
|
||||
), onClick = onClick
|
||||
), onClick = onClick,
|
||||
enabled = !isDisabled
|
||||
) {
|
||||
Text(
|
||||
text,
|
||||
|
Loading…
x
Reference in New Issue
Block a user