From f2b992b7d78b2981b6f97d945732d030984ed8e0 Mon Sep 17 00:00:00 2001 From: kishore Date: Sat, 15 Aug 2026 17:18:37 -0400 Subject: [PATCH 1/2] fix: description of omitted message and sample app additions --- .../commonMain/kotlin/kiit/codes/Status.kt | 2 +- .../src/main/kotlin/sample/SampleApp.kt | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/kiit-codes/src/commonMain/kotlin/kiit/codes/Status.kt b/kiit-codes/src/commonMain/kotlin/kiit/codes/Status.kt index 7451c6d..36997db 100644 --- a/kiit-codes/src/commonMain/kotlin/kiit/codes/Status.kt +++ b/kiit-codes/src/commonMain/kotlin/kiit/codes/Status.kt @@ -320,7 +320,7 @@ sealed class Passed : Status { val OMITTED = Excluded( "OMITTED", - "The item was left out.", + "The item was excluded from the result.", origin = StatusConstants.KIIT, ) diff --git a/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt b/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt index 3e9ca81..4b8e8cd 100644 --- a/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt +++ b/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt @@ -1,14 +1,31 @@ package sample +import kiit.codes.Checked import kiit.codes.CodesToHttp +import kiit.codes.Err +import kiit.codes.Excluded import kiit.codes.Failed +import kiit.codes.Information +import kiit.codes.Invalid import kiit.codes.Passed +import kiit.codes.Pending +import kiit.codes.Rejected +import kiit.codes.Restricted import kiit.codes.Status import kiit.codes.StatusException +import kiit.codes.Succeeded +import kiit.codes.Unserved +import kotlin.random.Random private val http = CodesToHttp() fun main() { + //test1() + test2() + test3() +} + +fun test1() { val service = UserService() report("create alice", service.create("alice", "alice@example.com")) @@ -34,3 +51,85 @@ private fun report(label: String, status: Status) { } println("$label -> ${status.name} ($outcome, http=${http.toCode(status)})") } + +fun test2() { + val value = Random.nextInt(1, 8) + val result: Status = when (value) { + 1 -> Succeeded.SUCCESS + 2 -> Pending.ACCEPTED + 3 -> Excluded.SKIPPED + 4 -> Information.NOTICE + 5 -> Restricted.DENIED + 6 -> Invalid.INVALID_VALUE + 7 -> Rejected.RULE_VIOLATION + else -> Unserved.UNEXPECTED + } + + val name = when(result) { + is Passed -> { + when(result) { + is Passed.Succeeded -> "Succeeded" + is Passed.Pending -> "Pending" + is Passed.Excluded -> "Excluded" + is Passed.Information -> "Information" + } + } + is Failed -> { + when(result) { + is Failed.Restricted -> "Restricted" + is Failed.Invalid -> "Invalid" + is Failed.Rejected -> "Rejected" + is Failed.Unserved -> "Unserved" + } + } + } + println("${name.padEnd(11)}: ${result.name}") +} + + +fun test3() { + val check1 = validatePhone("") + val check2 = validatePhone("12345678901") + val check3 = validatePhone("1111111111") + val check4 = validatePhone("1234567890") + val check5 = validatePhone("9876543210") + val check6 = validatePhone("1234567890", "admin") + println(check1) + println(check2) + println(check3) + println(check4) + println(check5) + println(check6) +} + +fun validatePhone(phone: String, caller: String = "guest"): Checked { + return when { + phone.isEmpty() -> { + Checked.failure( + Invalid.INVALID_VALUE, + listOf(Err.on("phone", phone, "Too short")), + ) + } + phone.length > 10 -> { + Checked.failure( + Invalid.INVALID_VALUE, + listOf(Err.on("phone", phone, "Too long")), + ) + } + phone == "1111111111" -> { + Checked.failure( + Rejected.RULE_VIOLATION, + listOf(Err.on("phone", phone, "Reserved phone for testing")), + ) + } + phone.startsWith("123") && caller != "admin" -> { + Checked.failure( + Restricted.DENIED, + listOf(Err.on("phone", phone, "Only admins can validate internal-use numbers")), + ) + } + else -> { + Checked.success() + } + } +} From 71fe9f203404b134020892ec0d6e5de3214e946f Mon Sep 17 00:00:00 2001 From: kishore Date: Sat, 15 Aug 2026 17:21:53 -0400 Subject: [PATCH 2/2] Update SampleApp.kt --- samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt b/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt index 4b8e8cd..32286e7 100644 --- a/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt +++ b/samples/sample-kotlin/src/main/kotlin/sample/SampleApp.kt @@ -20,7 +20,7 @@ import kotlin.random.Random private val http = CodesToHttp() fun main() { - //test1() + test1() test2() test3() }