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