UserTaskController.cs 3.5 KB

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