using back.context; using back.DataModels; using Microsoft.AspNetCore.Mvc; using System.Net; namespace back.controllers; [ApiController, Route("api/[controller]")] public class UsersController(UserContext userContext) : ControllerBase { private readonly UserContext _userContext = userContext; // GET: api/ //[HttpGet] //public async Task>> Get([FromQuery] int page = 1, [FromQuery] int pageSize = 20) //{ // var users = await _userContext.GetPage(page, pageSize); // var totalItems = await _userContext.GetTotalItems(); // Response.Headers.Append("X-Total-Count", totalItems.ToString()); // return Ok(users); //} //// GET api//5 //[HttpGet("{id}")] //public async Task Get(Guid id) //{ // var user = await _userContext.GetById(id); // if (user == null) // return NotFound(); // return Ok(user); //} [HttpPost] public async Task Login( [FromHeader(Name = "X-client-thumbprint")] string clientId, [FromBody] UserModel user ) { if (user == null || string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.Password)) return BadRequest(UserContext.Errors.BadRequest.Description); var existingUser = await _userContext.Login(user.Email, user.Password, clientId); if (existingUser == null) return Unauthorized(UserContext.Errors.Unauthorized.Description); return Ok(existingUser.ToDto()); } //// POST api/ //[HttpPost] //public async Task Post([FromBody] UserModel user) //{ // if (user == null) // return BadRequest("User cannot be null"); // var createdUser = await _userContext.Create(user); // return CreatedAtAction(nameof(Get), new { id = createdUser.Id }, createdUser); //} }