Skip to content

Commit

Permalink
Use data classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNatan committed Sep 16, 2023
1 parent a6ce3d6 commit 190e052
Show file tree
Hide file tree
Showing 59 changed files with 205 additions and 311 deletions.
1 change: 0 additions & 1 deletion application/src/main/kotlin/org/katan/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
import kotlinx.coroutines.runBlocking
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.katan.model.KatanConfig

@Suppress("UNUSED")
private object Application {
Expand Down
1 change: 0 additions & 1 deletion application/src/main/kotlin/org/katan/KoinLog4jLogger.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.katan

import org.apache.logging.log4j.LogManager
import org.katan.model.KatanConfig
import org.koin.core.Koin
import org.koin.core.logger.Level
import org.koin.core.logger.MESSAGE
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/kotlin/org/katan/model/blueprint/Blueprint.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.katan.model.blueprint

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.katan.model.Snowflake

Expand All @@ -10,5 +9,5 @@ data class Blueprint(
val id: Snowflake,
val createdAt: Instant,
val updatedAt: Instant,
val spec: BlueprintSpec
)
val spec: BlueprintSpec,
)
12 changes: 6 additions & 6 deletions core/src/main/kotlin/org/katan/model/blueprint/BlueprintSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class BlueprintSpec(
val version: String,
val remote: BlueprintSpecRemote?,
val build: BlueprintSpecBuild?,
val options: List<BlueprintSpecOption> = emptyList()
val options: List<BlueprintSpecOption> = emptyList(),
)

@Serializable
Expand All @@ -18,20 +18,20 @@ data class BlueprintSpecOption(
val name: String,
val type: List<String>,
val env: String?,
val defaultValue: String
val defaultValue: String,
)

@Serializable
data class BlueprintSpecRemote(
val origin: String
val origin: String,
)

@Serializable
data class BlueprintSpecBuild(
val image: BlueprintSpecImage,
val entrypoint: String,
val env: Map<String, String>,
val instance: BlueprintSpecInstance?
val instance: BlueprintSpecInstance?,
)

@Serializable
Expand All @@ -51,5 +51,5 @@ sealed class BlueprintSpecImage {

@Serializable
data class BlueprintSpecInstance(
val name: String
)
val name: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ data class InstanceInternalStats(
val lastOnlineCpus: Long?,
)


private const val MAX_PERCENTAGE = 100.0f

fun InstanceInternalStats.getMemoryUsagePercentage(): Float {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/kotlin/org/katan/model/instance/InstanceRuntime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
internal data class InstanceRuntime(
data class InstanceRuntime(
val id: String,
val network: InstanceRuntimeNetwork,
val platform: String?,
Expand All @@ -20,24 +20,24 @@ internal data class InstanceRuntime(
)

@Serializable
internal data class InstanceRuntimeNetwork(
data class InstanceRuntimeNetwork(
val ipV4Address: String,
val hostname: String?,
val networks: List<InstanceRuntimeSingleNetwork>,
)

@Serializable
internal data class InstanceRuntimeSingleNetwork(
data class InstanceRuntimeSingleNetwork(
val id: String,
val name: String,
val ipv4Address: String?,
val ipv6Address: String?,
)

@Serializable
internal data class InstanceRuntimeMount(
data class InstanceRuntimeMount(
val type: String,
val target: String,
val destination: String,
val readonly: Boolean,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UnitInstance(
val connection: HostPort?,
val runtime: InstanceRuntime?,
val blueprintId: Snowflake,
val createdAt: Instant
val createdAt: Instant,
)

val UnitInstance.containerIdOrThrow: String
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/katan/model/io/Bucket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class Bucket(
val path: String,
val name: String,
val isLocal: Boolean,
val createdAt: Instant?
val createdAt: Instant?,
)
8 changes: 5 additions & 3 deletions core/src/main/kotlin/org/katan/model/io/Directory.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.katan.model.io

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
@SerialName("directory")
data class Directory(
override val name: String,
override val relativePath: String,
Expand All @@ -12,8 +14,8 @@ data class Directory(
override val isHidden: Boolean,
override val createdAt: Instant?,
override val modifiedAt: Instant?,
val children: List<VirtualFile>,
) : VirtualFile {
val children: List<FileLike>,
) : FileLike {

override val isDirectory: Boolean get() = true
}
}
20 changes: 20 additions & 0 deletions core/src/main/kotlin/org/katan/model/io/File.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.katan.model.io

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
@SerialName("file")
data class File(
override val name: String,
override val relativePath: String,
override val absolutePath: String,
override val size: Long,
override val isHidden: Boolean,
override val createdAt: Instant?,
override val modifiedAt: Instant?,
) : FileLike {

override val isDirectory: Boolean get() = false
}
59 changes: 59 additions & 0 deletions core/src/main/kotlin/org/katan/model/io/FileLike.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.katan.model.io

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
sealed interface FileLike {

val name: String

val relativePath: String

val absolutePath: String

val size: Long

val isDirectory: Boolean

val isHidden: Boolean

val createdAt: Instant?

val modifiedAt: Instant?
}

val FileLike.extension: String
get() = name.substringAfterLast(".", "")

fun FileLike(
name: String,
relativePath: String,
absolutePath: String,
size: Long,
isHidden: Boolean,
createdAt: Instant?,
modifiedAt: Instant?,
children: List<FileLike>?,
): FileLike = if (children != null) {
Directory(
name = name,
relativePath = relativePath,
absolutePath = absolutePath,
size = size,
isHidden = isHidden,
createdAt = createdAt ?: modifiedAt,
modifiedAt = modifiedAt,
children = children,
)
} else {
File(
name = name,
relativePath = relativePath,
absolutePath = absolutePath,
size = size,
isHidden = isHidden,
createdAt = createdAt ?: modifiedAt,
modifiedAt = modifiedAt,
)
}
25 changes: 0 additions & 25 deletions core/src/main/kotlin/org/katan/model/io/VirtualFile.kt

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/katan/model/role/Role.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ data class Role(
val id: Snowflake,
val name: String,
val position: Int,
override val permissions: Permissions
override val permissions: Permissions,
) : PermissionsHolder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package org.katan.model.unit
enum class ImageUpdatePolicy(val id: String) {

Always("always"),
Never("never");
Never("never"),
;

companion object {

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/kotlin/org/katan/model/unit/Unit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ enum class UnitStatus(val value: String) {
Created("created"),
MissingInstance("missing-instance"),
CreatingInstance("creating-instance"),
Ready("ready");
Ready("ready"),
;

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import org.katan.model.account.Account
@Serializable
data class AuditLog(
val entries: List<AuditLogEntry>,
val actors: List<Account>
)
val actors: List<Account>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
data class AuditLogChange(
val key: String,
val oldValue: String?,
val newValue: String?
val newValue: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ data class AuditLogEntry(
val reason: String?,
val changes: List<AuditLogChange>,
val additionalData: String?,
val createdAt: Instant
)
val createdAt: Instant,
)
1 change: 1 addition & 0 deletions http/http-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
runtimeOnly(libs.expressly)
compileOnly(libs.ktor.server.core)
compileOnly(libs.ktor.server.cio)
implementation(projects.core)
implementation(projects.http.httpShared)
implementation(libs.ktor.server.websockets)
implementation(libs.hibernateValidator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.json.Json
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.katan.model.KatanConfig
import org.katan.KatanConfig
import org.katan.http.HttpModule
import org.katan.http.HttpModuleRegistry
import org.katan.http.installDefaultFeatures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import org.katan.model.KatanConfig
import org.katan.KatanConfig
import org.katan.http.server.dto.ServerInfoBuild
import org.katan.http.server.dto.ServerInfoResponse
import org.koin.ktor.ext.inject
Expand Down
1 change: 1 addition & 0 deletions http/http-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {
}

dependencies {
implementation(projects.core)
implementation(libs.koin.core)
implementation(libs.ktor.server.websockets)
implementation(libs.ktor.server.feature.defaultHeaders)
Expand Down

This file was deleted.

Loading

0 comments on commit 190e052

Please sign in to comment.