38 lines
872 B
C#
38 lines
872 B
C#
|
namespace WebApi.Controllers;
|
|||
|
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using TomatenMusic_Api.Auth.Helpers;
|
|||
|
using TomatenMusic_Api.Auth.Models;
|
|||
|
using TomatenMusic_Api.Auth.Services;
|
|||
|
|
|||
|
[ApiController]
|
|||
|
[Route("api/[controller]")]
|
|||
|
public class UsersController : ControllerBase
|
|||
|
{
|
|||
|
private IUserService _userService;
|
|||
|
|
|||
|
public UsersController(IUserService userService)
|
|||
|
{
|
|||
|
_userService = userService;
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost("authenticate")]
|
|||
|
public IActionResult Authenticate(AuthenticateRequest model)
|
|||
|
{
|
|||
|
var response = _userService.Authenticate(model);
|
|||
|
|
|||
|
if (response == null)
|
|||
|
return BadRequest(new { message = "Username or password is incorrect" });
|
|||
|
|
|||
|
return Ok(response);
|
|||
|
}
|
|||
|
|
|||
|
[Authorize]
|
|||
|
[HttpGet]
|
|||
|
public IActionResult GetAll()
|
|||
|
{
|
|||
|
var users = _userService.GetAll();
|
|||
|
return Ok(users);
|
|||
|
}
|
|||
|
}
|