Reputation: 6665
I'm trying to follow the DDD (Domain-Driven Design) approach in my project. My domain is a barbershop and the use case that I want to implement is - book an appointment.
The problem that I have is how to correctly organize boundaries around my aggregate that should help to handle this use cases (book an appointment).
Let's say I have a barber. Barber has working days. Working day has working hours (e.g. 09:00 - 20:00), breaks, and other booked appointments.
Schematically it would look like this
Barber
- WorkingDay
- 09:00-20:00 <- working hours
- Breaks
- 13:00-14:00
- 18:00-19:00
- Appointments
- 09:00-10:00
- 12:00-13:00
- WorkingDay
...
- WorkingDay
...
Rules to be considered:
I have two ideas of how to implement this:
Create WorkingDay
aggregate which will contain all related breaks and appointments.
Pros:
WorkingDay
aggregateWorkingDayRepository
repositoryCons:
Create WorkingDay
, Break
, Appointment
aggregates and verify rules in domain services
Pros:
Cons
WorkingDayRepository
, BreakRepository
, AppointmentRepository
)What other option can be used? Or what approach to follow in my case?
Upvotes: 0
Views: 325
Reputation: 3185
You could model this by using the concept of a Schedule
. Schedule is your worker's workdays (or calendar) with appointments. It could be a decent aggregate - schedule has to be always valid.
Then you could have AddAppointment
method on the Schedule
which will check the invariants.
If you need to track changes, I'd suggest using Domain Events that could be fired and then logged.
To avoid concurrency problems with bookings, i.e. when 2 users are trying to book the same slot, you can:
bookings
table you will have a unique constraint on <time slot id>, <barber id>
and when the second user is trying to book (insert a booking into the table) they will fail with unique constraint violation. Not sure how your db is structured but hope you get the idea.Upvotes: 1