UserTaskController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using MTWorkHR.Application.Filters;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Models;
  7. using MTWorkHR.Application.Services.Interfaces;
  8. using MTWorkHR.Identity.Services;
  9. namespace MTWorkHR.API.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. [AppAuthorize]
  14. public class UserTaskController : ControllerBase
  15. {
  16. private readonly IUserTaskService _userTaskService;
  17. private readonly IUserTaskAttachmentService _attachmentService;
  18. private readonly IUserTaskHistoryService _taskHistoryService;
  19. public UserTaskController(IUserTaskService userUserTaskService, IUserTaskAttachmentService attachmentService, IUserTaskHistoryService taskHistoryService)
  20. {
  21. this._userTaskService = userUserTaskService;
  22. _attachmentService = attachmentService;
  23. _taskHistoryService = taskHistoryService;
  24. }
  25. [HttpGet("GetAll")]
  26. [AppAuthorize(Permissions = "UserTask")]
  27. public async Task<ActionResult<List<UserTaskAllDto>>> GetAll([FromQuery]UserTaskPagingInputDto pagingInput)
  28. {
  29. return Ok(await _userTaskService.GetAll(pagingInput));
  30. }
  31. [HttpGet("Get")]
  32. [AppAuthorize(Permissions = "UserTask")]
  33. public async Task<ActionResult<UserTaskDto>> Get(long UserTaskId)
  34. {
  35. return Ok(await _userTaskService.GetById(UserTaskId));
  36. }
  37. [HttpPost("Create")]
  38. [ProducesResponseType(StatusCodes.Status200OK)]
  39. [AppAuthorize(Permissions = "UserTask.Create")]
  40. public async Task<ActionResult<UserTaskDto>> Create([FromBody] UserTaskDto input)
  41. {
  42. return await _userTaskService.Create(input);
  43. }
  44. [HttpPost("Update")]
  45. [ProducesResponseType(StatusCodes.Status200OK)]
  46. [AppAuthorize(Permissions = "UserTask.Update")]
  47. public async Task<ActionResult<UserTaskDto>> Update([FromBody] UserTaskDto input)
  48. {
  49. return await _userTaskService.Update(input);
  50. }
  51. [HttpDelete("Delete")]
  52. [ProducesResponseType(StatusCodes.Status200OK)]
  53. [AppAuthorize(Permissions = "UserTask.Delete")]
  54. public async Task Delete([FromQuery] long id)
  55. {
  56. await _userTaskService.Delete(id);
  57. }
  58. #region attachments
  59. [HttpPost("CreateAttachment")]
  60. [ProducesResponseType(StatusCodes.Status200OK)]
  61. [Consumes("multipart/form-data")]
  62. [AppAuthorize(Permissions = "UserTask.Create")]
  63. public async Task<ActionResult<AttachmentDto>> CreateAttachment([FromForm] AttachmentDto input)
  64. {
  65. return await _attachmentService.Create(input);
  66. }
  67. [HttpPost("UpdateAttachment")]
  68. [ProducesResponseType(StatusCodes.Status200OK)]
  69. [Consumes("multipart/form-data")]
  70. [AppAuthorize(Permissions = "UserTask.Update")]
  71. public async Task UpdateAttachment([FromForm] AttachmentDto input)
  72. {
  73. await _attachmentService.Update(input);
  74. }
  75. [HttpDelete("DeleteAttachment")]
  76. [ProducesResponseType(StatusCodes.Status200OK)]
  77. [AppAuthorize(Permissions = "UserTask.Delete")]
  78. public async Task DeleteAttachment([FromQuery] long id)
  79. {
  80. await _attachmentService.Delete(id);
  81. }
  82. #endregion
  83. #region History
  84. [HttpPost("CreateTaskHistory")]
  85. [ProducesResponseType(StatusCodes.Status200OK)]
  86. [AppAuthorize(Permissions = "UserTask.Create")]
  87. public async Task<ActionResult<UserTaskHistoryDto>> CreateTaskHistory([FromBody] UserTaskHistoryDto input)
  88. {
  89. return await _taskHistoryService.Create(input);
  90. }
  91. [HttpPost("UpdateTaskHistory")]
  92. [ProducesResponseType(StatusCodes.Status200OK)]
  93. [AppAuthorize(Permissions = "UserTask.Update")]
  94. public async Task UpdateTaskHistory([FromBody] UserTaskHistoryDto input)
  95. {
  96. await _taskHistoryService.Update(input);
  97. }
  98. [HttpDelete("DeleteTaskHistory")]
  99. [ProducesResponseType(StatusCodes.Status200OK)]
  100. [AppAuthorize(Permissions = "UserTask.Delete")]
  101. public async Task DeleteTaskHistory([FromQuery]long id)
  102. {
  103. await _taskHistoryService.Delete(id);
  104. }
  105. [HttpPost("ChangeStatus")]
  106. [ProducesResponseType(StatusCodes.Status200OK)]
  107. [AppAuthorize(Permissions = "UserTask.Update")]
  108. public async Task ChangeStatus([FromBody] TaskStatusDto input)
  109. {
  110. await _userTaskService.ChangeStatus(input.TaskId, input.StatusId);
  111. }
  112. #endregion
  113. }
  114. }