Add all layers implementation.
This commit is contained in:
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(
|
||||
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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user