using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Robware.Api.Auth.Models; using Robware.Auth; namespace Robware.Api.Auth.Controllers { [ApiController] public class AuthController : ControllerBase { private readonly ILogger _logger; private readonly IAuthenticator _authenticator; public AuthController(ILogger logger, IAuthenticator authenticator) { _logger = logger; _authenticator = authenticator; } [HttpPost(nameof(Authenticate))] public async Task> Authenticate(LoginRequest request) { var (result, user) = await _authenticator.Authenticate(request.Username, request.Password); switch (result) { case AuthenticationResult.Success: return user; case AuthenticationResult.NotFound: return NotFound(); case AuthenticationResult.IncorrectPassword: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } } }