Refactor user context handling with CurrentUserService

Introduced ICurrentUserService and its implementation to centralize retrieval of the current user's ID from claims. Updated FriendsController to use this service instead of direct claim access. Registered the service and IHttpContextAccessor in DI. Added integration tests for FriendsController. Moved UsernameValidator to Infrastructure/Validators.
This commit is contained in:
Artemy
2025-06-30 17:37:02 +07:00
parent a659c73357
commit f53ee6644b
7 changed files with 167 additions and 20 deletions
@@ -1,8 +1,10 @@
using Govor.API.Services.AdminsStuff.Interfaces;
using Govor.API.Services.Authentication.Interfaces;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Interfaces;
using Govor.Application.Interfaces.AdminsStuff;
using Govor.Application.Interfaces.Authentication;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Application.Services;
using Govor.Application.Validators;
using Govor.Core.Infrastructure.Extensions;
@@ -38,6 +40,9 @@ public static class ConfigurationProgramExtensions
var env = sp.GetRequiredService<IWebHostEnvironment>();
return new LocalStorageService(env.ContentRootPath);
});
services.AddHttpContextAccessor(); // it's very important for CurrentUserService
services.AddScoped<ICurrentUserService, CurrentUserService>();
}
public static void AddRepositories(this IServiceCollection services)