UserTaskController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. public async Task<ActionResult<List<UserTaskAllDto>>> GetAll([FromQuery]UserTaskPagingInputDto pagingInput)
  27. {
  28. return Ok(await _userTaskService.GetAll(pagingInput));
  29. }
  30. [HttpGet("Get")]
  31. public async Task<ActionResult<UserTaskDto>> Get(long UserTaskId)
  32. {
  33. return Ok(await _userTaskService.GetById(UserTaskId));
  34. }
  35. [HttpPost("Create")]
  36. [ProducesResponseType(StatusCodes.Status200OK)]
  37. public async Task<ActionResult<UserTaskDto>> Create([FromBody] UserTaskDto input)
  38. {
  39. return await _userTaskService.Create(input);
  40. }
  41. [HttpPost("Update")]
  42. [ProducesResponseType(StatusCodes.Status200OK)]
  43. public async Task<ActionResult<UserTaskDto>> Update([FromBody] UserTaskDto input)
  44. {
  45. return await _userTaskService.Update(input);
  46. }
  47. [HttpDelete("Delete")]
  48. [ProducesResponseType(StatusCodes.Status200OK)]
  49. public async Task Delete([FromQuery] long id)
  50. {
  51. await _userTaskService.Delete(id);
  52. }
  53. #region attachments
  54. [HttpPost("CreateAttachment")]
  55. [ProducesResponseType(StatusCodes.Status200OK)]
  56. [Consumes("multipart/form-data")]
  57. public async Task<ActionResult<AttachmentDto>> CreateAttachment([FromForm] AttachmentDto input)
  58. {
  59. return await _attachmentService.Create(input);
  60. }
  61. [HttpPost("UpdateAttachment")]
  62. [ProducesResponseType(StatusCodes.Status200OK)]
  63. [Consumes("multipart/form-data")]
  64. public async Task UpdateAttachment([FromForm] AttachmentDto input)
  65. {
  66. await _attachmentService.Update(input);
  67. }
  68. [HttpDelete("DeleteAttachment")]
  69. [ProducesResponseType(StatusCodes.Status200OK)]
  70. public async Task DeleteAttachment([FromQuery] long id)
  71. {
  72. await _attachmentService.Delete(id);
  73. }
  74. #endregion
  75. #region History
  76. [HttpPost("CreateTaskHistory")]
  77. [ProducesResponseType(StatusCodes.Status200OK)]
  78. public async Task<ActionResult<UserTaskHistoryDto>> CreateTaskHistory([FromBody] UserTaskHistoryDto input)
  79. {
  80. return await _taskHistoryService.Create(input);
  81. }
  82. [HttpPost("UpdateTaskHistory")]
  83. [ProducesResponseType(StatusCodes.Status200OK)]
  84. public async Task UpdateTaskHistory([FromBody] UserTaskHistoryDto input)
  85. {
  86. await _taskHistoryService.Update(input);
  87. }
  88. [HttpDelete("DeleteTaskHistory")]
  89. [ProducesResponseType(StatusCodes.Status200OK)]
  90. public async Task DeleteTaskHistory([FromQuery]long id)
  91. {
  92. await _taskHistoryService.Delete(id);
  93. }
  94. [HttpPost("ChangeStatus")]
  95. [ProducesResponseType(StatusCodes.Status200OK)]
  96. public async Task ChangeStatus([FromBody] TaskStatusDto input)
  97. {
  98. await _userTaskService.ChangeStatus(input.TaskId, input.StatusId);
  99. }
  100. #endregion
  101. }
  102. }