using GameIdeas.Shared.Dto; using GameIdeas.WebAPI.Exceptions; using GameIdeas.WebAPI.Services.Users; using Microsoft.AspNetCore.Mvc; namespace GameIdeas.WebAPI.Controllers; [ApiController] [Route("api/[controller]")] public class UserController( IUserService userService, ILoggerFactory loggerFactory) : Controller { private readonly ILogger logger = loggerFactory.CreateLogger(); [HttpPost("Login")] public async Task> Login([FromBody] UserDto model) { try { return Ok(await userService.Login(model)); } catch (UserInvalidException e) { logger.LogInformation(e, "Missing informations for authentication"); return StatusCode(406, e.Message); } catch (UserUnauthorizedException e) { logger.LogWarning(e, "Authentication invalid with there informations"); return Unauthorized(e.Message); } catch (Exception e) { logger.LogError(e, "Internal error while search games"); return StatusCode(500, e.Message); } } }