diff --git a/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/AddCompletedBookingsCommandHandler.cs b/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/AddCompletedBookingsCommandHandler.cs index 3b52965d..a96e8736 100644 --- a/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/AddCompletedBookingsCommandHandler.cs +++ b/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/AddCompletedBookingsCommandHandler.cs @@ -34,6 +34,9 @@ public async Task Handle(AddCompletedBookingsCommand request, Cancellation case BookingStatus.Canceled: member.AddCanceledBooking(offer, null, employee, booking.Date, booking.Duration, booking.BookedRecordId); break; + case BookingStatus.CanceledByFacility: + member.AddCanceledByFacilityBooking(offer, null, employee, booking.Date, booking.Duration, booking.BookedRecordId, booking.Caution); + break; } } diff --git a/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/BookingData.cs b/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/BookingData.cs index 1810ba11..015a2f59 100644 --- a/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/BookingData.cs +++ b/community-service/src/Community.Application/Members/Commands/AddCompletedBookings/BookingData.cs @@ -15,5 +15,6 @@ public class BookingData public short Duration { get; private set; } public Guid BookedRecordId { get; private set; } public BookingStatus Status { get; private set; } + public string Caution { get; set; } } } diff --git a/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommand.cs b/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommand.cs deleted file mode 100644 index 4973a64c..00000000 --- a/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommand.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Community.Domain.Members.ValueObjects; -using Core.Commands; - -namespace Community.Application.Members.Commands.AddFulfilledBooking -{ - public record AddFulfilledBookingCommand( - Guid MemberId, - BookingOffer Offer, - BookingFacility Facility, - BookingEmployee Employee, - DateTime Date, - short Duration, - Guid BookedRecordId - ) : ICommand; -} diff --git a/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommandHandler.cs b/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommandHandler.cs deleted file mode 100644 index 7f498c36..00000000 --- a/community-service/src/Community.Application/Members/Commands/AddFulfilledBooking/AddFulfilledBookingCommandHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using Community.Domain.Members; -using Core.Commands; -using Core.Domain.Repositories; -using MediatR; - -namespace Community.Application.Members.Commands.AddFulfilledBooking -{ - public class AddFulfilledBookingCommandHandler : ICommandHandler - { - private readonly IRepository repository; - - public AddFulfilledBookingCommandHandler(IRepository repository) - { - this.repository = repository; - } - - public async Task Handle(AddFulfilledBookingCommand request, CancellationToken cancellationToken) - { - var member = await repository.FindAsync(request.MemberId, cancellationToken); - - member.AddFulfilledBooking(request.Offer, request.Facility, request.Employee, request.Date, request.Duration, request.BookedRecordId); - - return Unit.Value; - } - } -} diff --git a/community-service/src/Community.Domain/Members/Events/BookingCanceledByFacility.cs b/community-service/src/Community.Domain/Members/Events/BookingCanceledByFacility.cs new file mode 100644 index 00000000..bfe177f4 --- /dev/null +++ b/community-service/src/Community.Domain/Members/Events/BookingCanceledByFacility.cs @@ -0,0 +1,30 @@ +using System; +using Community.Domain.Members.ValueObjects; +using Core.Domain; + +namespace Community.Domain.Members.Events +{ + public class BookingCanceledByFacility : IEvent + { + public BookingCanceledByFacility(Guid memberId, BookingOffer offer, BookingFacility facility, BookingEmployee employee, DateTime date, short duration, Guid bookedRecordId, string caution) + { + MemberId = memberId; + Offer = offer; + Facility = facility; + Employee = employee; + Date = date; + Duration = duration; + BookedRecordId = bookedRecordId; + Caution = caution; + } + + public Guid MemberId { get; } + public BookingOffer Offer { get; } + public BookingFacility Facility { get; } + public BookingEmployee Employee { get; } + public DateTime Date { get; } + public short Duration { get; } + public Guid BookedRecordId { get; } + public string Caution { get; } + } +} diff --git a/community-service/src/Community.Domain/Members/Member.cs b/community-service/src/Community.Domain/Members/Member.cs index 4dcd45e8..29975da6 100644 --- a/community-service/src/Community.Domain/Members/Member.cs +++ b/community-service/src/Community.Domain/Members/Member.cs @@ -88,5 +88,27 @@ public void Apply(BookingCanceled @event) @event.BookedRecordId )); } + + public void AddCanceledByFacilityBooking(BookingOffer offer, BookingFacility facility, BookingEmployee employee, DateTime date, short duration, Guid bookedRecordId, string caution) + { + var @event = new BookingCanceledByFacility(Id, offer, facility, employee, date, duration, bookedRecordId, caution); + + Enqueue(@event); + Apply(@event); + } + + public void Apply(BookingCanceledByFacility @event) + { + ArchivalBookings.Add(new ArchivalBooking( + @event.Offer, + @event.Facility, + @event.Employee, + @event.Date, + @event.Duration, + BookingStatus.CanceledByFacility, + @event.Caution, + @event.BookedRecordId + )); + } } } diff --git a/community-service/src/Community.Domain/Members/ValueObjects/ArchivalBooking.cs b/community-service/src/Community.Domain/Members/ValueObjects/ArchivalBooking.cs index faf79f8d..c5587b75 100644 --- a/community-service/src/Community.Domain/Members/ValueObjects/ArchivalBooking.cs +++ b/community-service/src/Community.Domain/Members/ValueObjects/ArchivalBooking.cs @@ -37,6 +37,7 @@ public enum BookingStatus { Fulfilled, Canceled, + CanceledByFacility, NotRealized } } diff --git a/community-service/src/Community.Infrastructure/Application/Members/Projections/MemberArchivalBookingsProjection.cs b/community-service/src/Community.Infrastructure/Application/Members/Projections/MemberArchivalBookingsProjection.cs index ccf02106..b539fd81 100644 --- a/community-service/src/Community.Infrastructure/Application/Members/Projections/MemberArchivalBookingsProjection.cs +++ b/community-service/src/Community.Infrastructure/Application/Members/Projections/MemberArchivalBookingsProjection.cs @@ -47,5 +47,19 @@ public void Apply(BookingCanceled @event, MemberArchivalBookings view) @event.BookedRecordId )); } + + public void Apply(BookingCanceledByFacility @event, MemberArchivalBookings view) + { + view.ArchivalBookings.Add(new ArchivalBooking( + @event.Offer, + @event.Facility, + @event.Employee, + @event.Date, + @event.Duration, + BookingStatus.CanceledByFacility, + @event.Caution, + @event.BookedRecordId + )); + } } }