You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AuthenticationController.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Diligent.WebAPI.Host.DTOs.Customer;
  2. using Diligent.WebAPI.Host.Mediator.Authentication.Commands;
  3. using Diligent.WebAPI.Host.Mediator.Authentication.Queries;
  4. using MediatR;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace Diligent.WebAPI.Host.Controllers
  7. {
  8. [ApiVersion("1.0")]
  9. [ApiController]
  10. [Route("v{version:apiVersion}/[controller]")]
  11. public class AuthenticationController : ControllerBase
  12. {
  13. // password for every user in database is "Nekasifra123!"
  14. private readonly IMediator _mediator;
  15. public AuthenticationController(IMediator mediator)
  16. {
  17. _mediator = mediator;
  18. }
  19. [HttpPost("login")]
  20. public async Task<ActionResult<CustomerReadDTO>> Login(CustomerLoginDTO customerLoginDTO) =>
  21. await _mediator.Send(new LoginUserQuery(customerLoginDTO));
  22. [HttpPost("addRole")]
  23. public async Task<ActionResult> CreateRole(string nameOfRole)
  24. {
  25. await _mediator.Send(new AddRoleCommand(nameOfRole));
  26. return StatusCode(201);
  27. }
  28. [HttpPost("register")]
  29. public async Task<ActionResult<CustomerReadDTO>> Register(CustomerCreateDTO customerCreateDTO) =>
  30. await _mediator.Send(new RegisterUserCommand(customerCreateDTO));
  31. }
  32. }