Compare commits
3 Commits
b5b896cb47
...
db7bcfa60a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db7bcfa60a | ||
|
|
8fa13103f3 | ||
|
|
2ca85aab88 |
@@ -1,7 +1,13 @@
|
|||||||
|
object Versions {
|
||||||
|
const val springBoot = "3.4.3"
|
||||||
|
const val springDependencyManagement = "1.1.7"
|
||||||
|
const val kotlinJvm = "1.9.25"
|
||||||
|
const val kotlinPluginSpring = "1.9.25"
|
||||||
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.9.25"
|
kotlin("jvm") version "1.9.25"
|
||||||
kotlin("plugin.spring") version "1.9.25"
|
kotlin("plugin.spring") version "1.9.25"
|
||||||
id("org.springframework.boot") version "3.4.4"
|
|
||||||
id("io.spring.dependency-management") version "1.1.7"
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,13 +24,24 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
subprojects {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
apply(plugin = "java")
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
apply(plugin = "org.jetbrains.kotlin.jvm")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
repositories {
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
mavenCentral()
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(platform("org.springframework.boot:spring-boot-dependencies:${Versions.springBoot}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyManagement {
|
||||||
|
imports {
|
||||||
|
mavenBom("org.springframework.boot:spring-boot-dependencies:${Versions.springBoot}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
|||||||
11
demo-application/build.gradle.kts
Normal file
11
demo-application/build.gradle.kts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
|
id("java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation(project(":demo-domain"))
|
||||||
|
implementation("org.springframework:spring-context")
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.demo.application.product
|
||||||
|
|
||||||
|
import com.example.demo.domain.product.model.Product
|
||||||
|
import com.example.demo.domain.product.port.ProductPort
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class ProductUseCases(
|
||||||
|
private val productPort: ProductPort
|
||||||
|
) {
|
||||||
|
fun getAll(): List<Product> = productPort.getAll()
|
||||||
|
}
|
||||||
8
demo-domain/build.gradle.kts
Normal file
8
demo-domain/build.gradle.kts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.example.demo.domain.product.model
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
data class Product(
|
||||||
|
val id: UUID,
|
||||||
|
val name: String,
|
||||||
|
val type: ProductType
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.example.demo.domain.product.model
|
||||||
|
|
||||||
|
enum class ProductType {
|
||||||
|
SOLID,
|
||||||
|
LIQUID,
|
||||||
|
GAS
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.example.demo.domain.product.port
|
||||||
|
|
||||||
|
import com.example.demo.domain.product.model.Product
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
interface ProductPort {
|
||||||
|
fun getById(id: UUID): Product?
|
||||||
|
|
||||||
|
fun getAll(): List<Product>
|
||||||
|
|
||||||
|
fun save(product: Product)
|
||||||
|
|
||||||
|
fun deleteById(id: UUID)
|
||||||
|
}
|
||||||
13
demo-exposition/build.gradle.kts
Normal file
13
demo-exposition/build.gradle.kts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
|
id("java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation(project(":demo-application"))
|
||||||
|
implementation(project(":demo-domain"))
|
||||||
|
implementation("org.springframework:spring-context")
|
||||||
|
implementation("org.springframework:spring-web")
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.exposition.product
|
||||||
|
|
||||||
|
import com.example.demo.application.product.ProductUseCases
|
||||||
|
import com.example.demo.exposition.product.model.ProductDto
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/products")
|
||||||
|
class ProductController(
|
||||||
|
private val productUseCases: ProductUseCases
|
||||||
|
) {
|
||||||
|
@GetMapping
|
||||||
|
fun getAll(): List<ProductDto> = productUseCases.getAll().map(::ProductDto)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.example.demo.exposition.product.model
|
||||||
|
|
||||||
|
import com.example.demo.domain.product.model.Product
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class ProductDto(
|
||||||
|
val id: UUID,
|
||||||
|
val name: String,
|
||||||
|
val type: ProductTypeDto
|
||||||
|
) {
|
||||||
|
constructor(product: Product): this(
|
||||||
|
id = product.id,
|
||||||
|
name = product.name,
|
||||||
|
type = ProductTypeDto.fromDomain(product.type)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toDomain() = Product(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
type = type.toDomain()
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.example.demo.exposition.product.model
|
||||||
|
|
||||||
|
import com.example.demo.domain.product.model.ProductType
|
||||||
|
|
||||||
|
enum class ProductTypeDto {
|
||||||
|
SOLID,
|
||||||
|
LIQUID,
|
||||||
|
GAS;
|
||||||
|
|
||||||
|
fun toDomain(): ProductType {
|
||||||
|
return when (this) {
|
||||||
|
SOLID -> ProductType.SOLID
|
||||||
|
LIQUID -> ProductType.LIQUID
|
||||||
|
GAS -> ProductType.GAS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromDomain(productType: ProductType) = when (productType) {
|
||||||
|
ProductType.SOLID -> SOLID
|
||||||
|
ProductType.LIQUID -> LIQUID
|
||||||
|
ProductType.GAS -> GAS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
demo-infrastructure/build.gradle.kts
Normal file
12
demo-infrastructure/build.gradle.kts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
|
id("java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation(project(":demo-application"))
|
||||||
|
implementation(project(":demo-domain"))
|
||||||
|
implementation("org.springframework:spring-context")
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.example.demo.infrastructure.product
|
||||||
|
|
||||||
|
import com.example.demo.domain.product.model.Product
|
||||||
|
import com.example.demo.domain.product.model.ProductType.LIQUID
|
||||||
|
import com.example.demo.domain.product.model.ProductType.SOLID
|
||||||
|
import com.example.demo.domain.product.port.ProductPort
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class ProductInMemoryAdapter : ProductPort {
|
||||||
|
private val products = mutableListOf<Product>(
|
||||||
|
Product(
|
||||||
|
id = UUID.randomUUID(),
|
||||||
|
name = "Banana x5",
|
||||||
|
type = SOLID
|
||||||
|
),
|
||||||
|
Product(
|
||||||
|
id = UUID.randomUUID(),
|
||||||
|
name = "Banana juice 1L",
|
||||||
|
type = LIQUID
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getById(id: UUID): Product? = products.find { product -> product.id == id }
|
||||||
|
|
||||||
|
override fun getAll(): List<Product> = products
|
||||||
|
|
||||||
|
override fun save(product: Product) {
|
||||||
|
if (getById(product.id) == null) {
|
||||||
|
products.add(product)
|
||||||
|
} else {
|
||||||
|
deleteById(product.id)
|
||||||
|
save(product)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deleteById(id: UUID) {
|
||||||
|
products.removeIf { product -> product.id == id }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm")
|
kotlin("jvm")
|
||||||
id("org.springframework.boot")
|
id("org.springframework.boot") version "3.4.3"
|
||||||
id("io.spring.dependency-management")
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
id("java")
|
id("java")
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib"))
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation(project(":demo-domain"))
|
||||||
|
implementation(project(":demo-application"))
|
||||||
|
implementation(project(":demo-infrastructure"))
|
||||||
|
implementation(project(":demo-exposition"))
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
}
|
}
|
||||||
|
|
||||||
springBoot {
|
springBoot {
|
||||||
mainClass = "com.example.demo.launcher.ApplicationLauncher"
|
mainClass = "com.example.demo.launcher.ApplicationLauncherKt"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
package com.example.demo.launcher
|
package com.example.demo.launcher
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication(
|
||||||
class DemoApplication
|
scanBasePackages = [
|
||||||
|
"com.example.demo.domain",
|
||||||
|
"com.example.demo.application",
|
||||||
|
"com.example.demo.infrastructure",
|
||||||
|
"com.example.demo.exposition"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
open class DemoApplication
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
runApplication<DemoApplication>(*args)
|
runApplication<DemoApplication>(*args)
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
rootProject.name = "demo"
|
rootProject.name = "demo"
|
||||||
|
include(":demo-domain")
|
||||||
|
include(":demo-application")
|
||||||
|
include(":demo-infrastructure")
|
||||||
|
include(":demo-exposition")
|
||||||
include(":demo-launcher")
|
include(":demo-launcher")
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.example.demo
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
|
||||||
import org.springframework.boot.runApplication
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
class DemoApplication
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
runApplication<DemoApplication>(*args)
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
spring.application.name=demo
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class DemoApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user