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 @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.1" />
<PackageReference Include="Idempwanna" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="9.0.11" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
<PackageReference Include="Scalar.AspNetCore" Version="2.12.7" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public async Task<IActionResult> GetOrdersAsync([FromQuery] OrdersFetchParameter
}

[HttpPost]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize(Roles = Permissions.CreateOrder)]
public async Task<IActionResult> CreateOrderAsync([FromBody] OrderCreationScheme request, CancellationToken cancellation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public sealed class PaymentsController(IDispatcher dispatcher, IEventDispatcher eventDispatcher) : ControllerBase
{
[HttpPost("online")]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize(Roles = Permissions.MakePayment)]
public async Task<IActionResult> CreateOnlineChargeAsync(
[FromBody] CheckoutSessionCreationScheme request, [FromHeader(Name = Headers.Credential)] string credential, CancellationToken cancellation)
Expand All @@ -33,6 +34,7 @@ public async Task<IActionResult> CreateOnlineChargeAsync(
}

[HttpPost("offline")]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize(Roles = Permissions.MakePayment)]
public async Task<IActionResult> CreateOfflinePaymentAsync([FromBody] OfflinePaymentScheme request, CancellationToken cancellation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public async Task<IActionResult> GetCustomersAsync([FromQuery] FetchCustomersPar
}

[HttpPost("customers")]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize]
public async Task<IActionResult> CreateCustomerAsync([FromBody] CustomerCreationScheme request, CancellationToken cancellation)
{
Expand Down Expand Up @@ -138,6 +139,7 @@ public async Task<IActionResult> GetCustomerAddressesAsync(

[HttpPost("customers/{customerId}/addresses")]
[Authorize(Roles = Permissions.EditCustomers)]
[Idempotent]
public async Task<IActionResult> AssignCustomerAddressAsync(
[FromBody] AssignCustomerAddressScheme request, [FromRoute] string customerId, CancellationToken cancellation)
{
Expand Down Expand Up @@ -232,6 +234,7 @@ public async Task<IActionResult> GetOwnersAsync([FromQuery] FetchOwnersParameter
}

[HttpPost("owners")]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize]
public async Task<IActionResult> CreateOwnerAsync([FromBody] OwnerCreationScheme request, CancellationToken cancellation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public async Task<IActionResult> GetEstablishmentsAsync(
}

[HttpPost]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
[Authorize(Roles = Permissions.CreateEstablishment)]
public async Task<IActionResult> CreateEstablishmentAsync(
[FromBody] EstablishmentCreationScheme request, CancellationToken cancellation)
Expand Down Expand Up @@ -111,6 +112,7 @@ public async Task<IActionResult> DeleteEstablishmentAsync(

[HttpPost("{establishmentId}/checkout")]
[Authorize(Roles = Permissions.MakePayment)]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
public async Task<IActionResult> CheckoutAsync(
[FromBody] CreateCheckoutScheme request, [FromRoute] string establishmentId, CancellationToken cancellation)
{
Expand Down Expand Up @@ -162,6 +164,7 @@ public async Task<IActionResult> GetProductsAsync(

[HttpPost("{establishmentId}/products")]
[Authorize(Roles = Permissions.CreateProduct)]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
public async Task<IActionResult> CreateProductAsync(
[FromBody] ProductCreationScheme request, [FromRoute] string establishmentId, CancellationToken cancellation)
{
Expand Down Expand Up @@ -292,6 +295,7 @@ public async Task<IActionResult> GetCredentialsAsync(

[HttpPost("{establishmentId}/integrations/credentials")]
[Authorize(Roles = Permissions.CreateCredential)]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
public async Task<IActionResult> AssignCredentialAsync(
[FromBody] CredentialCreationScheme request, [FromRoute] string establishmentId, CancellationToken cancellation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public sealed class SubscriptionsController(IDispatcher dispatcher) : Controller
{
[HttpPost]
[Authorize(Roles = Permissions.Subscribe)]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
public async Task<IActionResult> CreateCheckoutSessionAsync(
[FromBody] SubscriptionCheckoutSessionCreationScheme request, CancellationToken cancellation)
{
Expand All @@ -29,6 +30,7 @@ public async Task<IActionResult> CreateCheckoutSessionAsync(

[HttpDelete("{id}")]
[Authorize(Roles = Permissions.CancelSubscription)]
[Idempotent] // https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
public async Task<IActionResult> CancelSubscriptionAsync(
[FromQuery] SubscriptionCancelationScheme request, [FromRoute] string id, CancellationToken cancellation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ public static void AddWebComposition(this IServiceCollection services)
options.Realm = settings.Federation.Realm;
options.ClientSecret = settings.Federation.ClientSecret;
});

services.AddIdempotency()
.WithInMemoryCache(options =>
{
options.DefaultCacheExpiration = TimeSpan.FromMinutes(1);
options.DefaultHeaderName = Headers.Idempotency;
options.ThrowOnMissingKey = false;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
global using HttpsRichardy.Federation.Sdk.Extensions;
global using HttpsRichardy.Federation.Sdk.Contracts.Errors;

global using Scalar.AspNetCore;
global using Serilog;
global using Serilog.Context;

global using Scalar.AspNetCore;
global using FluentValidation.AspNetCore;

global using Idempwanna.Core.Configuration;
global using Idempwanna.Core.Attributes;
Loading