Skip to content

Commit 0253914

Browse files
authored
Merge pull request #18 from THC-Software/reservation_cancelation_fix
Reservation cancelation fix
2 parents e9a9703 + 5a4d4e8 commit 0253914

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

Application/Handlers/Events/ReservationEventHandler.cs

+18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ public async Task Handle(TechnicalReservationEvent reservationEvent, Cancellatio
5656

5757
private async Task HandleReservationCancelledEvent(TechnicalReservationEvent reservationEvent)
5858
{
59+
var existingPlayOffer = await _playOfferRepository.GetPlayOfferByReservationId(reservationEvent.EntityId);
60+
if (existingPlayOffer != null)
61+
{
62+
var playOfferEvent = new BaseEvent
63+
{
64+
EventId = Guid.NewGuid(),
65+
EntityId = existingPlayOffer.Id,
66+
EventType = EventType.PLAYOFFER_CANCELLED,
67+
EntityType = EntityType.PLAYOFFER,
68+
Timestamp = DateTime.UtcNow,
69+
CorrelationId = reservationEvent.EventId,
70+
EventData = new PlayOfferCancelledEvent()
71+
};
72+
73+
await _writeEventRepository.AppendEvent(playOfferEvent);
74+
await _writeEventRepository.Update();
75+
}
76+
5977
var existingReservation = await _reservationRepository.GetReservationById(reservationEvent.EntityId);
6078
existingReservation!.Apply([reservationEvent]);
6179
}

Domain/Repositories/PlayOfferRepository.cs

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public async Task<List<PlayOffer>> GetPlayOffersByParticipantId(Guid participant
5050

5151
return playOffer;
5252
}
53+
54+
public async Task<PlayOffer?> GetPlayOfferByReservationId(Guid reservationId)
55+
{
56+
return await _context.PlayOffers
57+
.Where(e => e.ReservationId == reservationId)
58+
.FirstOrDefaultAsync();
59+
}
60+
5361

5462
public async Task Update()
5563
{

PlayOfferService.Tests/IntegrationTests/PlayOfferRepositoryTest.cs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public async Task PlayOfferSetup()
1313
Id = Guid.Parse("d79f0bd6-c7ec-44e5-a02f-26e1567b0992"),
1414
ClubId = Guid.Parse("34f13619-14b5-4244-a74b-6a8ba210a0b1"),
1515
CreatorId = Guid.Parse("9b30e631-3ad8-4437-a934-94252d6294c4"),
16+
ReservationId = Guid.Parse("b5fab7b7-63f1-4847-a71c-ae37dbfed029")
1617
},
1718
new()
1819
{
@@ -98,6 +99,7 @@ public async Task GetPlayOffersByCreatorIdTest()
9899
}
99100

100101
[Test]
102+
101103
public async Task GetPlayOffersByOpponentIdTest()
102104
{
103105
//Given

PlayOfferService.Tests/IntegrationTests/ReservationEventHandlerTest.cs

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ public async Task ReservationSetup()
2323
};
2424
TestReservationRepository.CreateReservation(existingReservation);
2525
await TestReservationRepository.Update();
26+
27+
var existingPlayOffer = new PlayOffer
28+
{
29+
Id = Guid.Parse("f515dc74-46ad-4a7b-b4f2-8dfda4b7506f"),
30+
ClubId = Guid.Parse("6031061f-86c6-459b-9260-5b4772bae9d3"),
31+
CreatorId = Guid.Parse("844b93a3-fce8-4d8f-8a8d-38da07a9c11f"),
32+
ProposedStartTime = DateTime.UtcNow,
33+
ProposedEndTime = DateTime.UtcNow.AddHours(3),
34+
AcceptedStartTime = DateTime.UtcNow.AddHours(1),
35+
ReservationId = Guid.Parse("da9ff928-cfb2-4b98-9388-937905556706"),
36+
OpponentId = Guid.Parse("13158d40-c04f-49e8-aa0c-b2473145ceaf"),
37+
IsCancelled = false
38+
};
39+
TestPlayOfferRepository.CreatePlayOffer(existingPlayOffer);
40+
await TestPlayOfferRepository.Update();
2641
}
2742

2843
[Test]
@@ -83,6 +98,10 @@ public async Task ReservationCancelledEvent_ProjectionTest()
8398
await Mediator.Send(reservationCancelledEvent);
8499

85100
// Then
101+
var playOfferEvents = await TestWriteEventRepository.GetEventByEntityId(Guid.Parse("f515dc74-46ad-4a7b-b4f2-8dfda4b7506f"));
102+
Assert.That(playOfferEvents, Has.Count.EqualTo(1));
103+
Assert.That(playOfferEvents[0].EventType, Is.EqualTo(EventType.PLAYOFFER_CANCELLED));
104+
86105
var projectedReservation = await TestReservationRepository.GetReservationById(reservationCancelledEvent.EntityId);
87106

88107
Assert.That(projectedReservation, Is.Not.Null);

0 commit comments

Comments
 (0)