-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFacilitiesFeeds.cs
More file actions
196 lines (188 loc) · 10 KB
/
FacilitiesFeeds.cs
File metadata and controls
196 lines (188 loc) · 10 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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 AcmeFacilityUseRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, FacilityUse>
{
//public override string FeedPath { get; protected set; } = "example path override";
private readonly bool _useSingleSellerMode;
// Example constructor that can set state
public AcmeFacilityUseRpdeGenerator(bool useSingleSellerMode)
{
_useSingleSellerMode = useSingleSellerMode;
}
protected async override Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? afterTimestamp, long? afterId)
{
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
{
var q = db.From<FacilityUseTable>()
.Join<SellerTable>()
.OrderBy(x => x.Modified)
.ThenBy(x => x.Id)
.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<FacilityUseTable, SellerTable>(q)
.Select(result => new RpdeItem<FacilityUse>
{
Kind = RpdeKind.FacilityUse,
Id = result.Item1.Id,
Modified = result.Item1.Modified,
State = result.Item1.Deleted ? RpdeState.Deleted : RpdeState.Updated,
Data = result.Item1.Deleted ? null : new FacilityUse
{
// 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 FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUse, // isIndividual??
FacilityUseId = result.Item1.Id
}),
Name = result.Item1.Name,
Provider = _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,
} : 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,
},
Location = 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")
}
}
}
});
return query.ToList();
}
}
}
public class AcmeFacilityUseSlotRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, Slot>
{
//public override string FeedPath { get; protected set; } = "example path override";
protected async override Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTimestamp, long? afterId)
{
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
{
var query = db.Select<SlotTable>()
.OrderBy(x => x.Modified)
.ThenBy(x => x.Id)
.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)
.Select(x => new RpdeItem<Slot>
{
Kind = RpdeKind.FacilityUseSlot,
Id = x.Id,
Modified = x.Modified,
State = x.Deleted ? RpdeState.Deleted : RpdeState.Updated,
Data = x.Deleted ? null : new Slot
{
// 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 FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
}),
FacilityUse = RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUse,
FacilityUseId = x.FacilityUseId
}),
Identifier = x.Id,
StartDate = (DateTimeOffset)x.Start,
EndDate = (DateTimeOffset)x.End,
Duration = x.End - x.Start,
RemainingUses = x.RemainingUses - x.LeasedUses,
MaximumUses = x.MaximumUses,
Offers = new List<Offer> { new Offer
{
Id = RenderOfferId(new FacilityOpportunity
{
OfferId = 0,
OpportunityType = OpportunityType.FacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
}),
Price = x.Price,
PriceCurrency = "GBP",
OpenBookingFlowRequirement = FeedGeneratorHelper.OpenBookingFlowRequirement(
x.RequiresApproval,
x.RequiresAttendeeValidation,
x.RequiresAdditionalDetails,
x.AllowsProposalAmendment),
ValidFromBeforeStartDate = x.ValidFromBeforeStartDate,
LatestCancellationBeforeStartDate = x.LatestCancellationBeforeStartDate,
OpenBookingPrepayment = x.Prepayment.Convert(),
AllowCustomerCancellationFullRefund = x.AllowCustomerCancellationFullRefund,
}
},
}
});
return query.ToList();
}
}
}
}