From bc17fc0e06fd79f372b6f13818c658c98e13e828 Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Sun, 3 Mar 2024 20:14:00 +0100 Subject: [PATCH 1/7] feat(build): add java version of gradle API --- build-logic/src/main/kotlin/Utils.kt | 3 ++- build-logic/src/main/kotlin/kotlin-base.gradle.kts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build-logic/src/main/kotlin/Utils.kt b/build-logic/src/main/kotlin/Utils.kt index b4057f837..586773da9 100644 --- a/build-logic/src/main/kotlin/Utils.kt +++ b/build-logic/src/main/kotlin/Utils.kt @@ -5,5 +5,6 @@ import org.gradle.api.provider.Provider fun VersionCatalog.getLibrary(name: String): Provider = findLibrary(name).get() object JavaVersion { - const val target: Int = 17 + val asInt: Int = 17 + val asVersion: org.gradle.api.JavaVersion = org.gradle.api.JavaVersion.toVersion(asInt) } diff --git a/build-logic/src/main/kotlin/kotlin-base.gradle.kts b/build-logic/src/main/kotlin/kotlin-base.gradle.kts index 1d3b47bed..cbd8cde1e 100644 --- a/build-logic/src/main/kotlin/kotlin-base.gradle.kts +++ b/build-logic/src/main/kotlin/kotlin-base.gradle.kts @@ -21,5 +21,5 @@ tasks.test { } kotlin { - jvmToolchain(JavaVersion.target) + jvmToolchain(JavaVersion.asInt) } From 5834bacd1f2bc253b002b1dea2a4e5f73c467023 Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Sun, 3 Mar 2024 20:16:37 +0100 Subject: [PATCH 2/7] feat(build): add dependencies for micronaut --- build-logic/build.gradle.kts | 7 +++ build-logic/src/main/kotlin/Utils.kt | 3 ++ .../src/main/kotlin/micronaut-base.gradle.kts | 47 +++++++++++++++++++ gradle/libs.versions.toml | 22 +++++++++ 4 files changed, 79 insertions(+) create mode 100644 build-logic/src/main/kotlin/micronaut-base.gradle.kts diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index bef7e2c1b..521126d24 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -8,10 +8,17 @@ repositories { } dependencies { + implementation(libs.plugins.allOpen.asDependency()) implementation(libs.plugins.detekt.asDependency()) implementation(libs.plugins.kotlin.asDependency()) implementation(libs.plugins.kover.asDependency()) + implementation(libs.plugins.ksp.asDependency()) implementation(libs.plugins.ktfmt.asDependency()) + implementation(libs.plugins.micronaut.app.asDependency()) + implementation(libs.plugins.micronaut.aot.asDependency()) + implementation(libs.plugins.micronaut.test.asDependency()) + implementation(libs.micronaut.buildtools) + implementation(libs.plugins.shadow.asDependency()) } fun Provider.asDependency(): Provider = diff --git a/build-logic/src/main/kotlin/Utils.kt b/build-logic/src/main/kotlin/Utils.kt index 586773da9..2651a502d 100644 --- a/build-logic/src/main/kotlin/Utils.kt +++ b/build-logic/src/main/kotlin/Utils.kt @@ -1,9 +1,12 @@ +import org.gradle.api.artifacts.ExternalModuleDependencyBundle import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.provider.Provider fun VersionCatalog.getLibrary(name: String): Provider = findLibrary(name).get() +fun VersionCatalog.getBundle(name: String): Provider = findBundle(name).get() + object JavaVersion { val asInt: Int = 17 val asVersion: org.gradle.api.JavaVersion = org.gradle.api.JavaVersion.toVersion(asInt) diff --git a/build-logic/src/main/kotlin/micronaut-base.gradle.kts b/build-logic/src/main/kotlin/micronaut-base.gradle.kts new file mode 100644 index 000000000..9610edcf4 --- /dev/null +++ b/build-logic/src/main/kotlin/micronaut-base.gradle.kts @@ -0,0 +1,47 @@ +plugins { + id("kotlin-base") + id("org.jetbrains.kotlin.plugin.allopen") + id("com.google.devtools.ksp") + id("com.github.johnrengelman.shadow") + id("io.micronaut.application") + id("io.micronaut.aot") + id("io.micronaut.test-resources") +} + +val catalog: VersionCatalog = extensions.getByType().named("libs") + +dependencies { + ksp(catalog.getBundle("micronaut-ksp")) + implementation(catalog.getBundle("micronaut-kotlin")) + catalog.getLibrary("micronaut-httpClient").let { + compileOnly(it) + testImplementation(it) + } + runtimeOnly(catalog.getLibrary("logback")) + runtimeOnly(catalog.getLibrary("jackson-kotlin")) +} + +java { + sourceCompatibility = JavaVersion.asVersion +} + +graalvmNative.toolchainDetection.set(false) +micronaut { + runtime("netty") + testRuntime("kotest5") + processing { + incremental(true) + annotations("micronaut.playground.*") + } + aot { + // Please review carefully the optimizations enabled below + // Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details + optimizeServiceLoading = false + convertYamlToJava = false + precomputeOperations = true + cacheEnvironment = true + optimizeClassLoading = true + deduceEnvironment = true + optimizeNetty = true + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3e2f73366..40eabee61 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,23 +11,45 @@ konsist = "0.13.0" kotest = "5.8.0" kotlin = "1.9.22" kover = "0.7.6" +ksp = "1.9.22-1.0.17" ktfmt = "0.17.0" +micronaut = "4.3.4" +micronautBuildTools = "2.4.0" +shadow = "8.1.1" [libraries] cucumber-bom = { module = "io.cucumber:cucumber-bom", version.ref = "cucumber-bom" } cucumber-java = { module = "io.cucumber:cucumber-java" } cucumber-junit = { module = "io.cucumber:cucumber-junit-platform-engine" } junit-platform = { module = "org.junit.platform:junit-platform-suite", version.ref = "junit-platform" } +jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +kotlin-stdlibJdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } konsist = { module = "com.lemonappdev:konsist", version.ref = "konsist" } kotest = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } +logback = { module = "ch.qos.logback:logback-classic" } +micronaut-buildtools = { module = "io.micronaut.testresources:micronaut-test-resources-build-tools", version.ref = "micronautBuildTools" } +micronaut-httpClient = { module = "io.micronaut:micronaut-http-client" } +micronaut-httpValidation = { module = "io.micronaut:micronaut-http-validation" } +micronaut-kotlinRuntime = { module = "io.micronaut.kotlin:micronaut-kotlin-runtime" } +micronaut-serdeJackson = { module = "io.micronaut.serde:micronaut-serde-jackson" } +micronaut-serdeProcessor = { module = "io.micronaut.serde:micronaut-serde-processor" } [plugins] +allOpen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } gitSemVer = { id = "org.danilopianini.git-sensitive-semantic-versioning", version.ref = "gitSemVer" } kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" } +micronaut-app = { id = "io.micronaut.application", version.ref = "micronaut" } +micronaut-aot = { id = "io.micronaut.application", version.ref = "micronaut" } +micronaut-test = { id = "io.micronaut.test-resources", version.ref = "micronaut" } +shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } [bundles] cucumberJunit = [ "cucumber-java", "cucumber-junit" ] +micronaut-ksp = [ "micronaut-httpValidation", "micronaut-serdeProcessor" ] +micronaut-kotlin = [ "kotlin-reflect", "kotlin-stdlibJdk8", "micronaut-kotlinRuntime", "micronaut-serdeJackson", ] From 838ee1bf885c09a7511078fe597ba3b862ce6b48 Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Sun, 3 Mar 2024 20:24:49 +0100 Subject: [PATCH 3/7] wip(structure): first draft of structure - DO NOT WORK --- micronaut-playground/.gitignore | 15 ++++++++++ micronaut-playground/application.yml | 4 +++ micronaut-playground/build.gradle.kts | 13 +++++++++ micronaut-playground/gradle.properties | 3 ++ micronaut-playground/micronaut-cli.yml | 6 ++++ micronaut-playground/settings.gradle.kts | 3 ++ .../micronaut/playground/Application.kt | 20 +++++++++++++ .../application/UserEventsService.kt | 13 +++++++++ .../playground/application/UserService.kt | 24 ++++++++++++++++ .../application/api/UserEventsApi.kt | 7 +++++ .../application/api/UserServiceApi.kt | 9 ++++++ .../playground/commons/events/Event.kt | 7 +++++ .../playground/commons/events/UserCreated.kt | 6 ++++ .../micronaut/playground/domain/User.kt | 6 ++++ .../playground/domain/UserRepository.kt | 7 +++++ .../infrastructure/events/KafkaListener.kt | 28 +++++++++++++++++++ .../infrastructure/implementation/Services.kt | 12 ++++++++ .../persistence/model/UserEntity.kt | 11 ++++++++ .../repository/DatabaseRepository.kt | 22 +++++++++++++++ .../repository/InMemoryRepository.kt | 20 +++++++++++++ .../infrastructure/web/UserHTTPController.kt | 26 +++++++++++++++++ .../infrastructure/web/api/Login.kt | 8 ++++++ .../infrastructure/web/api/Register.kt | 8 ++++++ .../websocket/WebsocketServer.kt | 19 +++++++++++++ .../src/main/resources/application.properties | 2 ++ .../src/main/resources/logback.xml | 14 ++++++++++ .../io/kotest/provided/ProjectConfig.kt | 8 ++++++ .../playground/DatabaseRepositoryTest.kt | 15 ++++++++++ .../playground/MicronautPlaygroundTest.kt | 9 ++++++ .../playground/UserControllerTest.kt | 11 ++++++++ settings.gradle.kts | 1 + 31 files changed, 357 insertions(+) create mode 100644 micronaut-playground/.gitignore create mode 100644 micronaut-playground/application.yml create mode 100644 micronaut-playground/build.gradle.kts create mode 100644 micronaut-playground/gradle.properties create mode 100644 micronaut-playground/micronaut-cli.yml create mode 100644 micronaut-playground/settings.gradle.kts create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt create mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt create mode 100644 micronaut-playground/src/main/resources/application.properties create mode 100644 micronaut-playground/src/main/resources/logback.xml create mode 100644 micronaut-playground/src/test/kotlin/io/kotest/provided/ProjectConfig.kt create mode 100644 micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt create mode 100644 micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt create mode 100644 micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt diff --git a/micronaut-playground/.gitignore b/micronaut-playground/.gitignore new file mode 100644 index 000000000..5a03bc30a --- /dev/null +++ b/micronaut-playground/.gitignore @@ -0,0 +1,15 @@ +Thumbs.db +.DS_Store +.gradle +build/ +target/ +out/ +.micronaut/ +.idea +*.iml +*.ipr +*.iws +.project +.settings +.classpath +.factorypath diff --git a/micronaut-playground/application.yml b/micronaut-playground/application.yml new file mode 100644 index 000000000..5ffef1fc3 --- /dev/null +++ b/micronaut-playground/application.yml @@ -0,0 +1,4 @@ +application: + name: "My Application" + version: "1.0.0" + description: "My Application Description" diff --git a/micronaut-playground/build.gradle.kts b/micronaut-playground/build.gradle.kts new file mode 100644 index 000000000..e34ba7d5d --- /dev/null +++ b/micronaut-playground/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("micronaut-base") +} + +application { + mainClass.set("micronaut.playground.ApplicationKt") +} + +dependencies { + ksp("io.micronaut.data:micronaut-data-document-processor") + implementation("io.micronaut.data:micronaut-data-mongodb") + runtimeOnly("org.mongodb:mongodb-driver-sync") +} \ No newline at end of file diff --git a/micronaut-playground/gradle.properties b/micronaut-playground/gradle.properties new file mode 100644 index 000000000..58cfb62e8 --- /dev/null +++ b/micronaut-playground/gradle.properties @@ -0,0 +1,3 @@ +micronautVersion=4.3.2 +kotlinVersion=1.9.22 +org.gradle.jvmargs=-Xmx4096M diff --git a/micronaut-playground/micronaut-cli.yml b/micronaut-playground/micronaut-cli.yml new file mode 100644 index 000000000..63847bca5 --- /dev/null +++ b/micronaut-playground/micronaut-cli.yml @@ -0,0 +1,6 @@ +applicationType: default +defaultPackage: micronaut.playground +testFramework: kotest +sourceLanguage: kotlin +buildTool: gradle_kotlin +features: [app-name, gradle, http-client-test, kotest, kotlin, kotlin-application, ksp, logback, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources] \ No newline at end of file diff --git a/micronaut-playground/settings.gradle.kts b/micronaut-playground/settings.gradle.kts new file mode 100644 index 000000000..f78138728 --- /dev/null +++ b/micronaut-playground/settings.gradle.kts @@ -0,0 +1,3 @@ + + +rootProject.name="micronaut-playground" diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt new file mode 100644 index 000000000..5560f7fa7 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt @@ -0,0 +1,20 @@ +package micronaut.playground + +import io.micronaut.runtime.Micronaut.run + +fun main(args: Array) { + run(*args) +} + +// LEVEL -> WHATS -> DEPENDENCIES +// -------------------------------- +// DOMAIN -> Language: +// - Entities +// - Value Objects +// - Repositories +// - Factories +// APPLICATION -> Domain +// - Services +// INTERFACES -> +// - Controller (Indepedent of the framework) +// INFRASTRUCTURE diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt new file mode 100644 index 000000000..7f80226ba --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt @@ -0,0 +1,13 @@ +package micronaut.playground.application + +import micronaut.playground.application.api.UserEventsApi +import micronaut.playground.commons.events.UserCreated +import micronaut.playground.domain.User +import micronaut.playground.domain.UserRepository + +class UserEventsService(private val userRepository: UserRepository) : UserEventsApi { + + override fun onUserCreated(userCreated: UserCreated) { + userRepository.save(User(email = userCreated.email, password = userCreated.password)) + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt new file mode 100644 index 000000000..dfabe319c --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt @@ -0,0 +1,24 @@ +package micronaut.playground.application + +import micronaut.playground.application.api.UserServiceApi +import micronaut.playground.commons.events.EventPublisher +import micronaut.playground.commons.events.UserCreated +import micronaut.playground.domain.User +import micronaut.playground.domain.UserRepository + +open class UserService( + private val userRepository: UserRepository, + private val eventPublisher: EventPublisher, +) : UserServiceApi { + + override fun registerUser(email: String, password: String): User { + val user = User(email = email, password = password) + return userRepository.save(user).also { + eventPublisher.publish(UserCreated(email = email, password = password)) + } + } + + override fun loginUser(email: String, password: String): User? { + return userRepository.findByEmail(email)?.takeIf { it.password == password } + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt new file mode 100644 index 000000000..8662bfb8c --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt @@ -0,0 +1,7 @@ +package micronaut.playground.application.api + +import micronaut.playground.commons.events.UserCreated + +interface UserEventsApi { + fun onUserCreated(userCreated: UserCreated) +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt new file mode 100644 index 000000000..a9f6320c3 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt @@ -0,0 +1,9 @@ +package micronaut.playground.application.api + +import micronaut.playground.domain.User + +interface UserServiceApi { + fun registerUser(email: String, password: String): User + + fun loginUser(email: String, password: String): User? +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt new file mode 100644 index 000000000..4240536c6 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt @@ -0,0 +1,7 @@ +package micronaut.playground.commons.events + +interface Event + +interface EventPublisher { + fun publish(event: Event) +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt new file mode 100644 index 000000000..743e60537 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt @@ -0,0 +1,6 @@ +package micronaut.playground.commons.events + +data class UserCreated( + val email: String, + val password: String, +) : Event diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt new file mode 100644 index 000000000..328c59a17 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt @@ -0,0 +1,6 @@ +package micronaut.playground.domain + +data class User( + val email: String, + val password: String, +) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt new file mode 100644 index 000000000..cf257dc38 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt @@ -0,0 +1,7 @@ +package micronaut.playground.domain + +interface UserRepository { + fun findByEmail(email: String): User? + + fun save(user: User): User +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt new file mode 100644 index 000000000..e1d0e2b74 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt @@ -0,0 +1,28 @@ +package micronaut.playground.infrastructure.events + +import jakarta.inject.Singleton +import micronaut.playground.commons.events.Event +import micronaut.playground.commons.events.EventPublisher + +@Singleton +class KafkaEventPublisher() : EventPublisher { + override fun publish(event: Event) { + println("Publishing event: $event") + } +} + +/** + * @Singleton class KafkaEventPublisher(): EventPublisher { + * + * override fun publish(any: Any) { + * + * } + * + * } + * + * @KafkaListener class KafkaListener(userEventsService: UserEventsService): UserEventsApi { + * @Topic("user-created") override fun onUserCreated(userCreated: UserCreated) { + * userEventsService.onUserCreated(userCreated) } + * + * } + */ diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt new file mode 100644 index 000000000..6ce9d9b8e --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt @@ -0,0 +1,12 @@ +package micronaut.playground.infrastructure.implementation + +import jakarta.inject.Singleton +import micronaut.playground.application.UserService +import micronaut.playground.commons.events.EventPublisher +import micronaut.playground.domain.UserRepository + +@Singleton +class UserServiceImpl( + userRepository: UserRepository, + eventPublisher: EventPublisher, +) : UserService(userRepository, eventPublisher) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt new file mode 100644 index 000000000..e64dea474 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt @@ -0,0 +1,11 @@ +package micronaut.playground.infrastructure.persistence.model + +import io.micronaut.data.annotation.Id +import io.micronaut.data.annotation.MappedEntity +import io.micronaut.data.mongodb.annotation.MongoRepository +import io.micronaut.data.repository.CrudRepository +import jakarta.validation.constraints.NotBlank + +@MappedEntity data class UserEntity(@Id val email: String, @NotBlank val password: String) + +@MongoRepository interface UserModelRepository : CrudRepository {} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt new file mode 100644 index 000000000..ab60a9a56 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt @@ -0,0 +1,22 @@ +package micronaut.playground.infrastructure.persistence.repository + +import io.micronaut.context.annotation.Primary +import jakarta.inject.Singleton +import micronaut.playground.domain.User +import micronaut.playground.domain.UserRepository +import micronaut.playground.infrastructure.persistence.model.UserEntity +import micronaut.playground.infrastructure.persistence.model.UserModelRepository + +@Singleton +@Primary +class UserRepositoryImpl(private val userModelRepository: UserModelRepository) : UserRepository { + + override fun findByEmail(email: String): User? { + return userModelRepository.findById(email).map { User(it.email, it.password) }.orElse(null) + } + + override fun save(user: User): User { + val userModel = UserEntity(user.email, user.password) + return userModelRepository.save(userModel).let { User(it.email, it.password) } + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt new file mode 100644 index 000000000..bc94a0b9d --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt @@ -0,0 +1,20 @@ +package micronaut.playground.infrastructure.persistence.repository + +import jakarta.inject.Named +import micronaut.playground.domain.User +import micronaut.playground.domain.UserRepository + +@Named("inMemory") +class InMemoryRepository : UserRepository { + + val users = mutableListOf() + + override fun findByEmail(email: String): User? { + return users.find { it.email == email } + } + + override fun save(user: User): User { + users.add(user) + return user + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt new file mode 100644 index 000000000..924608b49 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt @@ -0,0 +1,26 @@ +package micronaut.playground.infrastructure.web + +import io.micronaut.http.annotation.Body +import io.micronaut.http.annotation.Controller +import io.micronaut.http.annotation.Post +import micronaut.playground.application.UserService +import micronaut.playground.infrastructure.web.api.LoginRequest +import micronaut.playground.infrastructure.web.api.LoginResponse +import micronaut.playground.infrastructure.web.api.RegisterRequest +import micronaut.playground.infrastructure.web.api.RegisterResponse + +@Controller("/users") +class UserHTTPController(private val userService: UserService) { + + @Post("/login", consumes = ["application/json"], produces = ["application/json"]) + fun login(@Body request: LoginRequest): LoginResponse { + val result = userService.loginUser(request.email, request.password) + return LoginResponse(result?.email ?: "") + } + + @Post("/register") + fun register(@Body request: RegisterRequest): RegisterResponse { + val result = userService.registerUser(request.email, request.password) + return RegisterResponse(result.email) + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt new file mode 100644 index 000000000..c0d1b48eb --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt @@ -0,0 +1,8 @@ +package micronaut.playground.infrastructure.web.api + +import io.micronaut.serde.annotation.Serdeable +import jakarta.validation.constraints.NotBlank + +@Serdeable data class LoginRequest(@NotBlank val email: String, val password: String) + +@Serdeable data class LoginResponse(val email: String) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt new file mode 100644 index 000000000..596cd9877 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt @@ -0,0 +1,8 @@ +package micronaut.playground.infrastructure.web.api + +import io.micronaut.serde.annotation.Serdeable +import jakarta.validation.constraints.NotBlank + +@Serdeable data class RegisterRequest(@NotBlank val email: String, @NotBlank val password: String) + +@Serdeable data class RegisterResponse(@NotBlank val email: String) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt new file mode 100644 index 000000000..b614d1493 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt @@ -0,0 +1,19 @@ +package micronaut.playground.infrastructure.websocket + +import io.micronaut.websocket.annotation.OnMessage +import io.micronaut.websocket.annotation.OnOpen +import io.micronaut.websocket.annotation.ServerWebSocket + +@ServerWebSocket("/ws") +class WebsocketServer { + + @OnOpen + fun onOpen() { + println("Client connected") + } + + @OnMessage + fun onMessage(message: String) { + println("Received message: $message") + } +} diff --git a/micronaut-playground/src/main/resources/application.properties b/micronaut-playground/src/main/resources/application.properties new file mode 100644 index 000000000..ec2059a50 --- /dev/null +++ b/micronaut-playground/src/main/resources/application.properties @@ -0,0 +1,2 @@ +#Thu Feb 22 11:03:09 CET 2024 +micronaut.application.name=micronaut-playground \ No newline at end of file diff --git a/micronaut-playground/src/main/resources/logback.xml b/micronaut-playground/src/main/resources/logback.xml new file mode 100644 index 000000000..2d77bdab5 --- /dev/null +++ b/micronaut-playground/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + + + + + + + diff --git a/micronaut-playground/src/test/kotlin/io/kotest/provided/ProjectConfig.kt b/micronaut-playground/src/test/kotlin/io/kotest/provided/ProjectConfig.kt new file mode 100644 index 000000000..a328bf464 --- /dev/null +++ b/micronaut-playground/src/test/kotlin/io/kotest/provided/ProjectConfig.kt @@ -0,0 +1,8 @@ +package io.kotest.provided + +import io.kotest.core.config.AbstractProjectConfig +import io.micronaut.test.extensions.kotest5.MicronautKotest5Extension + +object ProjectConfig : AbstractProjectConfig() { + override fun extensions() = listOf(MicronautKotest5Extension) +} diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt b/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt new file mode 100644 index 000000000..ea99ae9cb --- /dev/null +++ b/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt @@ -0,0 +1,15 @@ +package micronaut.playground + +import io.kotest.core.spec.style.AnnotationSpec +import io.micronaut.test.extensions.kotest5.annotation.MicronautTest +import micronaut.playground.domain.UserRepository + +@MicronautTest +class DatabaseRepositoryTest(private val userRepository: UserRepository) : AnnotationSpec() { + + @Test + fun testUserRepository() { + val users = userRepository.findByEmail("email") + assert(users == null) + } +} diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt b/micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt new file mode 100644 index 000000000..695a77734 --- /dev/null +++ b/micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt @@ -0,0 +1,9 @@ +package micronaut.playground + +import io.kotest.core.spec.style.StringSpec +import io.micronaut.runtime.EmbeddedApplication +import io.micronaut.test.extensions.kotest5.annotation.MicronautTest + +@MicronautTest +class MicronautPlaygroundTest(private val application: EmbeddedApplication<*>) : + StringSpec({ "test the server is running" { assert(application.isRunning) } }) diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt b/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt new file mode 100644 index 000000000..2ec00a8f0 --- /dev/null +++ b/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt @@ -0,0 +1,11 @@ +package micronaut.playground + +import io.kotest.core.spec.style.AnnotationSpec +import io.micronaut.test.extensions.kotest5.annotation.MicronautTest +import micronaut.playground.application.api.UserServiceApi + +@MicronautTest +class UserControllerTest(private val userServiceApi: UserServiceApi) : AnnotationSpec() { + + @Test fun test() {} +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 537e6c338..f6951e867 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -35,3 +35,4 @@ include("bdd") include("commons") include("users-service") include("servers-service") +include("micronaut-playground") From 19d9d70a45bdec4de36565caa2c8a1afae76c05e Mon Sep 17 00:00:00 2001 From: Alessandro Mazzoli Date: Mon, 4 Mar 2024 13:55:14 +0100 Subject: [PATCH 4/7] fix(style): corrected kfmtm and detekt errors --- .gitignore | 3 +++ micronaut-playground/application.yml | 6 +++--- micronaut-playground/build.gradle.kts | 10 +++------- micronaut-playground/micronaut-cli.yml | 2 +- micronaut-playground/settings.gradle.kts | 4 +--- .../main/kotlin/micronaut/playground/Application.kt | 2 +- .../playground/application/UserEventsService.kt | 1 - .../micronaut/playground/application/UserService.kt | 11 ++++++++--- .../playground/application/api/UserServiceApi.kt | 10 ++++++++-- .../{KafkaListener.kt => KafkaEventPublisher.kt} | 2 +- .../{Services.kt => UserServiceImpl.kt} | 0 .../infrastructure/persistence/model/UserEntity.kt | 8 ++++++-- .../persistence/repository/InMemoryRepository.kt | 1 - .../{DatabaseRepository.kt => UserRepositoryImpl.kt} | 1 - .../infrastructure/web/UserHTTPController.kt | 9 ++++++--- .../infrastructure/websocket/WebsocketServer.kt | 1 - micronaut-playground/src/main/resources/logback.xml | 5 +++-- .../micronaut/playground/DatabaseRepositoryTest.kt | 1 - .../kotlin/micronaut/playground/UserControllerTest.kt | 7 +------ 19 files changed, 45 insertions(+), 39 deletions(-) rename micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/{KafkaListener.kt => KafkaEventPublisher.kt} (93%) rename micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/{Services.kt => UserServiceImpl.kt} (100%) rename micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/{DatabaseRepository.kt => UserRepositoryImpl.kt} (99%) diff --git a/.gitignore b/.gitignore index 302a2c4e0..a77f0ce32 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ .idea/.gitignore .idea/vcs.xml .idea/ktfmt.xml +.idea/codeStyles/** +.idea/detekt.xml +.idea/ktlint-plugin.xml # CMake cmake-build-*/ diff --git a/micronaut-playground/application.yml b/micronaut-playground/application.yml index 5ffef1fc3..875e3675f 100644 --- a/micronaut-playground/application.yml +++ b/micronaut-playground/application.yml @@ -1,4 +1,4 @@ application: - name: "My Application" - version: "1.0.0" - description: "My Application Description" + name: "My Application" + version: "1.0.0" + description: "My Application Description" diff --git a/micronaut-playground/build.gradle.kts b/micronaut-playground/build.gradle.kts index e34ba7d5d..d74ae531b 100644 --- a/micronaut-playground/build.gradle.kts +++ b/micronaut-playground/build.gradle.kts @@ -1,13 +1,9 @@ -plugins { - id("micronaut-base") -} +plugins { id("micronaut-base") } -application { - mainClass.set("micronaut.playground.ApplicationKt") -} +application { mainClass.set("micronaut.playground.ApplicationKt") } dependencies { ksp("io.micronaut.data:micronaut-data-document-processor") implementation("io.micronaut.data:micronaut-data-mongodb") runtimeOnly("org.mongodb:mongodb-driver-sync") -} \ No newline at end of file +} diff --git a/micronaut-playground/micronaut-cli.yml b/micronaut-playground/micronaut-cli.yml index 63847bca5..bb018198e 100644 --- a/micronaut-playground/micronaut-cli.yml +++ b/micronaut-playground/micronaut-cli.yml @@ -3,4 +3,4 @@ defaultPackage: micronaut.playground testFramework: kotest sourceLanguage: kotlin buildTool: gradle_kotlin -features: [app-name, gradle, http-client-test, kotest, kotlin, kotlin-application, ksp, logback, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources] \ No newline at end of file +features: [ app-name, gradle, http-client-test, kotest, kotlin, kotlin-application, ksp, logback, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources ] \ No newline at end of file diff --git a/micronaut-playground/settings.gradle.kts b/micronaut-playground/settings.gradle.kts index f78138728..e4c841aa6 100644 --- a/micronaut-playground/settings.gradle.kts +++ b/micronaut-playground/settings.gradle.kts @@ -1,3 +1 @@ - - -rootProject.name="micronaut-playground" +rootProject.name = "micronaut-playground" diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt index 5560f7fa7..cb620a9de 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt @@ -2,7 +2,7 @@ package micronaut.playground import io.micronaut.runtime.Micronaut.run -fun main(args: Array) { +fun main(vararg args: String) { run(*args) } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt index 7f80226ba..e8cf38959 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt @@ -6,7 +6,6 @@ import micronaut.playground.domain.User import micronaut.playground.domain.UserRepository class UserEventsService(private val userRepository: UserRepository) : UserEventsApi { - override fun onUserCreated(userCreated: UserCreated) { userRepository.save(User(email = userCreated.email, password = userCreated.password)) } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt index dfabe319c..36a351166 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt @@ -10,15 +10,20 @@ open class UserService( private val userRepository: UserRepository, private val eventPublisher: EventPublisher, ) : UserServiceApi { - - override fun registerUser(email: String, password: String): User { + override fun registerUser( + email: String, + password: String, + ): User { val user = User(email = email, password = password) return userRepository.save(user).also { eventPublisher.publish(UserCreated(email = email, password = password)) } } - override fun loginUser(email: String, password: String): User? { + override fun loginUser( + email: String, + password: String, + ): User? { return userRepository.findByEmail(email)?.takeIf { it.password == password } } } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt index a9f6320c3..16c87011a 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt @@ -3,7 +3,13 @@ package micronaut.playground.application.api import micronaut.playground.domain.User interface UserServiceApi { - fun registerUser(email: String, password: String): User + fun registerUser( + email: String, + password: String, + ): User - fun loginUser(email: String, password: String): User? + fun loginUser( + email: String, + password: String, + ): User? } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt similarity index 93% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt rename to micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt index e1d0e2b74..902a36921 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaListener.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt @@ -5,7 +5,7 @@ import micronaut.playground.commons.events.Event import micronaut.playground.commons.events.EventPublisher @Singleton -class KafkaEventPublisher() : EventPublisher { +class KafkaEventPublisher : EventPublisher { override fun publish(event: Event) { println("Publishing event: $event") } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt similarity index 100% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/Services.kt rename to micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt index e64dea474..50251ed2d 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt @@ -6,6 +6,10 @@ import io.micronaut.data.mongodb.annotation.MongoRepository import io.micronaut.data.repository.CrudRepository import jakarta.validation.constraints.NotBlank -@MappedEntity data class UserEntity(@Id val email: String, @NotBlank val password: String) +@MappedEntity +data class UserEntity( + @Id val email: String, + @NotBlank val password: String, +) -@MongoRepository interface UserModelRepository : CrudRepository {} +@MongoRepository interface UserModelRepository : CrudRepository diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt index bc94a0b9d..0341e11d8 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt @@ -6,7 +6,6 @@ import micronaut.playground.domain.UserRepository @Named("inMemory") class InMemoryRepository : UserRepository { - val users = mutableListOf() override fun findByEmail(email: String): User? { diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt similarity index 99% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt rename to micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt index ab60a9a56..2727dd920 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/DatabaseRepository.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt @@ -10,7 +10,6 @@ import micronaut.playground.infrastructure.persistence.model.UserModelRepository @Singleton @Primary class UserRepositoryImpl(private val userModelRepository: UserModelRepository) : UserRepository { - override fun findByEmail(email: String): User? { return userModelRepository.findById(email).map { User(it.email, it.password) }.orElse(null) } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt index 924608b49..9cf66ab48 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt @@ -11,15 +11,18 @@ import micronaut.playground.infrastructure.web.api.RegisterResponse @Controller("/users") class UserHTTPController(private val userService: UserService) { - @Post("/login", consumes = ["application/json"], produces = ["application/json"]) - fun login(@Body request: LoginRequest): LoginResponse { + fun login( + @Body request: LoginRequest, + ): LoginResponse { val result = userService.loginUser(request.email, request.password) return LoginResponse(result?.email ?: "") } @Post("/register") - fun register(@Body request: RegisterRequest): RegisterResponse { + fun register( + @Body request: RegisterRequest, + ): RegisterResponse { val result = userService.registerUser(request.email, request.password) return RegisterResponse(result.email) } diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt index b614d1493..1ca610d00 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt +++ b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt @@ -6,7 +6,6 @@ import io.micronaut.websocket.annotation.ServerWebSocket @ServerWebSocket("/ws") class WebsocketServer { - @OnOpen fun onOpen() { println("Client connected") diff --git a/micronaut-playground/src/main/resources/logback.xml b/micronaut-playground/src/main/resources/logback.xml index 2d77bdab5..4b0818562 100644 --- a/micronaut-playground/src/main/resources/logback.xml +++ b/micronaut-playground/src/main/resources/logback.xml @@ -4,11 +4,12 @@ - %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + - + diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt b/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt index ea99ae9cb..8b05ad2fb 100644 --- a/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt +++ b/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt @@ -6,7 +6,6 @@ import micronaut.playground.domain.UserRepository @MicronautTest class DatabaseRepositoryTest(private val userRepository: UserRepository) : AnnotationSpec() { - @Test fun testUserRepository() { val users = userRepository.findByEmail("email") diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt b/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt index 2ec00a8f0..f533dd08d 100644 --- a/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt +++ b/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt @@ -2,10 +2,5 @@ package micronaut.playground import io.kotest.core.spec.style.AnnotationSpec import io.micronaut.test.extensions.kotest5.annotation.MicronautTest -import micronaut.playground.application.api.UserServiceApi -@MicronautTest -class UserControllerTest(private val userServiceApi: UserServiceApi) : AnnotationSpec() { - - @Test fun test() {} -} +@MicronautTest class UserControllerTest : AnnotationSpec() From 8e0c8fef03674eeef753b08aa26074325464f74e Mon Sep 17 00:00:00 2001 From: Alessandro Mazzoli Date: Mon, 4 Mar 2024 14:09:20 +0100 Subject: [PATCH 5/7] chore(style): renamed base package to follow conventions --- .../playground/application/UserEventsService.kt | 12 ------------ .../playground/application/api/UserEventsApi.kt | 7 ------- .../implementation/UserServiceImpl.kt | 12 ------------ .../playground/infrastructure/web/api/Login.kt | 8 -------- .../playground/infrastructure/web/api/Register.kt | 8 -------- .../services/template}/Application.kt | 2 +- .../template/application/UserEventsService.kt | 12 ++++++++++++ .../services/template}/application/UserService.kt | 12 ++++++------ .../template/application/api/UserEventsApi.kt | 7 +++++++ .../template}/application/api/UserServiceApi.kt | 4 ++-- .../services/template}/commons/events/Event.kt | 2 +- .../template}/commons/events/UserCreated.kt | 2 +- .../services/template}/domain/User.kt | 2 +- .../services/template}/domain/UserRepository.kt | 2 +- .../infrastructure/events/KafkaEventPublisher.kt | 6 +++--- .../implementation/UserServiceImpl.kt | 11 +++++++++++ .../persistence/model/UserEntity.kt | 2 +- .../persistence/repository/InMemoryRepository.kt | 6 +++--- .../persistence/repository/UserRepositoryImpl.kt | 10 +++++----- .../infrastructure/web/UserHTTPController.kt | 15 ++++++++------- .../template/infrastructure/web/api/Login.kt | 12 ++++++++++++ .../template/infrastructure/web/api/Register.kt | 15 +++++++++++++++ .../infrastructure/websocket/WebsocketServer.kt | 2 +- .../services/template}/DatabaseRepositoryTest.kt | 4 ++-- .../services/template}/MicronautPlaygroundTest.kt | 2 +- .../services/template}/UserControllerTest.kt | 2 +- 26 files changed, 95 insertions(+), 84 deletions(-) delete mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt delete mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt delete mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt delete mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt delete mode 100644 micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/Application.kt (91%) create mode 100644 micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserEventsService.kt rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/application/UserService.kt (65%) create mode 100644 micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserEventsApi.kt rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/application/api/UserServiceApi.kt (67%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/commons/events/Event.kt (61%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/commons/events/UserCreated.kt (63%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/domain/User.kt (62%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/domain/UserRepository.kt (71%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/events/KafkaEventPublisher.kt (75%) create mode 100644 micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/implementation/UserServiceImpl.kt rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/persistence/model/UserEntity.kt (86%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/persistence/repository/InMemoryRepository.kt (66%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/persistence/repository/UserRepositoryImpl.kt (62%) rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/web/UserHTTPController.kt (60%) create mode 100644 micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Login.kt create mode 100644 micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Register.kt rename micronaut-playground/src/main/kotlin/{micronaut/playground => piperkt/services/template}/infrastructure/websocket/WebsocketServer.kt (86%) rename micronaut-playground/src/test/kotlin/{micronaut/playground => piperkt/services/template}/DatabaseRepositoryTest.kt (80%) rename micronaut-playground/src/test/kotlin/{micronaut/playground => piperkt/services/template}/MicronautPlaygroundTest.kt (90%) rename micronaut-playground/src/test/kotlin/{micronaut/playground => piperkt/services/template}/UserControllerTest.kt (83%) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt deleted file mode 100644 index e8cf38959..000000000 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserEventsService.kt +++ /dev/null @@ -1,12 +0,0 @@ -package micronaut.playground.application - -import micronaut.playground.application.api.UserEventsApi -import micronaut.playground.commons.events.UserCreated -import micronaut.playground.domain.User -import micronaut.playground.domain.UserRepository - -class UserEventsService(private val userRepository: UserRepository) : UserEventsApi { - override fun onUserCreated(userCreated: UserCreated) { - userRepository.save(User(email = userCreated.email, password = userCreated.password)) - } -} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt deleted file mode 100644 index 8662bfb8c..000000000 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserEventsApi.kt +++ /dev/null @@ -1,7 +0,0 @@ -package micronaut.playground.application.api - -import micronaut.playground.commons.events.UserCreated - -interface UserEventsApi { - fun onUserCreated(userCreated: UserCreated) -} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt deleted file mode 100644 index 6ce9d9b8e..000000000 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/implementation/UserServiceImpl.kt +++ /dev/null @@ -1,12 +0,0 @@ -package micronaut.playground.infrastructure.implementation - -import jakarta.inject.Singleton -import micronaut.playground.application.UserService -import micronaut.playground.commons.events.EventPublisher -import micronaut.playground.domain.UserRepository - -@Singleton -class UserServiceImpl( - userRepository: UserRepository, - eventPublisher: EventPublisher, -) : UserService(userRepository, eventPublisher) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt deleted file mode 100644 index c0d1b48eb..000000000 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Login.kt +++ /dev/null @@ -1,8 +0,0 @@ -package micronaut.playground.infrastructure.web.api - -import io.micronaut.serde.annotation.Serdeable -import jakarta.validation.constraints.NotBlank - -@Serdeable data class LoginRequest(@NotBlank val email: String, val password: String) - -@Serdeable data class LoginResponse(val email: String) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt b/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt deleted file mode 100644 index 596cd9877..000000000 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/api/Register.kt +++ /dev/null @@ -1,8 +0,0 @@ -package micronaut.playground.infrastructure.web.api - -import io.micronaut.serde.annotation.Serdeable -import jakarta.validation.constraints.NotBlank - -@Serdeable data class RegisterRequest(@NotBlank val email: String, @NotBlank val password: String) - -@Serdeable data class RegisterResponse(@NotBlank val email: String) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/Application.kt similarity index 91% rename from micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/Application.kt index cb620a9de..8ca0e4f32 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/Application.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/Application.kt @@ -1,4 +1,4 @@ -package micronaut.playground +package piperkt.services.template import io.micronaut.runtime.Micronaut.run diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserEventsService.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserEventsService.kt new file mode 100644 index 000000000..8790d5362 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserEventsService.kt @@ -0,0 +1,12 @@ +package piperkt.services.template.application + +import piperkt.services.template.application.api.UserEventsApi +import piperkt.services.template.commons.events.UserCreated +import piperkt.services.template.domain.User +import piperkt.services.template.domain.UserRepository + +class UserEventsService(private val userRepository: UserRepository) : UserEventsApi { + override fun onUserCreated(userCreated: UserCreated) { + userRepository.save(User(email = userCreated.email, password = userCreated.password)) + } +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt similarity index 65% rename from micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt index 36a351166..9274900b4 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/UserService.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt @@ -1,10 +1,10 @@ -package micronaut.playground.application +package piperkt.services.template.application -import micronaut.playground.application.api.UserServiceApi -import micronaut.playground.commons.events.EventPublisher -import micronaut.playground.commons.events.UserCreated -import micronaut.playground.domain.User -import micronaut.playground.domain.UserRepository +import piperkt.services.template.application.api.UserServiceApi +import piperkt.services.template.commons.events.EventPublisher +import piperkt.services.template.commons.events.UserCreated +import piperkt.services.template.domain.User +import piperkt.services.template.domain.UserRepository open class UserService( private val userRepository: UserRepository, diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserEventsApi.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserEventsApi.kt new file mode 100644 index 000000000..790a69e0b --- /dev/null +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserEventsApi.kt @@ -0,0 +1,7 @@ +package piperkt.services.template.application.api + +import piperkt.services.template.commons.events.UserCreated + +interface UserEventsApi { + fun onUserCreated(userCreated: UserCreated) +} diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserServiceApi.kt similarity index 67% rename from micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserServiceApi.kt index 16c87011a..455b64b0b 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/application/api/UserServiceApi.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/api/UserServiceApi.kt @@ -1,6 +1,6 @@ -package micronaut.playground.application.api +package piperkt.services.template.application.api -import micronaut.playground.domain.User +import piperkt.services.template.domain.User interface UserServiceApi { fun registerUser( diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/Event.kt similarity index 61% rename from micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/Event.kt index 4240536c6..9dfa4c22f 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/Event.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/Event.kt @@ -1,4 +1,4 @@ -package micronaut.playground.commons.events +package piperkt.services.template.commons.events interface Event diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/UserCreated.kt similarity index 63% rename from micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/UserCreated.kt index 743e60537..c7abb5c11 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/commons/events/UserCreated.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/UserCreated.kt @@ -1,4 +1,4 @@ -package micronaut.playground.commons.events +package piperkt.services.template.commons.events data class UserCreated( val email: String, diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/domain/User.kt similarity index 62% rename from micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/domain/User.kt index 328c59a17..177e7b229 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/User.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/domain/User.kt @@ -1,4 +1,4 @@ -package micronaut.playground.domain +package piperkt.services.template.domain data class User( val email: String, diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/domain/UserRepository.kt similarity index 71% rename from micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/domain/UserRepository.kt index cf257dc38..5539dce46 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/domain/UserRepository.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/domain/UserRepository.kt @@ -1,4 +1,4 @@ -package micronaut.playground.domain +package piperkt.services.template.domain interface UserRepository { fun findByEmail(email: String): User? diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/events/KafkaEventPublisher.kt similarity index 75% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/events/KafkaEventPublisher.kt index 902a36921..73c91f2d7 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/events/KafkaEventPublisher.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/events/KafkaEventPublisher.kt @@ -1,8 +1,8 @@ -package micronaut.playground.infrastructure.events +package piperkt.services.template.infrastructure.events import jakarta.inject.Singleton -import micronaut.playground.commons.events.Event -import micronaut.playground.commons.events.EventPublisher +import piperkt.services.template.commons.events.Event +import piperkt.services.template.commons.events.EventPublisher @Singleton class KafkaEventPublisher : EventPublisher { diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/implementation/UserServiceImpl.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/implementation/UserServiceImpl.kt new file mode 100644 index 000000000..5045448bf --- /dev/null +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/implementation/UserServiceImpl.kt @@ -0,0 +1,11 @@ +package piperkt.services.template.infrastructure.implementation + +import jakarta.inject.Singleton +import piperkt.services.template.commons.events.EventPublisher +import piperkt.services.template.domain.UserRepository + +@Singleton +class UserServiceImpl( + userRepository: UserRepository, + eventPublisher: EventPublisher, +) : piperkt.services.template.application.UserService(userRepository, eventPublisher) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/model/UserEntity.kt similarity index 86% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/model/UserEntity.kt index 50251ed2d..953375a9c 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/model/UserEntity.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/model/UserEntity.kt @@ -1,4 +1,4 @@ -package micronaut.playground.infrastructure.persistence.model +package piperkt.services.template.infrastructure.persistence.model import io.micronaut.data.annotation.Id import io.micronaut.data.annotation.MappedEntity diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt similarity index 66% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt index 0341e11d8..a8f724fb3 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/InMemoryRepository.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt @@ -1,8 +1,8 @@ -package micronaut.playground.infrastructure.persistence.repository +package piperkt.services.template.infrastructure.persistence.repository import jakarta.inject.Named -import micronaut.playground.domain.User -import micronaut.playground.domain.UserRepository +import piperkt.services.template.domain.User +import piperkt.services.template.domain.UserRepository @Named("inMemory") class InMemoryRepository : UserRepository { diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt similarity index 62% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt index 2727dd920..575ac9201 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/persistence/repository/UserRepositoryImpl.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt @@ -1,11 +1,11 @@ -package micronaut.playground.infrastructure.persistence.repository +package piperkt.services.template.infrastructure.persistence.repository import io.micronaut.context.annotation.Primary import jakarta.inject.Singleton -import micronaut.playground.domain.User -import micronaut.playground.domain.UserRepository -import micronaut.playground.infrastructure.persistence.model.UserEntity -import micronaut.playground.infrastructure.persistence.model.UserModelRepository +import piperkt.services.template.domain.User +import piperkt.services.template.domain.UserRepository +import piperkt.services.template.infrastructure.persistence.model.UserEntity +import piperkt.services.template.infrastructure.persistence.model.UserModelRepository @Singleton @Primary diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt similarity index 60% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt index 9cf66ab48..d5551bd51 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/web/UserHTTPController.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt @@ -1,16 +1,17 @@ -package micronaut.playground.infrastructure.web +package piperkt.services.template.infrastructure.web import io.micronaut.http.annotation.Body import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Post -import micronaut.playground.application.UserService -import micronaut.playground.infrastructure.web.api.LoginRequest -import micronaut.playground.infrastructure.web.api.LoginResponse -import micronaut.playground.infrastructure.web.api.RegisterRequest -import micronaut.playground.infrastructure.web.api.RegisterResponse +import piperkt.services.template.infrastructure.web.api.LoginRequest +import piperkt.services.template.infrastructure.web.api.LoginResponse +import piperkt.services.template.infrastructure.web.api.RegisterRequest +import piperkt.services.template.infrastructure.web.api.RegisterResponse @Controller("/users") -class UserHTTPController(private val userService: UserService) { +class UserHTTPController( + private val userService: piperkt.services.template.application.UserService, +) { @Post("/login", consumes = ["application/json"], produces = ["application/json"]) fun login( @Body request: LoginRequest, diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Login.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Login.kt new file mode 100644 index 000000000..c61b48014 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Login.kt @@ -0,0 +1,12 @@ +package piperkt.services.template.infrastructure.web.api + +import io.micronaut.serde.annotation.Serdeable +import jakarta.validation.constraints.NotBlank + +@Serdeable +data class LoginRequest( + @NotBlank val email: String, + val password: String, +) + +@Serdeable data class LoginResponse(val email: String) diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Register.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Register.kt new file mode 100644 index 000000000..9ed2b0d41 --- /dev/null +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/api/Register.kt @@ -0,0 +1,15 @@ +package piperkt.services.template.infrastructure.web.api + +import io.micronaut.serde.annotation.Serdeable +import jakarta.validation.constraints.NotBlank + +@Serdeable +data class RegisterRequest( + @NotBlank val email: String, + @NotBlank val password: String, +) + +@Serdeable +data class RegisterResponse( + @NotBlank val email: String, +) diff --git a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/websocket/WebsocketServer.kt similarity index 86% rename from micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt rename to micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/websocket/WebsocketServer.kt index 1ca610d00..6bbde1729 100644 --- a/micronaut-playground/src/main/kotlin/micronaut/playground/infrastructure/websocket/WebsocketServer.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/websocket/WebsocketServer.kt @@ -1,4 +1,4 @@ -package micronaut.playground.infrastructure.websocket +package piperkt.services.template.infrastructure.websocket import io.micronaut.websocket.annotation.OnMessage import io.micronaut.websocket.annotation.OnOpen diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt b/micronaut-playground/src/test/kotlin/piperkt/services/template/DatabaseRepositoryTest.kt similarity index 80% rename from micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt rename to micronaut-playground/src/test/kotlin/piperkt/services/template/DatabaseRepositoryTest.kt index 8b05ad2fb..fd3a812b7 100644 --- a/micronaut-playground/src/test/kotlin/micronaut/playground/DatabaseRepositoryTest.kt +++ b/micronaut-playground/src/test/kotlin/piperkt/services/template/DatabaseRepositoryTest.kt @@ -1,8 +1,8 @@ -package micronaut.playground +package piperkt.services.template import io.kotest.core.spec.style.AnnotationSpec import io.micronaut.test.extensions.kotest5.annotation.MicronautTest -import micronaut.playground.domain.UserRepository +import piperkt.services.template.domain.UserRepository @MicronautTest class DatabaseRepositoryTest(private val userRepository: UserRepository) : AnnotationSpec() { diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt b/micronaut-playground/src/test/kotlin/piperkt/services/template/MicronautPlaygroundTest.kt similarity index 90% rename from micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt rename to micronaut-playground/src/test/kotlin/piperkt/services/template/MicronautPlaygroundTest.kt index 695a77734..3a2ba1730 100644 --- a/micronaut-playground/src/test/kotlin/micronaut/playground/MicronautPlaygroundTest.kt +++ b/micronaut-playground/src/test/kotlin/piperkt/services/template/MicronautPlaygroundTest.kt @@ -1,4 +1,4 @@ -package micronaut.playground +package piperkt.services.template import io.kotest.core.spec.style.StringSpec import io.micronaut.runtime.EmbeddedApplication diff --git a/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt b/micronaut-playground/src/test/kotlin/piperkt/services/template/UserControllerTest.kt similarity index 83% rename from micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt rename to micronaut-playground/src/test/kotlin/piperkt/services/template/UserControllerTest.kt index f533dd08d..bd599871f 100644 --- a/micronaut-playground/src/test/kotlin/micronaut/playground/UserControllerTest.kt +++ b/micronaut-playground/src/test/kotlin/piperkt/services/template/UserControllerTest.kt @@ -1,4 +1,4 @@ -package micronaut.playground +package piperkt.services.template import io.kotest.core.spec.style.AnnotationSpec import io.micronaut.test.extensions.kotest5.annotation.MicronautTest From 136c2e1486d35341816f9c0c1fb76a7630e4e6f5 Mon Sep 17 00:00:00 2001 From: luigi-borriello00 Date: Mon, 4 Mar 2024 15:04:04 +0100 Subject: [PATCH 6/7] refactor(template): resolve deepsource bugs --- build-logic/src/main/kotlin/Utils.kt | 2 +- .../piperkt/services/template/application/UserService.kt | 4 +--- .../persistence/repository/InMemoryRepository.kt | 4 +--- .../persistence/repository/UserRepositoryImpl.kt | 5 ++--- .../template/infrastructure/web/UserHTTPController.kt | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/build-logic/src/main/kotlin/Utils.kt b/build-logic/src/main/kotlin/Utils.kt index 2651a502d..d085a0e28 100644 --- a/build-logic/src/main/kotlin/Utils.kt +++ b/build-logic/src/main/kotlin/Utils.kt @@ -8,6 +8,6 @@ fun VersionCatalog.getLibrary(name: String): Provider = findBundle(name).get() object JavaVersion { - val asInt: Int = 17 + const val asInt: Int = 17 val asVersion: org.gradle.api.JavaVersion = org.gradle.api.JavaVersion.toVersion(asInt) } diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt index 9274900b4..34deb3701 100644 --- a/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt @@ -23,7 +23,5 @@ open class UserService( override fun loginUser( email: String, password: String, - ): User? { - return userRepository.findByEmail(email)?.takeIf { it.password == password } - } + ): User? = userRepository.findByEmail(email)?.takeIf { it.password == password } } diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt index a8f724fb3..cd14828ed 100644 --- a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt @@ -8,9 +8,7 @@ import piperkt.services.template.domain.UserRepository class InMemoryRepository : UserRepository { val users = mutableListOf() - override fun findByEmail(email: String): User? { - return users.find { it.email == email } - } + override fun findByEmail(email: String): User? = users.find { it.email == email } override fun save(user: User): User { users.add(user) diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt index 575ac9201..c949461e8 100644 --- a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/persistence/repository/UserRepositoryImpl.kt @@ -10,9 +10,8 @@ import piperkt.services.template.infrastructure.persistence.model.UserModelRepos @Singleton @Primary class UserRepositoryImpl(private val userModelRepository: UserModelRepository) : UserRepository { - override fun findByEmail(email: String): User? { - return userModelRepository.findById(email).map { User(it.email, it.password) }.orElse(null) - } + override fun findByEmail(email: String): User? = + userModelRepository.findById(email).map { User(it.email, it.password) }.orElse(null) override fun save(user: User): User { val userModel = UserEntity(user.email, user.password) diff --git a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt index d5551bd51..4b3e1a46a 100644 --- a/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt +++ b/micronaut-playground/src/main/kotlin/piperkt/services/template/infrastructure/web/UserHTTPController.kt @@ -17,7 +17,7 @@ class UserHTTPController( @Body request: LoginRequest, ): LoginResponse { val result = userService.loginUser(request.email, request.password) - return LoginResponse(result?.email ?: "") + return LoginResponse(result?.email.orEmpty()) } @Post("/register") From 97ef2dd05fa51358c61623ed9950a3c8f3235a7f Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Tue, 5 Mar 2024 17:19:00 +0100 Subject: [PATCH 7/7] ci: comment testing on windows and macos until find a fix for containertests --- .github/workflows/release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be6afb0a4..be803a72d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,9 +33,10 @@ jobs: fail-fast: false matrix: os: - - macos-13 +# Commented until we find a way to run containertests on macOS and Windows +# - macos-13 - ubuntu-22.04 - - windows-2022 +# - windows-2022 java-version: [ 17, 21 ] java-distribution: - adopt