diff --git a/core/common/src/dev/programadorthi/routing/core/RoutingExt.kt b/core/common/src/dev/programadorthi/routing/core/RoutingExt.kt index c81495c..a5c732b 100644 --- a/core/common/src/dev/programadorthi/routing/core/RoutingExt.kt +++ b/core/common/src/dev/programadorthi/routing/core/RoutingExt.kt @@ -2,9 +2,13 @@ package dev.programadorthi.routing.core import io.ktor.http.Parameters +public fun Routing.push(path: String) { + push(path = path, parameters = Parameters.Empty) +} + public fun Routing.push( path: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( uri = path, @@ -13,9 +17,13 @@ public fun Routing.push( ) } +public fun Routing.pushNamed(name: String) { + pushNamed(name = name, parameters = Parameters.Empty) +} + public fun Routing.pushNamed( name: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( name = name, @@ -24,9 +32,64 @@ public fun Routing.pushNamed( ) } +public fun Routing.pushWithBody( + path: String, + body: T, +) { + pushWithBody( + path = path, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.pushWithBody( + path: String, + parameters: Parameters, + body: T, +) { + callWithBody( + uri = path, + parameters = parameters, + routeMethod = RouteMethod.Push, + body = body, + ) +} + +public fun Routing.pushNamedWithBody( + name: String, + body: T, +) { + pushNamedWithBody( + name = name, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.pushNamedWithBody( + name: String, + parameters: Parameters, + body: T, +) { + callWithBody( + name = name, + parameters = parameters, + routeMethod = RouteMethod.Push, + body = body, + ) +} + +public fun Routing.replace(path: String) { + replace( + path = path, + parameters = Parameters.Empty, + ) +} + public fun Routing.replace( path: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( uri = path, @@ -35,9 +98,16 @@ public fun Routing.replace( ) } +public fun Routing.replaceNamed(name: String) { + replaceNamed( + name = name, + parameters = Parameters.Empty, + ) +} + public fun Routing.replaceNamed( name: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( name = name, @@ -46,9 +116,64 @@ public fun Routing.replaceNamed( ) } +public fun Routing.replaceWithBody( + path: String, + body: T, +) { + replaceWithBody( + path = path, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.replaceWithBody( + path: String, + parameters: Parameters, + body: T, +) { + callWithBody( + uri = path, + parameters = parameters, + routeMethod = RouteMethod.Replace, + body = body, + ) +} + +public fun Routing.replaceNamedWithBody( + name: String, + body: T, +) { + replaceNamedWithBody( + name = name, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.replaceNamedWithBody( + name: String, + parameters: Parameters, + body: T, +) { + callWithBody( + name = name, + parameters = parameters, + routeMethod = RouteMethod.Replace, + body = body, + ) +} + +public fun Routing.replaceAll(path: String) { + replaceAll( + path = path, + parameters = Parameters.Empty, + ) +} + public fun Routing.replaceAll( path: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( uri = path, @@ -57,9 +182,16 @@ public fun Routing.replaceAll( ) } +public fun Routing.replaceAllNamed(name: String) { + replaceAllNamed( + name = name, + parameters = Parameters.Empty, + ) +} + public fun Routing.replaceAllNamed( name: String, - parameters: Parameters = Parameters.Empty, + parameters: Parameters, ) { call( name = name, @@ -67,3 +199,51 @@ public fun Routing.replaceAllNamed( routeMethod = RouteMethod.ReplaceAll, ) } + +public fun Routing.replaceAllWithBody( + path: String, + body: T, +) { + replaceAllWithBody( + path = path, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.replaceAllWithBody( + path: String, + parameters: Parameters, + body: T, +) { + callWithBody( + uri = path, + parameters = parameters, + routeMethod = RouteMethod.ReplaceAll, + body = body, + ) +} + +public fun Routing.replaceAllNamedWithBody( + name: String, + body: T, +) { + replaceAllNamedWithBody( + name = name, + parameters = Parameters.Empty, + body = body, + ) +} + +public fun Routing.replaceAllNamedWithBody( + name: String, + parameters: Parameters, + body: T, +) { + callWithBody( + name = name, + parameters = parameters, + routeMethod = RouteMethod.ReplaceAll, + body = body, + ) +} diff --git a/core/common/test/dev/programadorthi/routing/core/Routes.kt b/core/common/test/dev/programadorthi/routing/core/Routes.kt index ecf4d6e..392bbd1 100644 --- a/core/common/test/dev/programadorthi/routing/core/Routes.kt +++ b/core/common/test/dev/programadorthi/routing/core/Routes.kt @@ -9,9 +9,9 @@ import io.ktor.http.Parameters import io.ktor.util.Attributes import kotlin.to -val invoked = mutableMapOf>() +internal val invoked = mutableMapOf>() -data class User( +internal data class User( val id: Int, val name: String, ) @@ -59,14 +59,14 @@ fun regex2(number: Int) { } @Route("/with-body") -fun withBody( +internal fun withBody( @Body user: User ) { invoked += "/with-body" to listOf(user) } @Route("/with-null-body") -fun withNullBody( +internal fun withNullBody( @Body user: User? ) { invoked += "/with-null-body" to listOf(user) diff --git a/core/jvm/test/dev/programadorthi/routing/core/RoutingByAnnotationsTest.kt b/core/jvm/test/dev/programadorthi/routing/core/RoutingByAnnotationsTest.kt index cef8a6b..77589af 100644 --- a/core/jvm/test/dev/programadorthi/routing/core/RoutingByAnnotationsTest.kt +++ b/core/jvm/test/dev/programadorthi/routing/core/RoutingByAnnotationsTest.kt @@ -6,15 +6,15 @@ import dev.programadorthi.routing.generated.configure import io.ktor.http.Parameters import io.ktor.http.parametersOf import io.ktor.util.Attributes +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.Job +import kotlinx.coroutines.test.advanceTimeBy +import kotlinx.coroutines.test.runTest import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.Job -import kotlinx.coroutines.test.advanceTimeBy -import kotlinx.coroutines.test.runTest @OptIn(ExperimentalCoroutinesApi::class) class RoutingByAnnotationsTest { @@ -268,11 +268,11 @@ class RoutingByAnnotationsTest { } // WHEN - routing.call(uri = "/path", routeMethod = RouteMethod.Push) + routing.push(path = "/path") advanceTimeBy(99) // THEN - assertEquals(listOf("PUSH"), invoked.remove("/path")) + assertEquals(listOf(RouteMethod.Push.value), invoked.remove("/path")) } @Test diff --git a/integration/compose/build.gradle.kts b/integration/compose/build.gradle.kts index ec8db02..73c6bab 100644 --- a/integration/compose/build.gradle.kts +++ b/integration/compose/build.gradle.kts @@ -3,6 +3,7 @@ plugins { kotlin("plugin.serialization") alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) + alias(libs.plugins.ksp) id("org.jetbrains.kotlinx.kover") alias(libs.plugins.maven.publish) } @@ -19,5 +20,18 @@ kotlin { implementation(libs.serialization.json) } } + commonTest { + dependencies { + implementation(projects.ksp.coreAnnotations) + } + } } } + +dependencies { + add("kspJvmTest", projects.ksp.coreProcessor) +} + +ksp { + arg("Routing_Module_Name", "Compose") +} diff --git a/integration/compose/common/test/dev/programadorthi/routing/compose/Composables.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/Composables.kt new file mode 100644 index 0000000..85374ab --- /dev/null +++ b/integration/compose/common/test/dev/programadorthi/routing/compose/Composables.kt @@ -0,0 +1,117 @@ +package dev.programadorthi.routing.compose + +import androidx.compose.runtime.Composable +import dev.programadorthi.routing.annotation.Body +import dev.programadorthi.routing.annotation.Path +import dev.programadorthi.routing.annotation.Route +import dev.programadorthi.routing.core.application.Application +import dev.programadorthi.routing.core.application.ApplicationCall +import io.ktor.http.Parameters +import io.ktor.util.Attributes + +internal val invoked = mutableMapOf>() + +internal data class User( + val id: Int, + val name: String, +) + +@Route("/initial") +@Composable +fun initial() { + invoked += "/initial" to emptyList() +} + +@Route("/path") +@Composable +fun execute() { + invoked += "/path" to emptyList() +} + +@Route(path = "/path/{id}") +@Composable +fun execute(id: Double) { + invoked += "/path/{id}" to listOf(id) +} + +@Route(path = "/named/{name}", name = "named") +@Composable +fun named(name: String) { + invoked += "/named/{name}" to listOf(name) +} + +@Route(path = "/custom/{random}", name = "custom") +@Composable +fun custom( + @Path("random") value: String +) { + invoked += "/custom/{random}" to listOf(value) +} + +@Route(path = "/optional/{id?}") +@Composable +fun optional(id: Char?) { + invoked += "/optional/{id?}" to listOf(id) +} + +@Route(path = "/tailcard/{param...}") +@Composable +fun tailcard(param: List?) { + invoked += "/tailcard/{param...}" to (param ?: emptyList()) +} + +/*@Route(regex = ".+/hello") +@Composable +fun regex1() { + invoked += ".+/hello" to listOf() +} + +@Route(regex = "/(?\\d+)") +@Composable +fun regex2(number: Int) { + invoked += "/(?\\d+)" to listOf(number) +}*/ + +@Route("/with-body") +@Composable +internal fun withBody( + @Body user: User +) { + invoked += "/with-body" to listOf(user) +} + +@Route("/with-null-body") +@Composable +internal fun withNullBody( + @Body user: User? +) { + invoked += "/with-null-body" to listOf(user) +} + +@Route("/path", method = "PUSH") +@Composable +fun byPushMethod() { + invoked += "/path" to listOf("PUSH") +} + +@Route("/path/{part1}/{part2}") +@Composable +fun multiParameters(part1: Int, part2: String) { + invoked += "/path/{part1}/{part2}" to listOf(part1, part2) +} + +@Route("/call") +@Composable +fun call(call: ApplicationCall) { + invoked += "/call" to listOf(call) +} + +@Route("/call/{part1}/{part2}") +@Composable +fun callParameters( + application: Application, + parameters: Parameters, + attributes: Attributes, +) { + invoked += "/call/{part1}/{part2}" to listOf(application, parameters, attributes) +} diff --git a/integration/compose/jvm/test/dev/programadorthi/routing/compose/history/ComposeRoutingByAnnotationsTest.kt b/integration/compose/jvm/test/dev/programadorthi/routing/compose/history/ComposeRoutingByAnnotationsTest.kt new file mode 100644 index 0000000..04e9c09 --- /dev/null +++ b/integration/compose/jvm/test/dev/programadorthi/routing/compose/history/ComposeRoutingByAnnotationsTest.kt @@ -0,0 +1,525 @@ +package dev.programadorthi.routing.compose.history + +import dev.programadorthi.routing.compose.Routing +import dev.programadorthi.routing.compose.User +import dev.programadorthi.routing.compose.helper.runComposeTest +import dev.programadorthi.routing.compose.invoked +import dev.programadorthi.routing.core.RouteMethod +import dev.programadorthi.routing.core.application.Application +import dev.programadorthi.routing.core.application.ApplicationCall +import dev.programadorthi.routing.core.push +import dev.programadorthi.routing.core.pushNamed +import dev.programadorthi.routing.core.pushWithBody +import dev.programadorthi.routing.core.routing +import dev.programadorthi.routing.generated.configure +import io.ktor.http.Parameters +import io.ktor.http.parametersOf +import io.ktor.util.Attributes +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.advanceTimeBy +import kotlin.random.Random +import kotlin.test.Ignore +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertIs +import kotlin.test.assertNotNull + +@OptIn(ExperimentalCoroutinesApi::class) +class ComposeRoutingByAnnotationsTest { + + @Test + fun shouldHandleInitial() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(emptyList(), invoked.remove("/initial")) + } + + @Test + fun shouldHandleAPath() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/path") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(RouteMethod.Push.value), invoked.remove("/path")) + } + + @Test + fun shouldHandleAPathWithDoubleId() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/path/3.4") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(3.4), invoked.remove("/path/{id}")) + } + + @Test + fun shouldHandleByName() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.pushNamed(name = "named", parameters = parametersOf("name", "Routing")) + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf("Routing"), invoked.remove("/named/{name}")) + } + + @Test + fun shouldHandleByCustomPathName() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + val nextInt = Random.Default.nextInt() + routing.push(path = "/custom/$nextInt") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf("$nextInt"), invoked.remove("/custom/{random}")) + } + + @Test + fun shouldHandleNullOptionalValue() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/optional") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(null), invoked.remove("/optional/{id?}")) + } + + @Test + fun shouldHandleNonNullOptionalValue() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/optional/ABC") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf('A'), invoked.remove("/optional/{id?}")) + } + + @Test + fun shouldHandleTailcardOneParameter() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/tailcard/p1") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf("p1"), invoked.remove("/tailcard/{param...}")) + } + + @Test + fun shouldHandleTailcardManyParameter() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/tailcard/p1/p2/p3/p4") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf("p1", "p2", "p3", "p4"), invoked.remove("/tailcard/{param...}")) + } + + @Ignore("Compose Regex is not supported yet") + @Test + fun shouldHandleByRegex() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/foo/hello") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(), invoked.remove(".+/hello")) + } + + @Ignore("Compose Regex is not supported yet") + @Test + fun shouldHandleByRegexWithParameters() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/456") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(456), invoked.remove("/(?\\d+)")) + } + + @Test + fun shouldHandleWithBody() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + val body = User(id = 456, name = "With Body") + routing.pushWithBody(path = "/with-body", body = body) + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(body), invoked.remove("/with-body")) + } + + @Test + fun shouldHandleWithNullBody() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/with-null-body") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(null), invoked.remove("/with-null-body")) + } + + @Test + fun shouldHandleWithNonNullBody() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + val body = User(id = 456, name = "With Body") + routing.pushWithBody(path = "/with-null-body", body = body) + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(body), invoked.remove("/with-null-body")) + } + + @Test + fun shouldHandleCustomMethod() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/path") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf("PUSH"), invoked.remove("/path")) + } + + @Test + fun shouldHandleMultipleParameters() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/path/13579/partition") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + assertEquals(listOf(13579, "partition"), invoked.remove("/path/{part1}/{part2}")) + } + + @Test + fun shouldHandleCallDirectly() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/call") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + val call = invoked.remove("/call")?.firstOrNull() as? ApplicationCall + assertNotNull(call) + assertEquals("/call", call.uri) + assertEquals("", call.name) + assertEquals(RouteMethod.Push, call.routeMethod) + assertEquals(Parameters.Empty, call.parameters) + } + + @Test + fun shouldHandleCallProperties() = + runComposeTest { coroutineContext, composition, clock -> + // GIVEN + val routing = + routing(parentCoroutineContext = coroutineContext) { + configure() + } + + // WHEN + composition.setContent { + Routing( + routing = routing, + startUri = "/initial", + ) + } + advanceTimeBy(99) + clock.sendFrame(0L) // Ask for recomposition + + routing.push(path = "/call/p01/p02") + advanceTimeBy(99) // Ask for routing + clock.sendFrame(0L) // Ask for recomposition + + // THEN + val items = invoked.remove("/call/{part1}/{part2}") + assertNotNull(items) + assertIs(items.firstOrNull()) + assertEquals(parametersOf("part1" to listOf("p01"), "part2" to listOf("p02")), items[1]) + assertIs(items[2]) + } +} diff --git a/samples/ksp-sample/src/commonMain/kotlin/dev/programadorthi/routing/sample/Composables.kt b/samples/ksp-sample/src/commonMain/kotlin/dev/programadorthi/routing/sample/Composables.kt deleted file mode 100644 index a74d0b0..0000000 --- a/samples/ksp-sample/src/commonMain/kotlin/dev/programadorthi/routing/sample/Composables.kt +++ /dev/null @@ -1,91 +0,0 @@ -package dev.programadorthi.routing.sample - -import androidx.compose.runtime.Composable -import dev.programadorthi.routing.annotation.Body -import dev.programadorthi.routing.annotation.Path -import dev.programadorthi.routing.annotation.Route -import dev.programadorthi.routing.core.application.Application -import io.ktor.http.Parameters -import io.ktor.util.Attributes - -@Route("/compose") -@Composable -fun compose() { - println(">>>> I'm routing") -} - -@Route(path = "/compose/{id}") -@Composable -fun compose(id: Double) { - println(">>>> ID: $id") -} - -@Route(path = "/composeNamed/{name}", name = "composeNamed") -@Composable -fun composeNamed(name: String) { - println(">>>> name: $name") -} - -@Route(path = "/composeCustom/{random}", name = "composeCustom") -@Composable -fun composeCustom(@Path("random") value: String) { - println(">>>> value: $value") -} - -@Route(path = "/composeOptional/{id?}") -@Composable -fun composeOptional(id: Char?) { - println(">>>> Optional ID: $id") -} - -@Route(path = "/composeTailcard/{param...}") -@Composable -fun composeTailcard(param: List?) { - println(">>>> Tailcard params: $param") -} - -/*@Route(regex = ".+/hello") -@Composable -fun composeRegex1() { - println(">>>> Routing with regex") -}*/ - -@Route("/compose-with-body") -@Composable -fun composeWithBody(@Body user: User) { - println(">>>> with body $user") -} - -@Route("/compose-with-null-body") -@Composable -fun composeWithNullBody(@Body user: User?) { - println(">>>> null body $user") -} - -@Route("/compose", method = "PUSH") -@Composable -fun composeByPushMethod() { - println(">>>> I'm pushing a route") -} - -@Route("/compose/{part1}/{part2}") -@Composable -fun composeMultiParameters(part1: Int, part2: String) { - println(">>>> Parts: $part1 and $part2") -} - -@Route("/compose-call/{part1}/{part2}") -@Composable -fun composeCallParameters( - application: Application, - parameters: Parameters, - attributes: Attributes, -) { - println( - """ - >>>> application: $application - >>>> parameters: $parameters - >>>> attributes: $attributes - """.trimIndent() - ) -}