Batch creation

85 views
Skip to first unread message

G

unread,
May 11, 2017, 5:39:08 AM5/11/17
to DDD/CQRS
Hi all,

I have been working on a cqrs + es project and I would like to discuss (get help designing) possible approaches to implementation of a specific area.

 

Some of the requirements are (and this seen by a user - and UI - point of view):

 

- Create a batch of tickets - a user provides a few details common to all tickets and then each ticket gets a unique identifier and those details common to all.

 

- A (non cancelled) ticket (created and belonging to a batch) can be cancelled

 

- A (non used ticket) can be used (marked as used and set to a buyer)

 

- All (non-cancelled) tickets belonging to a batch can be cancelled in one go

 

I am confused about the best way to go about this

 

So, user could send a GenerateTicketsCommand { qty: 300, issueDate: “10/05/2017”, expiryDate:“10/09/2017"}

 

Now, what I am struggling with is about Aggregate Roots. 


Would I have a TicketsBatchAggregateRoot and TicketAggregateRoot? And some how (process manager), initial GenerateTicketsCommand (via a TicketsBatchGeneratedEvent) would end up triggering 300 GenerateTicketCommand {Id:“Guid”, ExpiryDate: “10/09/2017", issueDate:“10/05/2017”, BatchId: “BatchId”}?

 

Any pointers would be greatly appreciated - I understand there are a lot of it depends, and so I am happy to answer any questions, of course.


Thanks in advance.

G

Juan

unread,
May 12, 2017, 10:02:48 PM5/12/17
to DDD/CQRS
Hola...

from my point of view, after reading the requirements, it seems that you can't create tickets alone, a ticket must belong to a batch, so I see one aggregate with 2 entities: Batch and Ticket. The aggregate root is Batch.

The batch entity (the root) has the responsability of creating its own tickets and asign an id to them (for example you can identify the tickets from 1 to N in a given batch). The user doesn't access the tickets directly, but through the batch. The batch is a composition of tickets.

You would have just one repository: BatchRepository.

As batch and ticket entities are inside the same aggregate, you have transactional consistency between them: when you run the CreateBatchOfTickets command, either you create a new batch with all the tickets or you don't create anything. The tickets would be created by the batch entity they belong to.

For example Use Case CancelTicketOfBatch (batchId, ticketId) would be:

Batch batch = batchRepository.fromId (batchId);
bath.cancelTicket ( ticketId );
batchRepository.persist ( batch );
Reply all
Reply to author
Forward
0 new messages