From 6b17be81ce6b9e8a0390a708fea627227b79c629 Mon Sep 17 00:00:00 2001 From: Luke Winship Date: Tue, 6 Jun 2023 10:59:41 +0100 Subject: [PATCH] feat: Use env vars to override generated activity / facilityType --- Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs | 7 +++++-- Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs | 7 +++++-- Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs | 7 +++++-- .../BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs | 7 +++++-- .../BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs | 7 +++++-- .../BookingSystem.AspNetFramework/Stores/FacilityStore.cs | 7 +++++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs b/Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs index 709cb8d3..8a0ead09 100644 --- a/Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs +++ b/Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs @@ -24,6 +24,9 @@ public AcmeFacilityUseRpdeGenerator(AppSettings appSettings) protected override async Task>> GetRpdeItems(long? afterTimestamp, long? afterId) { + var facilityTypeId = Environment.GetEnvironmentVariable("FACILITY_TYPE_ID") ?? "https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"; + var facilityTypePrefLabel = Environment.GetEnvironmentVariable("FACILITY_TYPE_PREF_LABEL") ?? "Squash Court"; + using (var db = FakeBookingSystem.FakeDatabase.DatabaseWrapper.Database.Open()) { var q = db.From() @@ -107,8 +110,8 @@ protected override async Task>> GetRpdeItems(long? af FacilityType = new List { new Concept { - Id = new Uri("https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"), - PrefLabel = "Squash Court", + Id = new Uri(facilityTypeId), + PrefLabel = facilityTypePrefLabel, InScheme = new Uri("https://openactive.io/facility-types") } } diff --git a/Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs b/Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs index 778dfaf4..8ea2243f 100644 --- a/Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs +++ b/Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs @@ -74,6 +74,9 @@ public AcmeSessionSeriesRpdeGenerator(AppSettings appSettings) protected override async Task>> GetRpdeItems(long? afterTimestamp, long? afterId) { + var activityId = Environment.GetEnvironmentVariable("ACTIVITY_ID") ?? "https://openactive.io/activity-list#c07d63a0-8eb9-4602-8bcc-23be6deb8f83"; + var activityPrefLabel = Environment.GetEnvironmentVariable("ACTIVITY_PREF_LABEL") ?? "Jet Skiing"; + using (var db = FakeBookingSystem.FakeDatabase.DatabaseWrapper.Database.Open()) { var q = db.From() @@ -199,8 +202,8 @@ protected override async Task>> GetRpdeItems(long? { new Concept { - Id = new Uri("https://openactive.io/activity-list#c07d63a0-8eb9-4602-8bcc-23be6deb8f83"), - PrefLabel = "Jet Skiing", + Id = new Uri(activityId), + PrefLabel = activityPrefLabel, InScheme = new Uri("https://openactive.io/activity-list") } } diff --git a/Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs b/Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs index 59335ab2..2adaf1cb 100644 --- a/Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs +++ b/Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs @@ -286,6 +286,9 @@ protected override async Task TriggerTestAction(OpenBookingSimulateAction simula // Similar to the RPDE logic, this needs to render and return an new hypothetical OrderItem from the database based on the supplied opportunity IDs protected override async Task GetOrderItems(List> orderItemContexts, StoreBookingFlowContext flowContext, OrderStateContext stateContext) { + var facilityTypeId = Environment.GetEnvironmentVariable("FACILITY_TYPE_ID") ?? "https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"; + var facilityTypePrefLabel = Environment.GetEnvironmentVariable("FACILITY_TYPE_PREF_LABEL") ?? "Squash Court"; + // Note the implementation of this method must also check that this OrderItem is from the Seller specified by context.SellerId (this is not required if using a Single Seller) // Additionally this method must check that there are enough spaces in each entry @@ -349,8 +352,8 @@ protected override async Task GetOrderItems(List { new Concept { - Id = new Uri("https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"), - PrefLabel = "Squash Court", + Id = new Uri(facilityTypeId), + PrefLabel = facilityTypePrefLabel, InScheme = new Uri("https://openactive.io/facility-types") } } diff --git a/Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs b/Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs index 709cb8d3..8a0ead09 100644 --- a/Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs +++ b/Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs @@ -24,6 +24,9 @@ public AcmeFacilityUseRpdeGenerator(AppSettings appSettings) protected override async Task>> GetRpdeItems(long? afterTimestamp, long? afterId) { + var facilityTypeId = Environment.GetEnvironmentVariable("FACILITY_TYPE_ID") ?? "https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"; + var facilityTypePrefLabel = Environment.GetEnvironmentVariable("FACILITY_TYPE_PREF_LABEL") ?? "Squash Court"; + using (var db = FakeBookingSystem.FakeDatabase.DatabaseWrapper.Database.Open()) { var q = db.From() @@ -107,8 +110,8 @@ protected override async Task>> GetRpdeItems(long? af FacilityType = new List { new Concept { - Id = new Uri("https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"), - PrefLabel = "Squash Court", + Id = new Uri(facilityTypeId), + PrefLabel = facilityTypePrefLabel, InScheme = new Uri("https://openactive.io/facility-types") } } diff --git a/Examples/BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs b/Examples/BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs index 778dfaf4..8ea2243f 100644 --- a/Examples/BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs +++ b/Examples/BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs @@ -74,6 +74,9 @@ public AcmeSessionSeriesRpdeGenerator(AppSettings appSettings) protected override async Task>> GetRpdeItems(long? afterTimestamp, long? afterId) { + var activityId = Environment.GetEnvironmentVariable("ACTIVITY_ID") ?? "https://openactive.io/activity-list#c07d63a0-8eb9-4602-8bcc-23be6deb8f83"; + var activityPrefLabel = Environment.GetEnvironmentVariable("ACTIVITY_PREF_LABEL") ?? "Jet Skiing"; + using (var db = FakeBookingSystem.FakeDatabase.DatabaseWrapper.Database.Open()) { var q = db.From() @@ -199,8 +202,8 @@ protected override async Task>> GetRpdeItems(long? { new Concept { - Id = new Uri("https://openactive.io/activity-list#c07d63a0-8eb9-4602-8bcc-23be6deb8f83"), - PrefLabel = "Jet Skiing", + Id = new Uri(activityId), + PrefLabel = activityPrefLabel, InScheme = new Uri("https://openactive.io/activity-list") } } diff --git a/Examples/BookingSystem.AspNetFramework/Stores/FacilityStore.cs b/Examples/BookingSystem.AspNetFramework/Stores/FacilityStore.cs index 59335ab2..2adaf1cb 100644 --- a/Examples/BookingSystem.AspNetFramework/Stores/FacilityStore.cs +++ b/Examples/BookingSystem.AspNetFramework/Stores/FacilityStore.cs @@ -286,6 +286,9 @@ protected override async Task TriggerTestAction(OpenBookingSimulateAction simula // Similar to the RPDE logic, this needs to render and return an new hypothetical OrderItem from the database based on the supplied opportunity IDs protected override async Task GetOrderItems(List> orderItemContexts, StoreBookingFlowContext flowContext, OrderStateContext stateContext) { + var facilityTypeId = Environment.GetEnvironmentVariable("FACILITY_TYPE_ID") ?? "https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"; + var facilityTypePrefLabel = Environment.GetEnvironmentVariable("FACILITY_TYPE_PREF_LABEL") ?? "Squash Court"; + // Note the implementation of this method must also check that this OrderItem is from the Seller specified by context.SellerId (this is not required if using a Single Seller) // Additionally this method must check that there are enough spaces in each entry @@ -349,8 +352,8 @@ protected override async Task GetOrderItems(List { new Concept { - Id = new Uri("https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651"), - PrefLabel = "Squash Court", + Id = new Uri(facilityTypeId), + PrefLabel = facilityTypePrefLabel, InScheme = new Uri("https://openactive.io/facility-types") } }