-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from zucchero-sintattico/feature/micronaut-pro…
…ject-structure Prepare Template for Microservice Develop
- Loading branch information
Showing
38 changed files
with
454 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
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<MinimalExternalModuleDependency> = findLibrary(name).get() | ||
|
||
fun VersionCatalog.getBundle(name: String): Provider<ExternalModuleDependencyBundle> = findBundle(name).get() | ||
|
||
object JavaVersion { | ||
const val target: Int = 17 | ||
const val asInt: Int = 17 | ||
val asVersion: org.gradle.api.JavaVersion = org.gradle.api.JavaVersion.toVersion(asInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ tasks.test { | |
} | ||
|
||
kotlin { | ||
jvmToolchain(JavaVersion.target) | ||
jvmToolchain(JavaVersion.asInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<VersionCatalogsExtension>().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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Thumbs.db | ||
.DS_Store | ||
.gradle | ||
build/ | ||
target/ | ||
out/ | ||
.micronaut/ | ||
.idea | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.project | ||
.settings | ||
.classpath | ||
.factorypath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
application: | ||
name: "My Application" | ||
version: "1.0.0" | ||
description: "My Application Description" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
micronautVersion=4.3.2 | ||
kotlinVersion=1.9.22 | ||
org.gradle.jvmargs=-Xmx4096M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = "micronaut-playground" |
20 changes: 20 additions & 0 deletions
20
micronaut-playground/src/main/kotlin/piperkt/services/template/Application.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package piperkt.services.template | ||
|
||
import io.micronaut.runtime.Micronaut.run | ||
|
||
fun main(vararg args: String) { | ||
run(*args) | ||
} | ||
|
||
// LEVEL -> WHATS -> DEPENDENCIES | ||
// -------------------------------- | ||
// DOMAIN -> Language: | ||
// - Entities | ||
// - Value Objects | ||
// - Repositories | ||
// - Factories | ||
// APPLICATION -> Domain | ||
// - Services | ||
// INTERFACES -> | ||
// - Controller (Indepedent of the framework) | ||
// INFRASTRUCTURE |
12 changes: 12 additions & 0 deletions
12
...aut-playground/src/main/kotlin/piperkt/services/template/application/UserEventsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
micronaut-playground/src/main/kotlin/piperkt/services/template/application/UserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package piperkt.services.template.application | ||
|
||
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, | ||
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? = userRepository.findByEmail(email)?.takeIf { it.password == password } | ||
} |
7 changes: 7 additions & 0 deletions
7
...aut-playground/src/main/kotlin/piperkt/services/template/application/api/UserEventsApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package piperkt.services.template.application.api | ||
|
||
import piperkt.services.template.commons.events.UserCreated | ||
|
||
interface UserEventsApi { | ||
fun onUserCreated(userCreated: UserCreated) | ||
} |
15 changes: 15 additions & 0 deletions
15
...ut-playground/src/main/kotlin/piperkt/services/template/application/api/UserServiceApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package piperkt.services.template.application.api | ||
|
||
import piperkt.services.template.domain.User | ||
|
||
interface UserServiceApi { | ||
fun registerUser( | ||
email: String, | ||
password: String, | ||
): User | ||
|
||
fun loginUser( | ||
email: String, | ||
password: String, | ||
): User? | ||
} |
7 changes: 7 additions & 0 deletions
7
micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/Event.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package piperkt.services.template.commons.events | ||
|
||
interface Event | ||
|
||
interface EventPublisher { | ||
fun publish(event: Event) | ||
} |
6 changes: 6 additions & 0 deletions
6
micronaut-playground/src/main/kotlin/piperkt/services/template/commons/events/UserCreated.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package piperkt.services.template.commons.events | ||
|
||
data class UserCreated( | ||
val email: String, | ||
val password: String, | ||
) : Event |
6 changes: 6 additions & 0 deletions
6
micronaut-playground/src/main/kotlin/piperkt/services/template/domain/User.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package piperkt.services.template.domain | ||
|
||
data class User( | ||
val email: String, | ||
val password: String, | ||
) |
7 changes: 7 additions & 0 deletions
7
micronaut-playground/src/main/kotlin/piperkt/services/template/domain/UserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package piperkt.services.template.domain | ||
|
||
interface UserRepository { | ||
fun findByEmail(email: String): User? | ||
|
||
fun save(user: User): User | ||
} |
28 changes: 28 additions & 0 deletions
28
...nd/src/main/kotlin/piperkt/services/template/infrastructure/events/KafkaEventPublisher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package piperkt.services.template.infrastructure.events | ||
|
||
import jakarta.inject.Singleton | ||
import piperkt.services.template.commons.events.Event | ||
import piperkt.services.template.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) } | ||
* | ||
* } | ||
*/ |
11 changes: 11 additions & 0 deletions
11
...rc/main/kotlin/piperkt/services/template/infrastructure/implementation/UserServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
15 changes: 15 additions & 0 deletions
15
.../src/main/kotlin/piperkt/services/template/infrastructure/persistence/model/UserEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package piperkt.services.template.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<UserEntity, String> |
17 changes: 17 additions & 0 deletions
17
...lin/piperkt/services/template/infrastructure/persistence/repository/InMemoryRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package piperkt.services.template.infrastructure.persistence.repository | ||
|
||
import jakarta.inject.Named | ||
import piperkt.services.template.domain.User | ||
import piperkt.services.template.domain.UserRepository | ||
|
||
@Named("inMemory") | ||
class InMemoryRepository : UserRepository { | ||
val users = mutableListOf<User>() | ||
|
||
override fun findByEmail(email: String): User? = users.find { it.email == email } | ||
|
||
override fun save(user: User): User { | ||
users.add(user) | ||
return user | ||
} | ||
} |
Oops, something went wrong.