public async Task <IActionResult> UpdateBookingStatus(Guid hearingId, UpdateBookingStatusRequest updateBookingStatusRequest) { if (hearingId == Guid.Empty) { ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}"); return(BadRequest(ModelState)); } var result = new UpdateBookingStatusRequestValidation().Validate(updateBookingStatusRequest); if (!result.IsValid) { ModelState.AddFluentValidationErrors(result.Errors); return(BadRequest(ModelState)); } try { var bookingStatus = MapUpdateBookingStatus(updateBookingStatusRequest.Status); var command = new UpdateHearingStatusCommand(hearingId, bookingStatus, updateBookingStatusRequest.UpdatedBy, updateBookingStatusRequest.CancelReason); await _commandHandler.Handle(command); switch (bookingStatus) { case BookingStatus.Booked: break; case BookingStatus.Created: var queriedVideoHearing = await GetHearingToPublish(hearingId); var createVideoHearingEvent = new HearingIsReadyForVideoIntegrationEvent(queriedVideoHearing); await _eventPublisher.PublishAsync(createVideoHearingEvent); break; case BookingStatus.Cancelled: await _eventPublisher.PublishAsync(new HearingCancelledIntegrationEvent(hearingId)); break; default: break; } return(NoContent()); } catch (HearingNotFoundException) { return(NotFound()); } catch (DomainRuleException exception) { exception.ValidationFailures.ForEach(x => ModelState.AddModelError(x.Name, x.Message)); return(Conflict(ModelState)); } }
public async Task should_be_able_to_update_status() { var seededHearing = await Hooks.SeedVideoHearing(); TestContext.WriteLine($"New seeded video hearing id: {seededHearing.Id}"); var newBookingStatus = BookingStatus.Created; var command = new UpdateHearingStatusCommand(seededHearing.Id, newBookingStatus, "test", null); await _commandHandler.Handle(command); await using var db = new BookingsDbContext(BookingsDbContextOptions); var hearing = await db.VideoHearings.FindAsync(seededHearing.Id); hearing.Status.Should().Be(newBookingStatus); }
private async Task UpdateHearingStatusAsync(Guid hearingId, BookingStatus bookingStatus, string updatedBy, string cancelReason) { var command = new UpdateHearingStatusCommand(hearingId, bookingStatus, updatedBy, cancelReason); await _commandHandler.Handle(command); }