using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using uWine.Core.Domain.Entities; using uWine.Core.Infrastructure.Services; namespace uWine.Api.Controllers { [ApiController] [Route("/[controller]")] public class TestController : Controller { private readonly IConfiguration _configuration; private readonly OwnerService _ownerService; private readonly AuthenticationService _authenticationService; private readonly UserService _userService; public TestController(IConfiguration configuration, OwnerService ownerService, AuthenticationService authenticationService, UserService userService) { _configuration = configuration; _ownerService = ownerService; _authenticationService = authenticationService; _userService = userService; } [HttpGet("cklogin")] [ProducesResponseType(typeof(( int userId, string TUserId, string role, User user)), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public IActionResult test() { try { var TUserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var userId = int.Parse(User.FindFirst("userId").Value); var role = User.FindFirst(ClaimTypes.Role)?.Value; var user = _userService.Process(userId); return Ok(new { userId, TUserId, role, user }); } catch(Exception ex) { return Unauthorized(new { status = 401, exeptiom = ex }); } } } }