Implementation of getAll and create products endpoints.

This commit is contained in:
Florian THIERRY
2025-04-23 23:13:48 +02:00
parent ed0acfc5dc
commit f98e1227e8
14 changed files with 136 additions and 31 deletions

View File

@@ -1,16 +1,28 @@
package com.example.demo.exposition.product
import com.example.demo.application.product.ProductUseCases
import com.example.demo.domain.core.error.FunctionalError
import com.example.demo.domain.product.inputport.ProductInputPort
import com.example.demo.domain.product.model.Product
import com.example.demo.exposition.product.model.ProductCreationRequest
import com.example.demo.exposition.product.model.ProductDto
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.map
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/api/products")
class ProductController(
private val productUseCases: ProductUseCases
private val productInputPort: ProductInputPort
) {
@GetMapping
fun getAll(): List<ProductDto> = productUseCases.getAll().map(::ProductDto)
suspend fun getAll(): Result<List<ProductDto>, FunctionalError> = productInputPort.getAll()
.map { products -> products.map(::ProductDto) }
@PostMapping
suspend fun create(@RequestBody request: ProductCreationRequest): Result<Product, FunctionalError> =
productInputPort.create(request.name, request.type)
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.exposition.product.core.advice
import org.springframework.web.bind.annotation.RestControllerAdvice
@RestControllerAdvice
class ResultControllerAdvice {
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.exposition.product.model
import com.example.demo.domain.product.model.ProductType
data class ProductCreationRequest(
val name: String,
val type: ProductType
)