UserController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. [HttpPost("ResetPassword")]
  67. [ProducesResponseType(StatusCodes.Status200OK)]
  68. public async Task<bool> ResetPassword([FromBody] ResetPasswordDto input)
  69. {
  70. return await _userService.ResetPassword(input);
  71. }
  72. [HttpGet("GetBlobFile")]
  73. [ProducesResponseType(StatusCodes.Status200OK)]
  74. public async Task<ActionResult> GetBlobFile([FromQuery] string filePath)
  75. {
  76. var res = await _userService.Download(filePath);
  77. return File(res.Content, res.ContentType);
  78. }
  79. }
  80. }