UserController.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using MTWorkHR.Application.Identity;
  5. using MTWorkHR.Application.Models;
  6. using MTWorkHR.Identity.Services;
  7. namespace MTWorkHR.API.Controllers
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class UserController : ControllerBase
  12. {
  13. private readonly IUserService _userService;
  14. public UserController(IUserService userService)
  15. {
  16. this._userService = userService;
  17. }
  18. [HttpGet("GetAll")]
  19. public async Task<ActionResult<List<UserDto>>> GetAll()
  20. {
  21. return Ok( await _userService.GetAll());
  22. }
  23. [HttpGet("Get")]
  24. public async Task<ActionResult<UserDto>> Get(string userId)
  25. {
  26. return Ok(await _userService.GetById(userId));
  27. }
  28. [HttpPost("Create")]
  29. [ProducesResponseType(StatusCodes.Status200OK)]
  30. public async Task<ActionResult<UserDto>> Create([FromBody] UserDto input)
  31. {
  32. return await _userService.Create(input);
  33. }
  34. [HttpPost("Update")]
  35. [ProducesResponseType(StatusCodes.Status200OK)]
  36. public async Task Update([FromBody] UserDto input)
  37. {
  38. await _userService.Update(input);
  39. }
  40. [HttpPost("Delete")]
  41. [ProducesResponseType(StatusCodes.Status200OK)]
  42. public async Task Delete(string id)
  43. {
  44. await _userService.Delete(id);
  45. }
  46. [HttpPost("ResetPassword")]
  47. [ProducesResponseType(StatusCodes.Status200OK)]
  48. public async Task<bool> ResetPassword([FromBody] ResetPasswordDto input)
  49. {
  50. return await _userService.ResetPassword(input);
  51. }
  52. }
  53. }