temporal potentially working variant (bot not building
This commit is contained in:
features
auth
client
common
client
src
jsMain
kotlin
dev
inmo
postssystem
features
common
common
content
binary
client
src
jsMain
kotlin
dev
inmo
postssystem
features
content
binary
client
src
jsMain
kotlin
dev
inmo
postssystem
features
content
client
text
client
src
jsMain
kotlin
dev
inmo
postssystem
features
content
text
posts
common
src
commonMain
kotlin
dev
inmo
postssystem
features
posts
common
roles
client
src
commonMain
kotlin
dev
inmo
postssystem
features
services/posts/client/src
commonMain
kotlin
dev
inmo
postssystem
services
jsMain
kotlin
dev
inmo
postssystem
services
posts
client
31
features/roles/client/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/client/DefaultRolesSettings.kt
Normal file
31
features/roles/client/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/client/DefaultRolesSettings.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.inmo.postssystem.features.roles.client
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.plus
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.postssystem.features.auth.client.settings.AuthSettings
|
||||
import dev.inmo.postssystem.features.roles.common.Role
|
||||
import dev.inmo.postssystem.features.roles.common.RolesStorage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import org.koin.core.Koin
|
||||
|
||||
class DefaultRolesSettings(
|
||||
private val koin: Koin,
|
||||
private val authSettings: AuthSettings,
|
||||
private val scope: CoroutineScope
|
||||
) : RolesSettings {
|
||||
private val _userRoles = MutableStateFlow<List<Role>>(emptyList())
|
||||
override val userRoles: StateFlow<List<Role>> = _userRoles.asStateFlow()
|
||||
|
||||
val rolesUpdatingJob = (authSettings.user + authSettings.authorizedDIModule).subscribeSafelyWithoutExceptions(scope) {
|
||||
val user = authSettings.user.value
|
||||
|
||||
if (user == null || authSettings.authorizedDIModule.value == null) {
|
||||
_userRoles.value = emptyList()
|
||||
} else {
|
||||
_userRoles.value = koin.get<RolesStorage<Role>>().getRoles(user.id)
|
||||
}
|
||||
println(user)
|
||||
println(userRoles.value)
|
||||
}
|
||||
}
|
@ -6,5 +6,6 @@ import dev.inmo.postssystem.features.roles.common.Role
|
||||
import dev.inmo.postssystem.features.roles.common.RolesStorage
|
||||
|
||||
val loader = AuthorizedModuleLoader {
|
||||
single<RolesSettings> { DefaultRolesSettings(getKoin(), get(), get()) }
|
||||
single<RolesStorage<Role>> { ClientRolesStorage(get(AuthorizedQualifiers.ServerUrlQualifier), get(), Role.serializer()) }
|
||||
}
|
||||
|
8
features/roles/client/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/client/RolesSettings.kt
Normal file
8
features/roles/client/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/client/RolesSettings.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package dev.inmo.postssystem.features.roles.client
|
||||
|
||||
import dev.inmo.postssystem.features.roles.common.Role
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface RolesSettings {
|
||||
val userRoles: StateFlow<List<Role>>
|
||||
}
|
Reference in New Issue
Block a user