-
Notifications
You must be signed in to change notification settings - Fork 7
Add events feed and store #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
civsiv
wants to merge
9
commits into
master
Choose a base branch
from
coverage/events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e704394
Add events feed and store
civsiv 850a368
add facilities feed back in
civsiv 69c66b0
fixes
civsiv 5af249c
uncomment facilties
civsiv b6a48e1
fix Leasing typo
civsiv 048e75b
fix Recalculate typo
civsiv 027da54
fix typo for controlled
civsiv 7e2b2a2
Add PartialSchedules to SessionSeries
civsiv 82e8f75
add framework files
civsiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Examples/BookingSystem.AspNetCore/Extensions/FeedGeneratorHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using OpenActive.FakeDatabase.NET; | ||
using OpenActive.NET; | ||
using OpenActive.Server.NET.OpenBookingHelper; | ||
|
||
namespace BookingSystem | ||
{ | ||
public static class FeedGeneratorHelper | ||
{ | ||
public static List<OpenBookingFlowRequirement> OpenBookingFlowRequirement(bool requiresApproval, bool requiresAttendeeValidation, bool requiresAdditionalDetails, bool allowsProposalAmendment) | ||
{ | ||
List<OpenBookingFlowRequirement> openBookingFlowRequirement = null; | ||
|
||
if (requiresApproval) | ||
{ | ||
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); | ||
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingApproval); | ||
} | ||
|
||
if (requiresAttendeeValidation) | ||
{ | ||
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); | ||
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingAttendeeDetails); | ||
} | ||
|
||
if (requiresAdditionalDetails) | ||
{ | ||
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); | ||
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingIntakeForm); | ||
} | ||
|
||
if (allowsProposalAmendment) | ||
{ | ||
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); | ||
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingNegotiation); | ||
} | ||
return openBookingFlowRequirement; | ||
} | ||
|
||
public static EventAttendanceModeEnumeration MapAttendanceMode(AttendanceMode attendanceMode) | ||
{ | ||
switch (attendanceMode) | ||
{ | ||
case AttendanceMode.Offline: | ||
return EventAttendanceModeEnumeration.OfflineEventAttendanceMode; | ||
case AttendanceMode.Online: | ||
return EventAttendanceModeEnumeration.OnlineEventAttendanceMode; | ||
case AttendanceMode.Mixed: | ||
return EventAttendanceModeEnumeration.MixedEventAttendanceMode; | ||
default: | ||
throw new OpenBookingException(new OpenBookingError(), $"AttendanceMode Type {attendanceMode} not supported"); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Examples/BookingSystem.AspNetCore/Extensions/StoreHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pulling out common functionality between all Stores |
||
using System.Collections.Generic; | ||
using OpenActive.FakeDatabase.NET; | ||
using OpenActive.NET; | ||
using OpenActive.Server.NET.OpenBookingHelper; | ||
|
||
namespace BookingSystem | ||
{ | ||
public static class StoreHelper | ||
{ | ||
public static List<TaxChargeSpecification> GetUnitTaxSpecification(BookingFlowContext flowContext, AppSettings appSettings, decimal? price) | ||
{ | ||
switch (flowContext.TaxPayeeRelationship) | ||
{ | ||
case TaxPayeeRelationship.BusinessToBusiness when appSettings.Payment.TaxCalculationB2B: | ||
case TaxPayeeRelationship.BusinessToConsumer when appSettings.Payment.TaxCalculationB2C: | ||
return new List<TaxChargeSpecification> | ||
{ | ||
new TaxChargeSpecification | ||
{ | ||
Name = "VAT at 20%", | ||
Price = price * (decimal?)0.2, | ||
PriceCurrency = "GBP", | ||
Rate = (decimal?)0.2 | ||
} | ||
}; | ||
case TaxPayeeRelationship.BusinessToBusiness when !appSettings.Payment.TaxCalculationB2B: | ||
case TaxPayeeRelationship.BusinessToConsumer when !appSettings.Payment.TaxCalculationB2C: | ||
return null; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling out common functionality between all FeedGenerators