diff --git a/core/core-utils/build.gradle.kts b/core/core-utils/build.gradle.kts index b4d41716..fd030472 100644 --- a/core/core-utils/build.gradle.kts +++ b/core/core-utils/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { api("org.jetbrains.exposed:exposed-jdbc") api("org.jetbrains.exposed:exposed-kotlin-datetime") api("com.zaxxer:HikariCP") + api("org.flywaydb:flyway-core:9.22.3") // BigDecimal api("com.ionspin.kotlin:bignum:0.3.8") diff --git a/core/core-utils/src/main/kotlin/at/mocode/core/utils/error/Result.kt b/core/core-utils/src/main/kotlin/at/mocode/core/utils/error/Result.kt deleted file mode 100644 index c42990ac..00000000 --- a/core/core-utils/src/main/kotlin/at/mocode/core/utils/error/Result.kt +++ /dev/null @@ -1,67 +0,0 @@ -package at.mocode.core.utils.error - -/** - * A discriminated union that encapsulates a successful outcome with a value of type [T] - * or a failure with an arbitrary [Throwable] exception. - */ -sealed class Result { - /** - * Represents a successful operation with the given [data] value. - */ - data class Success(val data: T) : Result() - - /** - * Represents a failed operation with the given [exception] that caused it to fail. - */ - data class Error(val exception: Throwable) : Result() - - /** - * Returns `true` if this instance represents a successful outcome. - */ - fun isSuccess(): Boolean = this is Success - - /** - * Returns `true` if this instance represents a failed outcome. - */ - fun isError(): Boolean = this is Error - - /** - * Returns the encapsulated value if this instance represents [Success] or `null` if it is [Error]. - */ - fun getOrNull(): T? = when (this) { - is Success -> data - is Error -> null - } - - /** - * Returns the encapsulated value if this instance represents [Success] or throws the encapsulated [exception] if it is [Error]. - */ - fun getOrThrow(): T = when (this) { - is Success -> data - is Error -> throw exception - } - - companion object { - /** - * Creates a [Result.Success] instance with the given [data] value. - */ - fun success(data: T): Result = Success(data) - - /** - * Creates a [Result.Error] instance with the given [exception]. - */ - fun error(exception: Throwable): Result = Error(exception) - } -} - -/** - * Calls the specified function [block] and returns its encapsulated result if invocation was successful, - * catching any [Throwable] exception that was thrown from the [block] function execution and encapsulating it as a failure. - */ -inline fun runCatching(block: () -> T): Result { - return try { - Result.success(block()) - } catch (e: Throwable) { - Result.error(e) - } -}