Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
Add idempotency protection to B#145
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 20 additions & 8 deletions
28 OpenActive.Server.NET/CustomBookingEngine/CustomBookingEngine.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -335,11 +335,11 @@ public async Task<ResponseContent> GetOrderStatus(string clientId, Uri sellerId, | ||
| } | ||
| else | ||
| { | ||
| return ResponseContent.OpenBookingResponse(OpenActiveSerializer.Serialize(result), HttpStatusCode.OK); | ||
| return ResponseContent.OpenBookingResponse(result.Response, result.HttpStatusCode); | ||
| } | ||
| } | ||
| protected abstract Task<Order> ProcessGetOrderStatus(OrderIdComponents orderId, SellerIdComponents sellerId, ILegalEntity seller); | ||
| protected abstract Task<ProcessFlowResult> ProcessGetOrderStatus(OrderIdComponents orderId, SellerIdComponents sellerId, ILegalEntity seller); | ||
| protected bool IsOpportunityTypeRecognised(string opportunityTypeString) | ||
| @@ -384,8 +384,7 @@ private async Task<ResponseContent> ProcessCheckpoint(string clientId, Uri selle | ||
| var (orderId, sellerIdComponents, seller) = await ConstructIdsFromRequest(clientId, sellerId, uuid, orderType); | ||
| var orderResponse = await ProcessFlowRequest(ValidateFlowRequest<OrderQuote>(orderId, sellerIdComponents, seller, flowStage, orderQuote), orderQuote); | ||
| // Return a 409 status code if any OrderItem level errors exist | ||
| return ResponseContent.OpenBookingResponse(OpenActiveSerializer.Serialize(orderResponse), | ||
| orderResponse.OrderedItem.Exists(x => x.Error?.Count > 0) ? HttpStatusCode.Conflict : HttpStatusCode.OK); | ||
| return ResponseContent.OpenBookingResponse(orderResponse.Response, orderResponse.HttpStatusCode); | ||
nickevansuk marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| public async Task<ResponseContent> ProcessOrderCreationB(string clientId, Uri sellerId, string uuid, string orderJson) | ||
| { | ||
| @@ -400,7 +399,7 @@ public async Task<ResponseContent> ProcessOrderCreationB(string clientId, Uri se | ||
| var response = order.OrderProposalVersion != null ? | ||
| await ProcessOrderCreationFromOrderProposal(orderId, settings.OrderIdTemplate, seller, sellerIdComponents, order) : | ||
| await ProcessFlowRequest(ValidateFlowRequest<Order>(orderId, sellerIdComponents, seller, FlowStage.B, order), order); | ||
| return ResponseContent.OpenBookingResponse(OpenActiveSerializer.Serialize(response), HttpStatusCode.OK); | ||
| return ResponseContent.OpenBookingResponse(response.Response, response.HttpStatusCode); | ||
| } | ||
| public async Task<ResponseContent> ProcessOrderProposalCreationP(string clientId, Uri sellerId, string uuid, string orderJson) | ||
| @@ -413,7 +412,8 @@ public async Task<ResponseContent> ProcessOrderProposalCreationP(string clientId | ||
| throw new OpenBookingException(new UnexpectedOrderTypeError(), "OrderProposal is required for P"); | ||
| } | ||
| var (orderId, sellerIdComponents, seller) = await ConstructIdsFromRequest(clientId, sellerId, uuid, OrderType.OrderProposal); | ||
| return ResponseContent.OpenBookingResponse(OpenActiveSerializer.Serialize(await ProcessFlowRequest(ValidateFlowRequest<OrderProposal>(orderId, sellerIdComponents, seller, FlowStage.P, order), order)), HttpStatusCode.OK); | ||
| var response = await ProcessFlowRequest(ValidateFlowRequest<OrderProposal>(orderId, sellerIdComponents, seller, FlowStage.P, order), order); | ||
| return ResponseContent.OpenBookingResponse(response.Response, response.HttpStatusCode); | ||
| } | ||
| private SellerIdComponents GetSellerIdComponentsFromApiKey(Uri sellerId) | ||
| @@ -760,9 +760,21 @@ async Task<ResponseContent> IBookingEngine.TriggerTestAction(string actionJson) | ||
| }; | ||
| } | ||
| public abstract Task<TOrder> ProcessFlowRequest<TOrder>(BookingFlowContext request, TOrder order) where TOrder : Order, new(); | ||
| public abstract Task<ProcessFlowResult> ProcessFlowRequest<TOrder>(BookingFlowContext request, TOrder order) where TOrder : Order, new(); | ||
| public abstract Task<Order> ProcessOrderCreationFromOrderProposal(OrderIdComponents orderId, OrderIdTemplate orderIdTemplate, ILegalEntity seller, SellerIdComponents sellerId, Order order); | ||
| public abstract Task<ProcessFlowResult> ProcessOrderCreationFromOrderProposal(OrderIdComponents orderId, OrderIdTemplate orderIdTemplate, ILegalEntity seller, SellerIdComponents sellerId, Order order); | ||
| } | ||
| public class ProcessFlowResult | ||
| { | ||
| public string Response { get; } | ||
| public HttpStatusCode HttpStatusCode { get; } | ||
| public ProcessFlowResult(string response, HttpStatusCode httpStatusCode) | ||
| { | ||
| Response = response; | ||
| HttpStatusCode = httpStatusCode; | ||
| } | ||
| } | ||
| } | ||
17 changes: 11 additions & 6 deletions
17 OpenActive.Server.NET/StoreBookingEngine/StoreBookingEngine.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 23 additions & 3 deletions
26 OpenActive.Server.NET/StoreBookingEngine/Stores/OrderStore.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that this abstraction - the idea of moving the throwing of the
OrderAlreadyExistsErrorinto theStoreBookingEngine- is excellent.It is however, a breaking change for users of the library.
Will break this out into a separate issue to capture it for future.