I have an aggregate root called SizeRangeAggregate which holds the range of size of clothing piece dimension and price for that range.
I created an post rest API which create new SizeRangeAggregate. It follows the CQRS/ES which means
- it creates
CreateSizeCommand - publish it to
CreateSizeCommandcommand handler - generate
SizeRangeCreatedevent - persist the event to eventstore
- publish the event to
SizeRangeCreatedevent handler where the read model is generated calledSizeRangeReadModel
I want to add a simple domain logic where an API will not create a new SizeRangeAggregate if the range is already defined in other SizeRangeAggregate.
Currently I am using the read model range filter (something like getByRange) in API controller to get the SizeRangeReadModel if exist, before creating CreateSizeCommand . But I think I am doing it wrong as this is a domain logic and thats why should not be in controller.
Could you suggest me best option/ way to implement this.