-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEventsFeed.cs
More file actions
172 lines (168 loc) · 9.38 KB
/
EventsFeed.cs
File metadata and controls
172 lines (168 loc) · 9.38 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using OpenActive.DatasetSite.NET;
using OpenActive.FakeDatabase.NET;
using OpenActive.NET;
using OpenActive.NET.Rpde.Version1;
using OpenActive.Server.NET.OpenBookingHelper;
using ServiceStack.OrmLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BookingSystem
{
public class AcmeEventRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<EventOpportunity, Event>
{
private readonly bool _useSingleSellerMode;
// Example constructor that can set state from EngineConfig
public AcmeEventRpdeGenerator(bool useSingleSellerMode)
{
this._useSingleSellerMode = useSingleSellerMode;
}
protected async override Task<List<RpdeItem<Event>>> GetRpdeItems(long? afterTimestamp, long? afterId)
{
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
{
var q = db.From<ClassTable>()
.Join<SellerTable>()
.OrderBy(x => x.Modified)
.ThenBy(x => x.Id)
.Where(x => x.IsEvent) // Filters for Events only
.Where(x => !afterTimestamp.HasValue && !afterId.HasValue ||
x.Modified > afterTimestamp ||
x.Modified == afterTimestamp && x.Id > afterId &&
x.Modified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
.Take(RpdePageSize);
var query = db
.SelectMulti<ClassTable, SellerTable>(q)
.Select(result => new RpdeItem<Event>
{
Kind = RpdeKind.Event,
Id = result.Item1.Id,
Modified = result.Item1.Modified,
State = result.Item1.Deleted ? RpdeState.Deleted : RpdeState.Updated,
Data = result.Item1.Deleted ? null : new Event
{
// QUESTION: Should the this.IdTemplate and this.BaseUrl be passed in each time rather than set on
// the parent class? Current thinking is it's more extensible on parent class as function signature remains
// constant as power of configuration through underlying class grows (i.e. as new properties are added)
Id = RenderOpportunityId(new EventOpportunity
{
OpportunityType = OpportunityType.Event,
EventId = result.Item1.Id,
}),
Name = result.Item1.Title,
EventAttendanceMode = FeedGeneratorHelper.MapAttendanceMode(result.Item1.AttendanceMode),
Organizer = _useSingleSellerMode ? new Organization
{
Id = RenderSingleSellerId(),
Name = "Test Seller",
TaxMode = TaxMode.TaxGross,
TermsOfService = new List<Terms>
{
new PrivacyPolicy
{
Name = "Privacy Policy",
Url = new Uri("https://example.com/privacy.html"),
RequiresExplicitConsent = false
}
},
IsOpenBookingAllowed = true,
} : result.Item2.IsIndividual ? (ILegalEntity)new Person
{
Id = RenderSellerId(new SellerIdComponents { SellerIdLong = result.Item2.Id }),
Name = result.Item2.Name,
TaxMode = result.Item2.IsTaxGross ? TaxMode.TaxGross : TaxMode.TaxNet,
IsOpenBookingAllowed = true,
} : (ILegalEntity)new Organization
{
Id = RenderSellerId(new SellerIdComponents { SellerIdLong = result.Item2.Id }),
Name = result.Item2.Name,
TaxMode = result.Item2.IsTaxGross ? TaxMode.TaxGross : TaxMode.TaxNet,
TermsOfService = new List<Terms>
{
new PrivacyPolicy
{
Name = "Privacy Policy",
Url = new Uri("https://example.com/privacy.html"),
RequiresExplicitConsent = false
}
},
IsOpenBookingAllowed = true,
},
Offers = new List<Offer> { new Offer
{
Id = RenderOfferId(new EventOpportunity
{
OpportunityType = OpportunityType.Event,
EventId = result.Item1.Id,
OfferId = 0
}),
Price = result.Item1.Price,
PriceCurrency = "GBP",
OpenBookingFlowRequirement = FeedGeneratorHelper.OpenBookingFlowRequirement(
result.Item1.RequiresApproval,
result.Item1.RequiresAttendeeValidation,
result.Item1.RequiresAdditionalDetails,
result.Item1.AllowsProposalAmendment),
ValidFromBeforeStartDate = result.Item1.ValidFromBeforeStartDate,
LatestCancellationBeforeStartDate = result.Item1.LatestCancellationBeforeStartDate,
OpenBookingPrepayment = result.Item1.Prepayment.Convert(),
AllowCustomerCancellationFullRefund = result.Item1.AllowCustomerCancellationFullRefund
}
},
Location = result.Item1.AttendanceMode == AttendanceMode.Online ? null : new Place
{
Name = "Fake Pond",
Address = new PostalAddress
{
StreetAddress = "1 Fake Park",
AddressLocality = "Another town",
AddressRegion = "Oxfordshire",
PostalCode = "OX1 1AA",
AddressCountry = "GB"
},
Geo = new GeoCoordinates
{
Latitude = result.Item1.LocationLat,
Longitude = result.Item1.LocationLng,
}
},
AffiliatedLocation = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : new Place
{
Name = "Fake Pond",
Address = new PostalAddress
{
StreetAddress = "1 Fake Park",
AddressLocality = "Another town",
AddressRegion = "Oxfordshire",
PostalCode = "OX1 1AA",
AddressCountry = "GB"
},
Geo = new GeoCoordinates
{
Latitude = result.Item1.LocationLat,
Longitude = result.Item1.LocationLng,
}
},
Url = new Uri("https://www.example.com/a-session-age"),
Activity = new List<Concept>
{
new Concept
{
Id = new Uri("https://openactive.io/activity-list#c07d63a0-8eb9-4602-8bcc-23be6deb8f83"),
PrefLabel = "Jet Skiing",
InScheme = new Uri("https://openactive.io/activity-list")
}
},
StartDate = (DateTimeOffset)result.Item1.Start,
EndDate = (DateTimeOffset)result.Item1.End,
Duration = result.Item1.End - result.Item1.Start,
RemainingAttendeeCapacity = result.Item1.RemainingSpaces - result.Item1.LeasedSpaces,
MaximumAttendeeCapacity = result.Item1.TotalSpaces
}
});
return query.ToList();
}
}
}
}