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

feat: Add IFU CI support #204

Merged
merged 17 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .github/workflows/openactive-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
mode: ['random', 'controlled']
profile: ['all-features', 'single-seller', 'no-payment-reconciliation', 'no-auth', 'no-tax-calculation', 'prepayment-always-required']
profile: ['all-features', 'single-seller', 'no-payment-reconciliation', 'no-auth', 'no-tax-calculation', 'prepayment-always-required', 'facilityuse-has-slots']
steps:
- name: Checkout OpenActive.Server.NET
uses: actions/checkout@v2
Expand Down Expand Up @@ -177,7 +177,6 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- core
- framework
runs-on: ubuntu-latest
steps:
# Checkout the repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
public class AppSettings
{
public string JsonLdIdBaseUrl { get; set; }
public FeatureSettings FeatureFlags { get; set; }
}

/**
* Note feature defaults are set here, and are used for the .NET Framework reference implementation
*/
public class FeatureSettings
{
public bool FacilityUseHasSlots { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Startup(IWebHostEnvironment environment, IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IClientStore, ClientStore>();
services.AddSingleton<FakeBookingSystem>();
services.AddSingleton(x => new FakeBookingSystem(AppSettings.FeatureFlags.FacilityUseHasSlots));

var builder = services.AddIdentityServer(options =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FeatureFlags": {
"FacilityUseHasSlots": true
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Urls": "https://localhost:5003;http://localhost:5002",
"JsonLdIdBaseUrl": "https://localhost:5001"
"JsonLdIdBaseUrl": "https://localhost:5001",
"FeatureFlags": {
"FacilityUseHasSlots": false
}
}
33 changes: 26 additions & 7 deletions Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,17 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
PrefLabel = facilityTypePrefLabel,
InScheme = new Uri("https://openactive.io/facility-types")
}
}
},
IndividualFacilityUse = result.Item1.IndividualFacilityUses != null ? result.Item1.IndividualFacilityUses.Select(ifu => new OpenActive.NET.IndividualFacilityUse
{
Id = RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.IndividualFacilityUse,
IndividualFacilityUseId = ifu.Id,
FacilityUseId = result.Item1.Id
}),
Name = ifu.Name
}).ToList() : null,
}
});

Expand Down Expand Up @@ -136,7 +146,7 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
.Take(RpdePageSize)
.Select(x => new RpdeItem<Slot>
{
Kind = RpdeKind.FacilityUseSlot,
Kind = _appSettings.FeatureFlags.FacilityUseHasSlots ? RpdeKind.FacilityUseSlot : RpdeKind.IndividualFacilityUseSlot,
Id = x.Id,
Modified = x.Modified,
State = x.Deleted ? RpdeState.Deleted : RpdeState.Updated,
Expand All @@ -147,14 +157,22 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
// constant as power of configuration through underlying class grows (i.e. as new properties are added)
Id = RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUseSlot,
OpportunityType = _appSettings.FeatureFlags.FacilityUseHasSlots ? OpportunityType.FacilityUseSlot : OpportunityType.IndividualFacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
SlotId = x.Id,
IndividualFacilityUseId = !_appSettings.FeatureFlags.FacilityUseHasSlots ? x.IndividualFacilityUseId : null,
}),
FacilityUse = RenderOpportunityId(new FacilityOpportunity
FacilityUse = _appSettings.FeatureFlags.FacilityUseHasSlots ?
RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUse,
FacilityUseId = x.FacilityUseId
})
: RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.IndividualFacilityUse,
IndividualFacilityUseId = x.IndividualFacilityUseId,
FacilityUseId = x.FacilityUseId,
}),
Identifier = x.Id,
StartDate = (DateTimeOffset)x.Start,
Expand All @@ -167,9 +185,10 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
Id = RenderOfferId(new FacilityOpportunity
{
OfferId = 0,
OpportunityType = OpportunityType.FacilityUseSlot,
OpportunityType = _appSettings.FeatureFlags.FacilityUseHasSlots ? OpportunityType.FacilityUseSlot : OpportunityType.IndividualFacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
SlotId = x.Id,
IndividualFacilityUseId = !_appSettings.FeatureFlags.FacilityUseHasSlots ? x.IndividualFacilityUseId : null,
}),
Price = x.Price,
PriceCurrency = "GBP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FacilityOpportunity : IBookableIdComponents
public long? FacilityUseId { get; set; }
public long? SlotId { get; set; }
public long? OfferId { get; set; }
public long? IndividualFacilityUseId { get; set; }

public override bool Equals(object obj)
{
Expand All @@ -27,7 +28,8 @@ public override bool Equals(object obj)
return OpportunityType == other.OpportunityType &&
FacilityUseId == other.FacilityUseId &&
SlotId == other.SlotId &&
OfferId == other.OfferId;
OfferId == other.OfferId &&
IndividualFacilityUseId == other.IndividualFacilityUseId;
}

public override int GetHashCode()
Expand All @@ -39,6 +41,7 @@ public override int GetHashCode()
hashCode = (hashCode * 397) ^ FacilityUseId.GetHashCode();
hashCode = (hashCode * 397) ^ SlotId.GetHashCode();
hashCode = (hashCode * 397) ^ OfferId.GetHashCode();
hashCode = (hashCode * 397) ^ IndividualFacilityUseId.GetHashCode();
// ReSharper enable NonReadonlyMemberInGetHashCode
return hashCode;
}
Expand Down
1 change: 1 addition & 0 deletions Examples/BookingSystem.AspNetCore/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class FeatureSettings
public bool PaymentReconciliationDetailValidation { get; set; } = true;
public bool OnlyFreeOpportunities { get; set; } = false;
public bool PrepaymentAlwaysRequired { get; set; } = false;
public bool FacilityUseHasSlots { get; set; } = false;
}

public class PaymentSettings
Expand Down
69 changes: 49 additions & 20 deletions Examples/BookingSystem.AspNetCore/Settings/EngineConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ public static class EngineConfig
{
public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSettings, FakeBookingSystem fakeBookingSystem)
{
var facilityBookablePaidIdTemplate = appSettings.FeatureFlags.FacilityUseHasSlots ?
new BookablePairIdTemplate<FacilityOpportunity>(
// Opportunity
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.FacilityUseSlot,
AssignedFeed = OpportunityType.FacilityUseSlot,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/slots/{SlotId}",
OfferIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/slots/{SlotId}#/offers/{OfferId}",
Bookable = true
},
// Parent
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.FacilityUse,
AssignedFeed = OpportunityType.FacilityUse,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}"
})
:
new BookablePairIdTemplate<FacilityOpportunity>(
// Opportunity
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.IndividualFacilityUseSlot,
AssignedFeed = OpportunityType.IndividualFacilityUseSlot,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/individual-facility-uses/{IndividualFacilityUseId}/slots/{SlotId}",
OfferIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/individual-facility-uses/{IndividualFacilityUseId}/slots/{SlotId}#/offers/{OfferId}",
Bookable = true
},
// Parent
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.IndividualFacilityUse,
AssignedFeed = OpportunityType.FacilityUse,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/individual-facility-uses/{IndividualFacilityUseId}"
},
// Grandparent
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.FacilityUse,
AssignedFeed = OpportunityType.FacilityUse,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}"
})
;

return new StoreBookingEngine(
new BookingEngineSettings
{
Expand All @@ -38,24 +83,8 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
Bookable = false
}),

new BookablePairIdTemplate<FacilityOpportunity> (
// Opportunity
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.FacilityUseSlot,
AssignedFeed = OpportunityType.FacilityUseSlot,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/facility-use-slots/{SlotId}",
OfferIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/facility-use-slots/{SlotId}#/offers/{OfferId}",
Bookable = true
},
// Parent
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.FacilityUse,
AssignedFeed = OpportunityType.FacilityUse,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}"
})/*,

facilityBookablePaidIdTemplate,
/*
new BookablePairIdTemplate<ScheduledSessionOpportunity>(
// Opportunity
new OpportunityIdConfiguration
Expand Down Expand Up @@ -148,7 +177,7 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
OpportunityType.FacilityUse, new AcmeFacilityUseRpdeGenerator(appSettings, fakeBookingSystem)
},
{
OpportunityType.FacilityUseSlot, new AcmeFacilityUseSlotRpdeGenerator(appSettings,fakeBookingSystem)
appSettings.FeatureFlags.FacilityUseHasSlots ? OpportunityType.FacilityUseSlot : OpportunityType.IndividualFacilityUseSlot, new AcmeFacilityUseSlotRpdeGenerator(appSettings,fakeBookingSystem)
}
},

Expand Down Expand Up @@ -253,7 +282,7 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
new SessionStore(appSettings, fakeBookingSystem), new List<OpportunityType> { OpportunityType.ScheduledSession }
},
{
new FacilityStore(appSettings, fakeBookingSystem), new List<OpportunityType> { OpportunityType.FacilityUseSlot }
new FacilityStore(appSettings, fakeBookingSystem), new List<OpportunityType> { appSettings.FeatureFlags.FacilityUseHasSlots ? OpportunityType.FacilityUseSlot : OpportunityType.IndividualFacilityUseSlot }
}
},
OrderStore = new AcmeOrderStore(appSettings, fakeBookingSystem),
Expand Down
2 changes: 1 addition & 1 deletion Examples/BookingSystem.AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void ConfigureServices(IServiceCollection services)
.AddControllers()
.AddMvcOptions(options => options.InputFormatters.Insert(0, new OpenBookingInputFormatter()));

services.AddSingleton<IBookingEngine>(sp => EngineConfig.CreateStoreBookingEngine(AppSettings, new FakeBookingSystem()));
services.AddSingleton<IBookingEngine>(sp => EngineConfig.CreateStoreBookingEngine(AppSettings, new FakeBookingSystem(AppSettings.FeatureFlags.FacilityUseHasSlots)));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
Loading
Loading