Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ public async Task<IActionResult> GetOrdersFeed([FromServices] IBookingEngine boo
}
}

// GET api/openbooking/order-proposals-rpde
[HttpGet("order-proposals-rpde")]
[Authorize(OpenActiveScopes.OrdersFeed)]
public async Task<IActionResult> GetOrderProposalsFeed([FromServices] IBookingEngine bookingEngine, long? afterTimestamp, string afterId, long? afterChangeNumber)
{
try
{
// Note only a subset of these parameters will be supplied when this endpoints is called
// They are all provided here for the bookingEngine to choose the correct endpoint
// The auth token must also be provided from the associated authentication method
string clientId = User.GetAccessTokenOrdersFeedClaim();
return (await bookingEngine.GetOrderProposalsRPDEPageForFeed(clientId, afterTimestamp, afterId, afterChangeNumber)).GetContentResult();
}
catch (OpenBookingException obe)
{
return obe.ErrorResponseContent.GetContentResult();
}
}

// POST api/openbooking/test-interface/datasets/uat-ci/opportunities
[HttpPost("test-interface/datasets/{testDatasetIdentifier}/opportunities")]
public async Task<IActionResult> TestInterfaceDatasetInsert([FromServices] IBookingEngine bookingEngine, string testDatasetIdentifier, [FromBody] string @event)
Expand Down
75 changes: 65 additions & 10 deletions Examples/BookingSystem.AspNetCore/Feeds/OrdersFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
{
var q = db.From<OrderTable>()
.LeftJoin<OrderTable, OrderItemsTable>((orders, items) => orders.OrderId == items.OrderId)
.OrderBy(x => x.Modified)
.OrderBy(x => x.OrderModified)
.ThenBy(x => x.OrderId)
.Where(x =>
x.VisibleInFeed != FeedVisibility.None && x.ClientId == clientId && (
x.VisibleInOrdersFeed != FeedVisibility.None && x.ClientId == clientId && (
!afterTimestamp.HasValue ||
x.Modified > afterTimestamp ||
x.Modified == afterTimestamp &&
x.OrderModified > afterTimestamp ||
x.OrderModified == afterTimestamp &&
string.Compare(afterId, x.OrderId, StringComparison.InvariantCulture) > 0) &&
x.Modified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
x.OrderModified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
.Take(RPDEPageSize);

var query = db
Expand All @@ -43,9 +43,9 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
{
Kind = RpdeKind.Order,
Id = result.OrderTable.OrderId,
Modified = result.OrderTable.Modified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInFeed == FeedVisibility.Archived ? null :
Modified = result.OrderTable.OrderModified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? null :
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, result.OrderTable.OrderId), result.OrderTable,
result.OrderItemsTable.Select(orderItem => new OrderItem
{
Expand Down Expand Up @@ -87,8 +87,7 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
orderItem.Status == BookingStatus.Confirmed ? OrderItemStatus.OrderItemConfirmed :
orderItem.Status == BookingStatus.CustomerCancelled ? OrderItemStatus.CustomerCancelled :
orderItem.Status == BookingStatus.SellerCancelled ? OrderItemStatus.SellerCancelled :
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended :
orderItem.Status == BookingStatus.Proposed ? OrderItemStatus.OrderItemProposed : (OrderItemStatus?)null,
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended : (OrderItemStatus?)null,
CancellationMessage = orderItem.CancellationMessage,
CustomerNotice = orderItem.CustomerNotice,
}).ToList()
Expand All @@ -99,4 +98,60 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
}
}
}

public class AcmeOrderProposalsFeedRpdeGenerator : OrdersRPDEFeedModifiedTimestampAndID
{
//public override string FeedPath { get; protected set; } = "example path override";

protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long? afterTimestamp, string afterId)
{
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
{
var q = db.From<OrderTable>()
.LeftJoin<OrderTable, OrderItemsTable>((orders, items) => orders.OrderId == items.OrderId)
.OrderBy(x => x.OrderProposalModified)
.ThenBy(x => x.OrderId)
.Where(x =>
x.VisibleInOrderProposalsFeed != FeedVisibility.None && x.ClientId == clientId && (
!afterTimestamp.HasValue ||
x.OrderProposalModified > afterTimestamp ||
x.OrderProposalModified == afterTimestamp &&
string.Compare(afterId, x.OrderId, StringComparison.InvariantCulture) > 0) &&
x.OrderProposalModified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
.Take(RPDEPageSize);

var query = db
.SelectMulti<OrderTable, OrderItemsTable>(q)
.GroupBy(x => new { x.Item1.OrderId })
.Select(result => new
{
OrderTable = result.Select(item => new { item.Item1 }).FirstOrDefault()?.Item1,
OrderItemsTable = result.Select(item => new { item.Item2 }).ToList().Select(orderItem => orderItem.Item2).ToList()
})
.Select(result => new RpdeItem
{
Kind = RpdeKind.Order,
Id = result.OrderTable.OrderId,
Modified = result.OrderTable.OrderProposalModified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? null :
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, result.OrderTable.OrderId), result.OrderTable,
result.OrderItemsTable.Select(orderItem => new OrderItem
{
Id = RenderOrderItemId(OrderType.Order, result.OrderTable.OrderId, orderItem.Id),
AcceptedOffer = new Offer
{
Id = orderItem.OfferJsonLdId,
Price = orderItem.Price,
PriceCurrency = "GBP"
},
OrderedItem = orderItem.OpportunityJsonLdId
}).ToList()
)
});

return query.ToList();
}
}
}
}
3 changes: 2 additions & 1 deletion Examples/BookingSystem.AspNetCore/Settings/EngineConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
"{+BaseUrl}/{OrderType}/{uuid}",
"{+BaseUrl}/{OrderType}/{uuid}#/orderedItems/{OrderItemIdLong}"),

OrderFeedGenerator = new AcmeOrdersFeedRpdeGenerator()
OrdersFeedGenerator = new AcmeOrdersFeedRpdeGenerator(),
OrderProposalsFeedGenerator = new AcmeOrderProposalsFeedRpdeGenerator()
},
new DatasetSiteGeneratorSettings
{
Expand Down
3 changes: 1 addition & 2 deletions Examples/BookingSystem.AspNetCore/Stores/OrderStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ public async override Task<Order> GetOrderStatus(OrderIdComponents orderId, Sell
orderItem.Status == BookingStatus.Confirmed ? OrderItemStatus.OrderItemConfirmed :
orderItem.Status == BookingStatus.CustomerCancelled ? OrderItemStatus.CustomerCancelled :
orderItem.Status == BookingStatus.SellerCancelled ? OrderItemStatus.SellerCancelled :
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended :
orderItem.Status == BookingStatus.Proposed ? OrderItemStatus.OrderItemProposed : (OrderItemStatus?)null
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended : (OrderItemStatus?)null
}).ToList();
var order = RenderOrderFromDatabaseResult(orderIdUri, dbOrder, orderItems);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ public async Task<HttpResponseMessage> GetOrdersFeed(long? afterTimestamp = (lon
}
}

// GET api/openbooking/order-proposals-rpde
[HttpGet]
[Route("order-proposals-rpde")]
public async Task<HttpResponseMessage> GetOrderProposalsFeed(long? afterTimestamp = (long?)null, string afterId = null, long? afterChangeNumber = (long?)null)
{
try
{
// Note only a subset of these parameters will be supplied when this endpoints is called
// They are all provided here for the bookingEngine to choose the correct endpoint
// The auth token must also be provided from the associated authentication method
string clientId = AuthenticationHelper.GetClientIdFromAuth(Request, User);
return (await _bookingEngine.GetOrderProposalsRPDEPageForFeed(clientId, afterTimestamp, afterId, afterChangeNumber)).GetContentResult();
}
catch (OpenBookingException obe)
{
return obe.ErrorResponseContent.GetContentResult();
}
}

// POST api/openbooking/test-interface/datasets/uat-ci/opportunities
[HttpPost]
[Route("test-interface/datasets/{testDatasetIdentifier}/opportunities")]
Expand Down
75 changes: 65 additions & 10 deletions Examples/BookingSystem.AspNetFramework/Feeds/OrdersFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
{
var q = db.From<OrderTable>()
.LeftJoin<OrderTable, OrderItemsTable>((orders, items) => orders.OrderId == items.OrderId)
.OrderBy(x => x.Modified)
.OrderBy(x => x.OrderModified)
.ThenBy(x => x.OrderId)
.Where(x =>
x.VisibleInFeed != FeedVisibility.None && x.ClientId == clientId && (
x.VisibleInOrdersFeed != FeedVisibility.None && x.ClientId == clientId && (
!afterTimestamp.HasValue ||
x.Modified > afterTimestamp ||
x.Modified == afterTimestamp &&
x.OrderModified > afterTimestamp ||
x.OrderModified == afterTimestamp &&
string.Compare(afterId, x.OrderId, StringComparison.InvariantCulture) > 0) &&
x.Modified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
x.OrderModified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
.Take(RPDEPageSize);

var query = db
Expand All @@ -43,9 +43,9 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
{
Kind = RpdeKind.Order,
Id = result.OrderTable.OrderId,
Modified = result.OrderTable.Modified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInFeed == FeedVisibility.Archived ? null :
Modified = result.OrderTable.OrderModified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? null :
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, result.OrderTable.OrderId), result.OrderTable,
result.OrderItemsTable.Select(orderItem => new OrderItem
{
Expand Down Expand Up @@ -87,8 +87,7 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
orderItem.Status == BookingStatus.Confirmed ? OrderItemStatus.OrderItemConfirmed :
orderItem.Status == BookingStatus.CustomerCancelled ? OrderItemStatus.CustomerCancelled :
orderItem.Status == BookingStatus.SellerCancelled ? OrderItemStatus.SellerCancelled :
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended :
orderItem.Status == BookingStatus.Proposed ? OrderItemStatus.OrderItemProposed : (OrderItemStatus?)null,
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended : (OrderItemStatus?)null,
CancellationMessage = orderItem.CancellationMessage,
CustomerNotice = orderItem.CustomerNotice,
}).ToList()
Expand All @@ -99,4 +98,60 @@ protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long
}
}
}

public class AcmeOrderProposalsFeedRpdeGenerator : OrdersRPDEFeedModifiedTimestampAndID
{
//public override string FeedPath { get; protected set; } = "example path override";

protected async override Task<List<RpdeItem>> GetRPDEItems(string clientId, long? afterTimestamp, string afterId)
{
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
{
var q = db.From<OrderTable>()
.LeftJoin<OrderTable, OrderItemsTable>((orders, items) => orders.OrderId == items.OrderId)
.OrderBy(x => x.OrderProposalModified)
.ThenBy(x => x.OrderId)
.Where(x =>
x.VisibleInOrderProposalsFeed != FeedVisibility.None && x.ClientId == clientId && (
!afterTimestamp.HasValue ||
x.OrderProposalModified > afterTimestamp ||
x.OrderProposalModified == afterTimestamp &&
string.Compare(afterId, x.OrderId, StringComparison.InvariantCulture) > 0) &&
x.OrderProposalModified < (DateTimeOffset.UtcNow - new TimeSpan(0, 0, 2)).UtcTicks)
.Take(RPDEPageSize);

var query = db
.SelectMulti<OrderTable, OrderItemsTable>(q)
.GroupBy(x => new { x.Item1.OrderId })
.Select(result => new
{
OrderTable = result.Select(item => new { item.Item1 }).FirstOrDefault()?.Item1,
OrderItemsTable = result.Select(item => new { item.Item2 }).ToList().Select(orderItem => orderItem.Item2).ToList()
})
.Select(result => new RpdeItem
{
Kind = RpdeKind.Order,
Id = result.OrderTable.OrderId,
Modified = result.OrderTable.OrderProposalModified,
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? null :
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, result.OrderTable.OrderId), result.OrderTable,
result.OrderItemsTable.Select(orderItem => new OrderItem
{
Id = RenderOrderItemId(OrderType.Order, result.OrderTable.OrderId, orderItem.Id),
AcceptedOffer = new Offer
{
Id = orderItem.OfferJsonLdId,
Price = orderItem.Price,
PriceCurrency = "GBP"
},
OrderedItem = orderItem.OpportunityJsonLdId
}).ToList()
)
});

return query.ToList();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
"{+BaseUrl}/{OrderType}/{uuid}",
"{+BaseUrl}/{OrderType}/{uuid}#/orderedItems/{OrderItemIdLong}"),

OrderFeedGenerator = new AcmeOrdersFeedRpdeGenerator()
OrdersFeedGenerator = new AcmeOrdersFeedRpdeGenerator(),
OrderProposalsFeedGenerator = new AcmeOrderProposalsFeedRpdeGenerator()
},
new DatasetSiteGeneratorSettings
{
Expand Down
3 changes: 1 addition & 2 deletions Examples/BookingSystem.AspNetFramework/Stores/OrderStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ public async override Task<Order> GetOrderStatus(OrderIdComponents orderId, Sell
orderItem.Status == BookingStatus.Confirmed ? OrderItemStatus.OrderItemConfirmed :
orderItem.Status == BookingStatus.CustomerCancelled ? OrderItemStatus.CustomerCancelled :
orderItem.Status == BookingStatus.SellerCancelled ? OrderItemStatus.SellerCancelled :
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended :
orderItem.Status == BookingStatus.Proposed ? OrderItemStatus.OrderItemProposed : (OrderItemStatus?)null
orderItem.Status == BookingStatus.Attended ? OrderItemStatus.CustomerAttended : (OrderItemStatus?)null
}).ToList();
var order = RenderOrderFromDatabaseResult(orderIdUri, dbOrder, orderItems);

Expand Down
Loading