Skip to content

Commit

Permalink
#101 Accessibility - BookingArchived domain event structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
kgniazdowski committed Aug 2, 2021
1 parent f0b8075 commit e66aca4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Accessibility.Domain.SharedKernel;

namespace Accessibility.Domain.Bookings.BookedRecords
{
public class ArchivedBookedRecord
{
public ArchivedBookedRecord(BookedRecordId id, EmployeeId employeeId, OfferId offerId, DateTime date, short durationInMinutes, BookedRecordStatus status)
{
Id = id;
EmployeeId = employeeId;
OfferId = offerId;
Date = date;
DurationInMinutes = durationInMinutes;
Status = status;
}

public BookedRecordId Id { get; set; }
public EmployeeId EmployeeId { get; }
public OfferId OfferId { get; }
public DateTime Date { get; }
public short DurationInMinutes { get; }
public BookedRecordStatus Status { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ internal BookedRecord(EmployeeId employeeId, OfferId offerId, Money price, DateT
CheckRule(new DateMustBeFromTheFutureRule(date));

this.Id = new BookedRecordId(Guid.NewGuid());
this.employeeId = employeeId;
this.offerId = offerId;
this.price = price;
this.EmployeeId = employeeId;
this.OfferId = offerId;
this.Price = price;
this.Date = date;
this.DurationInMinutes = durationInMinutes;
this.Status = BookedRecordStatus.Booked;
}

internal BookedRecordId Id;
private EmployeeId employeeId;
private OfferId offerId;
private Money price;
public BookedRecordId Id { get; }
public EmployeeId EmployeeId { get; }
public OfferId OfferId { get; }
public Money Price { get ;}
public DateTime Date { get; }
public short DurationInMinutes { get; }
public BookedRecordStatus Status { get; private set; }
Expand All @@ -51,6 +51,6 @@ internal void ChangeStatus(BookedRecordStatus newStatus)
}

internal async Task<bool> IsTermAvailable(BookingId bookingId, FacilityId facilityId, IBookingPeriodOfTimeChecker checker) =>
await checker.IsRecordAvailable(bookingId, facilityId, employeeId, Date, Date.AddMinutes(DurationInMinutes));
await checker.IsRecordAvailable(bookingId, facilityId, EmployeeId, Date, Date.AddMinutes(DurationInMinutes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ public void Archive()

if (!IsMadeManually)
{
AddDomainEvent(new BookingCompletedEvent(PublicCustomerId, BookedRecords));
AddDomainEvent(new BookingArchivedEvent(PublicCustomerId, BookedRecords.Select(record => new ArchivedBookedRecord(
record.Id,
record.EmployeeId,
record.OfferId,
record.Date,
record.DurationInMinutes,
record.Status
))));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Accessibility.Domain.Bookings.Events
{
public class BookingCompletedEvent : DomainEventBase
public class BookingArchivedEvent : DomainEventBase
{
public BookingCompletedEvent(PublicCustomerId customerId, IEnumerable<BookedRecord> bookedRecords)
public BookingArchivedEvent(PublicCustomerId customerId, IEnumerable<ArchivedBookedRecord> bookedRecords)
{
CustomerId = customerId;
BookedRecords = bookedRecords;
}

public PublicCustomerId CustomerId { get; }
public IEnumerable<BookedRecord> BookedRecords { get; }
public IEnumerable<ArchivedBookedRecord> BookedRecords { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public void Configure(EntityTypeBuilder<Accessibility.Domain.Bookings.Booking> b
x.HasKey("Id");
x.Property("Id").HasColumnName("booked_record_id");
x.OwnsOne<EmployeeId>("employeeId", e =>
x.OwnsOne<EmployeeId>(b => b.EmployeeId, e =>
e.Property(p => p.Value).HasColumnName("employee_id"));
x.OwnsOne<OfferId>("offerId", e =>
x.OwnsOne<OfferId>(b => b.OfferId, e =>
e.Property(p => p.Value).HasColumnName("offer_id"));
x.OwnsOne<Money>("price", m =>
x.OwnsOne<Money>(b => b.Price, m =>
{
m.Property(p => p.Value).HasColumnName("price");
m.Property(p => p.Currency).HasColumnName("currency");
Expand Down

0 comments on commit e66aca4

Please sign in to comment.