Suppose, I want to design an E-commerce system. I want to create a ProductDTO here which contains general information of a product.
data class ProductDTO(
val productId: String,
@get:PostiveOrZero
val amount: Long
)
data class CreateOrderCommand(
@TargetAggregateIdentifier
val orderId: String,
val product: ProductDTO
)
// my aggregate
class OrderAggregate {
@AggregateIdentifier
lateinit var orderId: String
lateinit var product: ProductDTO
}
// my query model
data class Order(
val orderId: String,
val product: ProductDTO
)
my question is, should I separate ProductDTO between Command and Query. Should command model and query model has its own ProductDTO. For the command model, it may need validation constraint to validate the input but query model may not need it. How should I design it in this case?