Skip to content

Commit

Permalink
feat(api): Add UserAtomicLock middleware to request pipeline
Browse files Browse the repository at this point in the history
- Added `UserAtomicLock` attribute to the `CreatePost` action in `PostController.cs`
- Registered `UserAtomicLockMiddleware` as a singleton in `Startup.cs`
- Added `app.UseMiddleware<UserAtomicLockMiddleware>()` in the HTTP request pipeline
  • Loading branch information
SakuraIsayeki committed May 10, 2024
1 parent 6cb8259 commit 3210b51
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WowsKarma.Api/Controllers/PostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public IActionResult GetLatestPosts(
/// <response code="422">Attached replay is invalid.</response>
/// <response code="403">Restrictions are in effect for one of the targeted accounts.</response>
/// <response code="404">One of the targeted accounts was not found.</response>
[HttpPost, Authorize(RequireNoPlatformBans)]
[HttpPost, Authorize(RequireNoPlatformBans), UserAtomicLock]
[ProducesResponseType(201), ProducesResponseType(400), ProducesResponseType(422), ProducesResponseType(typeof(string), 403), ProducesResponseType(typeof(string), 404)]
public async Task<IActionResult> CreatePost(
[FromForm] string postDto,
Expand Down
7 changes: 5 additions & 2 deletions WowsKarma.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text;
using Hangfire;
using Hangfire.PostgreSql;
using Hangfire.Tags.PostgreSql;
Expand Down Expand Up @@ -280,6 +280,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddResiliencePolicies();

services.AddSystemd();

services.AddSingleton<UserAtomicLockMiddleware>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -334,7 +336,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthorization();

app.UseMiddleware<RequestLoggingMiddleware>();

app.UseMiddleware<UserAtomicLockMiddleware>();

app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
Expand Down

0 comments on commit 3210b51

Please sign in to comment.