-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayOffer.cs
81 lines (72 loc) · 2.76 KB
/
PlayOffer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.ComponentModel.DataAnnotations.Schema;
using PlayOfferService.Domain.Events;
using PlayOfferService.Domain.Events.PlayOffer;
using PlayOfferService.Domain.Events.Reservation;
namespace PlayOfferService.Domain.Models;
public class PlayOffer
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid ClubId { get; set; }
public Guid CreatorId { get; set; }
public Guid? OpponentId { get; set; }
public DateTime ProposedStartTime { get; set; }
public DateTime ProposedEndTime { get; set; }
public DateTime? AcceptedStartTime { get; set; }
public Guid? ReservationId { get; set; }
public bool IsCancelled { get; set; }
public PlayOffer() { }
public void Apply(List<BaseEvent> baseEvents)
{
foreach (var baseEvent in baseEvents)
{
switch (baseEvent.EventType)
{
case EventType.PLAYOFFER_CREATED:
ApplyPlayOfferCreatedEvent((PlayOfferCreatedEvent)baseEvent.EventData);
break;
case EventType.PLAYOFFER_JOINED:
ApplyPlayOfferJoinedEvent((PlayOfferJoinedEvent)baseEvent.EventData);
break;
case EventType.PLAYOFFER_CANCELLED:
ApplyPlayOfferCancelledEvent();
break;
case EventType.PLAYOFFER_RESERVATION_ADDED:
ApplyPlayOfferReservationAddedEvent((PlayOfferReservationAddedEvent)baseEvent.EventData);
break;
case EventType.PLAYOFFER_OPPONENT_REMOVED:
ApplyPlayOfferOpponentRemovedEvent();
break;
default:
throw new ArgumentOutOfRangeException($"{nameof(baseEvent.EventType)} is not supported for the entity Playoffer!");
}
}
}
private void ApplyPlayOfferCreatedEvent(PlayOfferCreatedEvent domainEvent)
{
Id = domainEvent.Id;
ClubId = domainEvent.ClubId;
CreatorId = domainEvent.CreatorId;
ProposedStartTime = domainEvent.ProposedStartTime;
ProposedEndTime = domainEvent.ProposedEndTime;
IsCancelled = false;
}
private void ApplyPlayOfferJoinedEvent(PlayOfferJoinedEvent domainEvent)
{
AcceptedStartTime = domainEvent.AcceptedStartTime;
OpponentId = domainEvent.OpponentId;
}
private void ApplyPlayOfferCancelledEvent()
{
IsCancelled = true;
}
private void ApplyPlayOfferReservationAddedEvent(PlayOfferReservationAddedEvent domainEvent)
{
ReservationId = domainEvent.ReservationId;
}
private void ApplyPlayOfferOpponentRemovedEvent()
{
OpponentId = null;
AcceptedStartTime = null;
}
}