UserTaskController.cs 3.6 KB

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