block un block usecase
This commit is contained in:
parent
8c92180a56
commit
d5e4411767
@ -60,4 +60,30 @@ class UserNetworkDataSource {
|
||||
result.body<Boolean>()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun block(login : String) : Result<Boolean> = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val result = client.patch("$SERVER_ADDRESS/api/{login}/block") {
|
||||
header(HttpHeaders.Authorization, token)
|
||||
}
|
||||
Log.d("result", "${result.status}")
|
||||
if (result.status != HttpStatusCode.OK) {
|
||||
error("Status ${result.status}")
|
||||
}
|
||||
result.body<Boolean>()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun unBlock(login : String) : Result<Boolean> = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val result = client.patch("$SERVER_ADDRESS/api/{login}/unblock") {
|
||||
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.contracts.Returns
|
||||
import kotlin.math.log
|
||||
|
||||
|
||||
@ -44,5 +45,11 @@ class UserRepoImpl (
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun block(login: String): Result<Boolean> {
|
||||
return userNetworkDataSource.block(login);
|
||||
}
|
||||
|
||||
override suspend fun unblock(login: String): Result<Boolean> {
|
||||
return userNetworkDataSource.block(login);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package ru.myitschool.work.domain.user
|
||||
|
||||
import ru.myitschool.work.data.auth.AuthStorageDataSource
|
||||
import ru.myitschool.work.data.user.UserDto
|
||||
|
||||
|
||||
public class BlockUseCase (
|
||||
private val repo: UserRepo,
|
||||
private val authStorageDataSource : AuthStorageDataSource
|
||||
){
|
||||
private fun getUserFromStorage() : UserDto? {
|
||||
return authStorageDataSource.userInfo
|
||||
}
|
||||
suspend operator fun invoke(value : String) = repo.block(getUserFromStorage()?.login!!)
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package ru.myitschool.work.domain.user
|
||||
|
||||
import ru.myitschool.work.data.auth.AuthStorageDataSource
|
||||
import ru.myitschool.work.data.user.UserDto
|
||||
|
||||
|
||||
public class UnBlockUseCase (
|
||||
private val repo: UserRepo,
|
||||
private val authStorageDataSource : AuthStorageDataSource
|
||||
){
|
||||
private fun getUserFromStorage() : UserDto? {
|
||||
return authStorageDataSource.userInfo
|
||||
}
|
||||
suspend operator fun invoke(value : String) = repo.unblock(getUserFromStorage()?.login!!)
|
||||
}
|
@ -5,4 +5,6 @@ interface UserRepo {
|
||||
suspend fun getUser(login: String) : Result<UserEntity>
|
||||
suspend fun getEntrancesList(login : String) : Result<List<EntranceEntity>>
|
||||
suspend fun enter(value : String, login : String) : Result<Boolean>
|
||||
suspend fun block(login: String): Result<Boolean>
|
||||
suspend fun unblock(login: String): Result<Boolean>
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user