Feat(ToolScreen): Support get tool online
Support get tool online in page
This commit is contained in:
13
app/src/main/kotlin/top/fatweb/oxygen/toolbox/model/Page.kt
Normal file
13
app/src/main/kotlin/top/fatweb/oxygen/toolbox/model/Page.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package top.fatweb.oxygen.toolbox.model
|
||||
|
||||
data class Page<T>(
|
||||
val total: Long,
|
||||
|
||||
val pages: Long,
|
||||
|
||||
val size: Long,
|
||||
|
||||
val current: Long,
|
||||
|
||||
val records: List<T>
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
package top.fatweb.oxygen.toolbox.model
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import top.fatweb.oxygen.toolbox.network.model.ResponseResult
|
||||
|
||||
sealed interface Result<out T> {
|
||||
data class Success<T>(val data: T) : Result<T>
|
||||
data class Fail(val message: String): Result<Nothing>
|
||||
data class Error(val exception: Throwable) : Result<Nothing>
|
||||
data object Loading : Result<Nothing>
|
||||
}
|
||||
|
||||
fun <T> Flow<ResponseResult<T>>.asResult(): Flow<Result<T>> = map<ResponseResult<T>, Result<T>> {
|
||||
if (it.success) {
|
||||
Result.Success(it.data!!)
|
||||
} else {
|
||||
Result.Fail(it.msg)
|
||||
}
|
||||
}
|
||||
.onStart { emit(Result.Loading) }
|
||||
.catch { emit(Result.Error(it)) }
|
||||
|
||||
fun <T, R> Result<T>.asExternalModel(block: (T) -> R): Result<R> =
|
||||
when (this) {
|
||||
is Result.Success -> {
|
||||
Result.Success(block(data))
|
||||
}
|
||||
|
||||
is Result.Fail -> {
|
||||
Result.Fail(message)
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
Result.Error(exception)
|
||||
}
|
||||
|
||||
Result.Loading -> Result.Loading
|
||||
}
|
||||
@@ -1,12 +1,53 @@
|
||||
package top.fatweb.oxygen.toolbox.model.tool
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
|
||||
data class Tool(
|
||||
val id: String,
|
||||
val id: Long,
|
||||
|
||||
val icon: ImageVector = OxygenIcons.Tool,
|
||||
val name: String,
|
||||
|
||||
val name: String
|
||||
)
|
||||
val toolId: String,
|
||||
|
||||
val icon: String,
|
||||
|
||||
val platform: Platform,
|
||||
|
||||
val description: String,
|
||||
|
||||
val base: String? = null,
|
||||
|
||||
val author: Author,
|
||||
|
||||
val ver: String,
|
||||
|
||||
val keywords: List<String>,
|
||||
|
||||
val categories: List<String>,
|
||||
|
||||
val source: String? = null,
|
||||
|
||||
val dist: String? = null,
|
||||
|
||||
val entryPoint: String,
|
||||
|
||||
val createTime: LocalDateTime,
|
||||
|
||||
val updateTime: LocalDateTime
|
||||
) {
|
||||
enum class Platform {
|
||||
WEB,
|
||||
|
||||
DESKTOP,
|
||||
|
||||
ANDROID
|
||||
}
|
||||
|
||||
data class Author(
|
||||
val username: String,
|
||||
|
||||
val nickname: String,
|
||||
|
||||
val avatar: String
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user