using Managing.Application.Abstractions.Services; using Managing.Domain.Users; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; namespace Managing.Api.Controllers; [ApiController] [Route("[controller]")] [Produces("application/json")] public abstract class BaseController : ControllerBase { private readonly IUserService _userService; public BaseController(IUserService userService) { _userService = userService; } protected async Task GetUser() { var identity = HttpContext?.User.Identity as ClaimsIdentity; if (identity != null) { var address = identity.Claims.FirstOrDefault(c => c.Type == "address").Value; var user = await _userService.GetUserByAddressAsync(address); if (user != null) return user; throw new Exception("User not found for this token"); } throw new Exception("Not identity assigned to this token"); } }