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 {
|
interface DataRepository {
|
||||||
suspend fun auth(login: String, password: String): LoginResult
|
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 getToken(): String
|
||||||
|
suspend fun getLogin(): String
|
||||||
suspend fun getInfo(): UserDTO
|
suspend fun getInfo(): UserDTO
|
||||||
suspend fun getVisits(id: String?): VisitCardWrapper
|
suspend fun getVisits(id: String?): VisitCardWrapper
|
||||||
}
|
}
|
@ -17,18 +17,22 @@ class DataRepositoryImpl @Inject constructor(@ApplicationContext private val con
|
|||||||
val result = Provider.provideRetrofit().auth(
|
val result = Provider.provideRetrofit().auth(
|
||||||
token
|
token
|
||||||
).execute()
|
).execute()
|
||||||
if (result.isSuccessful) saveToken(token)
|
if (result.isSuccessful) saveToken(token, login)
|
||||||
return LoginResult(result.isSuccessful, result.message())
|
return LoginResult(result.isSuccessful, result.message())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveToken(token: String) {
|
override suspend fun saveToken(token: String, login: String) {
|
||||||
context.getSharedPreferences("auth", MODE_PRIVATE).edit().putString("token", token).apply()
|
context.getSharedPreferences("auth", MODE_PRIVATE).edit().putString("token", token).putString("login", login).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getToken(): String {
|
override suspend fun getToken(): String {
|
||||||
return context.getSharedPreferences("auth", MODE_PRIVATE).getString("token", "")!!
|
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 {
|
override suspend fun getInfo(): UserDTO {
|
||||||
val result = Provider.provideRetrofit().getInfo(getToken()).execute()
|
val result = Provider.provideRetrofit().getInfo(getToken()).execute()
|
||||||
return if (result.isSuccessful) result.body()!!
|
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.LoginResult
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardWrapper
|
||||||
|
|
||||||
interface DomainRepository {
|
interface DomainRepository {
|
||||||
suspend fun auth(email: String, password: String): LoginResult
|
suspend fun auth(email: String, password: String): LoginResult
|
||||||
suspend fun saveToken(token: String)
|
suspend fun saveToken(token: String, login: String)
|
||||||
suspend fun getToken(): String
|
suspend fun getToken(): String?
|
||||||
suspend fun getInfo(): UserDTO
|
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.LoginResult
|
||||||
import com.nto.data.models.UserDTO
|
import com.nto.data.models.UserDTO
|
||||||
|
import com.nto.data.models.cards.VisitCardWrapper
|
||||||
import com.nto.data.repository.DataRepositoryImpl
|
import com.nto.data.repository.DataRepositoryImpl
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import javax.inject.Inject
|
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 {
|
override suspend fun auth(email: String, password: String): LoginResult {
|
||||||
return try {
|
return try {
|
||||||
dataRepositoryImpl.auth(
|
dataRepositoryImpl.auth(
|
||||||
login = email,
|
login = email, password = password
|
||||||
password = password
|
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
LoginResult(false, "IO exception was thrown: ${e.message}")
|
LoginResult(false, "IO exception was thrown: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveToken(token: String) {
|
override suspend fun saveToken(token: String, login: String) {
|
||||||
dataRepositoryImpl.saveToken(token)
|
dataRepositoryImpl.saveToken(token, login)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getToken(): String {
|
override suspend fun getToken(): String? {
|
||||||
return dataRepositoryImpl.getToken()
|
return try {
|
||||||
|
dataRepositoryImpl.getToken()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getInfo(): UserDTO{
|
override suspend fun getInfo(): UserDTO {
|
||||||
|
return try {
|
||||||
return dataRepositoryImpl.getInfo()
|
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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<application
|
<application
|
||||||
android:name=".di.App"
|
android:name=".di.App"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -87,7 +87,8 @@ fun DecoratedButton(
|
|||||||
true -> Disabled
|
true -> Disabled
|
||||||
false -> Default
|
false -> Default
|
||||||
}
|
}
|
||||||
), onClick = onClick
|
), onClick = onClick,
|
||||||
|
enabled = !isDisabled
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text,
|
text,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user