Skip to content
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

Add events feed and store #144

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add framework files
  • Loading branch information
civsiv committed May 27, 2021
commit 82e8f7555241bcf2a2e338287af212fa4a582125
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@
<Compile Include="Helpers\PropertyValueSpecificationHelper.cs" />
<Compile Include="Extensions\PropertyValueSpecificationHelper.cs" />
<Compile Include="Extensions\BookedOrderItemHelper.cs" />
<Compile Include="IdComponents\EventOpportunity.cs" />
<Compile Include="Stores\EventStore.cs" />
<Compile Include="Extensions\FeedGeneratorHelper.cs" />
<Compile Include="Extensions\StoreHelper.cs" />
<Compile Include="Feeds\EventsFeed.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
Expand Down
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 Examples/BookingSystem.AspNetFramework/Extensions/StoreHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
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();
}
}
}
}
172 changes: 172 additions & 0 deletions Examples/BookingSystem.AspNetFramework/Feeds/EventsFeed.cs
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();
}
}
}
}
36 changes: 5 additions & 31 deletions Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ protected async override Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
}),
Price = x.Price,
PriceCurrency = "GBP",
OpenBookingFlowRequirement = OpenBookingFlowRequirement(x),
OpenBookingFlowRequirement = FeedGeneratorHelper.OpenBookingFlowRequirement(
x.RequiresApproval,
x.RequiresAttendeeValidation,
x.RequiresAdditionalDetails,
x.AllowsProposalAmendment),
ValidFromBeforeStartDate = x.ValidFromBeforeStartDate,
LatestCancellationBeforeStartDate = x.LatestCancellationBeforeStartDate,
OpenBookingPrepayment = x.Prepayment.Convert(),
Expand All @@ -188,35 +192,5 @@ protected async override Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
return query.ToList();
}
}

private static List<OpenBookingFlowRequirement> OpenBookingFlowRequirement(SlotTable slot)
{
List<OpenBookingFlowRequirement> openBookingFlowRequirement = null;

if (slot.RequiresApproval)
{
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>();
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingApproval);
}

if (slot.RequiresAttendeeValidation)
{
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>();
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingAttendeeDetails);
}

if (slot.RequiresAdditionalDetails)
{
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>();
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingIntakeForm);
}

if (slot.AllowsProposalAmendment)
{
openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>();
openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingNegotiation);
}
return openBookingFlowRequirement;
}
}
}
Loading