Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class AppSettings
{
public string JsonLdIdBaseUrl { get; set; }
public bool GenerateIndividualFacilityUses { get; set; }
Comment thread
nickevansuk marked this conversation as resolved.
}
}
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.GenerateIndividualFacilityUses));

var builder = services.AddIdentityServer(options =>
{
Expand Down
33 changes: 26 additions & 7 deletions Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
PrefLabel = "Squash Court",
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 @@ -133,7 +143,7 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
.Take(RpdePageSize)
.Select(x => new RpdeItem<Slot>
{
Kind = RpdeKind.FacilityUseSlot,
Kind = _appSettings.FeatureFlags.GenerateIndividualFacilityUses ? RpdeKind.IndividualFacilityUseSlot : RpdeKind.FacilityUseSlot,
Id = x.Id,
Modified = x.Modified,
State = x.Deleted ? RpdeState.Deleted : RpdeState.Updated,
Expand All @@ -144,11 +154,19 @@ 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.GenerateIndividualFacilityUses ? OpportunityType.IndividualFacilityUseSlot : OpportunityType.FacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
SlotId = x.Id,
IndividualFacilityUseId = _appSettings.FeatureFlags.GenerateIndividualFacilityUses ? x.IndividualFacilityUseId : null,
}),
FacilityUse = RenderOpportunityId(new FacilityOpportunity
FacilityUse = _appSettings.FeatureFlags.GenerateIndividualFacilityUses ?
RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.IndividualFacilityUse,
IndividualFacilityUseId = x.IndividualFacilityUseId,
FacilityUseId = x.FacilityUseId,
})
: RenderOpportunityId(new FacilityOpportunity
{
OpportunityType = OpportunityType.FacilityUse,
FacilityUseId = x.FacilityUseId
Expand All @@ -164,9 +182,10 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
Id = RenderOfferId(new FacilityOpportunity
{
OfferId = 0,
OpportunityType = OpportunityType.FacilityUseSlot,
OpportunityType = _appSettings.FeatureFlags.GenerateIndividualFacilityUses ? OpportunityType.IndividualFacilityUseSlot : OpportunityType.FacilityUseSlot,
FacilityUseId = x.FacilityUseId,
SlotId = x.Id
SlotId = x.Id,
IndividualFacilityUseId = _appSettings.FeatureFlags.GenerateIndividualFacilityUses ? 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 GenerateIndividualFacilityUses { 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.GenerateIndividualFacilityUses ?
Comment thread
nickevansuk marked this conversation as resolved.
new BookablePairIdTemplate<FacilityOpportunity>(
// Opportunity
new OpportunityIdConfiguration
{
OpportunityType = OpportunityType.IndividualFacilityUseSlot,
AssignedFeed = OpportunityType.IndividualFacilityUseSlot,
OpportunityIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/individual-facility-uses/{IndividualFacilityUseId}/facility-use-slots/{SlotId}",
Comment thread
nickevansuk marked this conversation as resolved.
OfferIdTemplate = "{+BaseUrl}/facility-uses/{FacilityUseId}/individual-facility-uses/{IndividualFacilityUseId}/facility-use-slots/{SlotId}#/offers/{OfferId}",
Comment thread
nickevansuk marked this conversation as resolved.
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}"
})
:
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}",
Comment thread
nickevansuk marked this conversation as resolved.
Bookable = true
},
// Parent
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.GenerateIndividualFacilityUses ? OpportunityType.IndividualFacilityUseSlot : OpportunityType.FacilityUseSlot, 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.GenerateIndividualFacilityUses ? OpportunityType.IndividualFacilityUseSlot : OpportunityType.FacilityUseSlot }
}
},
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.GenerateIndividualFacilityUses)));
}

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