add EnterUseCase
This commit is contained in:
parent
a926afbd3d
commit
90727a314b
@ -4,6 +4,7 @@ import android.util.Log
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.patch
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpStatusCode
|
||||
@ -46,4 +47,17 @@ class UserNetworkDataSource {
|
||||
}
|
||||
|
||||
}
|
||||
suspend fun enter(value : Long, login : String): Result<Boolean> = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val result = client.patch("$SERVER_ADDRESS/api/open") {
|
||||
header(HttpHeaders.Authorization, token)
|
||||
|
||||
}
|
||||
Log.d("result", "${result.status}")
|
||||
if (result.status != HttpStatusCode.OK) {
|
||||
error("Status ${result.status}")
|
||||
}
|
||||
result.body<Boolean>()
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package ru.myitschool.work.data.user
|
||||
import ru.myitschool.work.domain.user.EntranceEntity
|
||||
import ru.myitschool.work.domain.user.UserEntity
|
||||
import ru.myitschool.work.domain.user.UserRepo
|
||||
import kotlin.math.log
|
||||
|
||||
|
||||
class UserRepoImpl (
|
||||
@ -28,12 +29,20 @@ class UserRepoImpl (
|
||||
userList.map { it.toEntity() }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun enter(value: Long, login : String): Result<Boolean> {
|
||||
return userNetworkDataSource.enter(value, login);
|
||||
}
|
||||
|
||||
fun EntranceDto.toEntity(): EntranceEntity {
|
||||
return EntranceEntity(
|
||||
login = login,
|
||||
name = this.name,
|
||||
enteredAt = this.enteredAt,
|
||||
|
||||
enterType = this.enterType
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package ru.myitschool.work.domain.user
|
||||
|
||||
import ru.myitschool.work.data.auth.AuthStorageDataSource
|
||||
import ru.myitschool.work.data.user.UserDto
|
||||
|
||||
class EnterUseCase (
|
||||
private val repo: UserRepo,
|
||||
private val authStorageDataSource : AuthStorageDataSource
|
||||
) {
|
||||
private fun getUserFromStorage() : UserDto? {
|
||||
return authStorageDataSource.userInfo
|
||||
}
|
||||
suspend operator fun invoke(value : Long) = repo.enter(value, getUserFromStorage()?.login!!)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package ru.myitschool.work.domain.user
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
|
@ -4,4 +4,5 @@ package ru.myitschool.work.domain.user
|
||||
interface UserRepo {
|
||||
suspend fun getUser(login: String) : Result<UserEntity>
|
||||
suspend fun getEntrancesList(login : String) : Result<List<EntranceEntity>>
|
||||
suspend fun enter(value : Long, login : String) : Result<Boolean>
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user