UserController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Countries.NET.Database;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using MTWorkHR.Application.Filters;
  6. using MTWorkHR.Application.Identity;
  7. using MTWorkHR.Application.Models;
  8. using MTWorkHR.Identity.Services;
  9. namespace MTWorkHR.API.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. [AppAuthorize]
  14. public class UserController : ControllerBase
  15. {
  16. private readonly IUserService _userService;
  17. public UserController(IUserService userService)
  18. {
  19. this._userService = userService;
  20. }
  21. [HttpPost("GetAll")]
  22. public async Task<ActionResult<List<UserAllDto>>> GetAll([FromBody] UserPagingInputDto pagingInput)
  23. {
  24. return Ok( await _userService.GetAll(pagingInput));
  25. }
  26. [HttpGet("GetAllCompanyEmployees")]
  27. public async Task<ActionResult<List<UserDto>>> GetAllCompanyEmployees()
  28. {
  29. return Ok(await _userService.GetAllCompanyEmployees());
  30. }
  31. [HttpGet("Get")]
  32. public async Task<ActionResult<UserDto>> Get()
  33. {
  34. return Ok(await _userService.GetById());
  35. }
  36. [HttpGet("GetById")]
  37. public async Task<ActionResult<UserDto>> GetById(string userId)
  38. {
  39. return Ok(await _userService.GetById(userId));
  40. }
  41. [HttpGet("GetByEmail")]
  42. public async Task<ActionResult<UserDto>> GetByEmail(string userId)
  43. {
  44. return Ok(await _userService.GetByEmail(userId));
  45. }
  46. [HttpPost("Create")]
  47. [ProducesResponseType(StatusCodes.Status200OK)]
  48. [Consumes("multipart/form-data")]
  49. public async Task<ActionResult<UserDto>> Create([FromForm] UserDto input)
  50. {
  51. return await _userService.Create(input);
  52. }
  53. [HttpPost("Update")]
  54. [Consumes("multipart/form-data")]
  55. [ProducesResponseType(StatusCodes.Status200OK)]
  56. public async Task<ActionResult<UserDto>> Update([FromForm] UserUpdateDto input)
  57. {
  58. return Ok(await _userService.Update(input));
  59. }
  60. [HttpDelete("Delete")]
  61. [ProducesResponseType(StatusCodes.Status200OK)]
  62. public async Task Delete([FromQuery] string id)
  63. {
  64. await _userService.Delete(id);
  65. }
  66. [HttpDelete("Suspend")]
  67. [ProducesResponseType(StatusCodes.Status200OK)]
  68. public async Task Suspend([FromQuery] string id)
  69. {
  70. await _userService.Suspend(id);
  71. }
  72. [HttpPost("ResetPassword")]
  73. [ProducesResponseType(StatusCodes.Status200OK)]
  74. public async Task<bool> ResetPassword([FromBody] ResetPasswordDto input)
  75. {
  76. return await _userService.ResetPassword(input);
  77. }
  78. [HttpGet("GetBlobFile")]
  79. [ProducesResponseType(StatusCodes.Status200OK)]
  80. public async Task<ActionResult> GetBlobFile([FromQuery] string filePath)
  81. {
  82. var res = await _userService.Download(filePath);
  83. return File(res.Content, res.ContentType);
  84. }
  85. }
  86. }