55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
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/<UsersController>
|
|
//[HttpGet]
|
|
//public async Task<ActionResult<IEnumerable<UserModel>>> 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/<UsersController>/5
|
|
//[HttpGet("{id}")]
|
|
//public async Task<IActionResult> Get(Guid id)
|
|
//{
|
|
// var user = await _userContext.GetById(id);
|
|
// if (user == null)
|
|
// return NotFound();
|
|
// return Ok(user);
|
|
//}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> 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/<UsersController>
|
|
//[HttpPost]
|
|
//public async Task<IActionResult> 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);
|
|
//}
|
|
}
|