Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
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
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e704394850a36869c66b05af249cb6a48e1048e75b027da547e2b2a282e8f75File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
ContributorAuthor 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(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 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(); | ||
| } | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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