using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using MTWorkHR.Application.Filters; using MTWorkHR.Application.Identity; using MTWorkHR.Application.Models; using MTWorkHR.Application.Services.Interfaces; using MTWorkHR.Identity.Services; namespace MTWorkHR.API.Controllers { [Route("api/[controller]")] [ApiController] [AppAuthorize] public class UserTaskController : ControllerBase { private readonly IUserTaskService _userTaskService; private readonly IUserTaskAttachmentService _attachmentService; private readonly IUserTaskHistoryService _taskHistoryService; public UserTaskController(IUserTaskService userUserTaskService, IUserTaskAttachmentService attachmentService, IUserTaskHistoryService taskHistoryService) { this._userTaskService = userUserTaskService; _attachmentService = attachmentService; _taskHistoryService = taskHistoryService; } [HttpGet("GetAll")] public async Task>> GetAll([FromQuery]UserTaskPagingInputDto pagingInput) { return Ok(await _userTaskService.GetAll(pagingInput)); } [HttpGet("Get")] public async Task> Get(long UserTaskId) { return Ok(await _userTaskService.GetById(UserTaskId)); } [HttpPost("Create")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> Create([FromBody] UserTaskDto input) { return await _userTaskService.Create(input); } [HttpPost("Update")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> Update([FromBody] UserTaskDto input) { return await _userTaskService.Update(input); } [HttpDelete("Delete")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task Delete([FromQuery] long id) { await _userTaskService.Delete(id); } #region attachments [HttpPost("CreateAttachment")] [ProducesResponseType(StatusCodes.Status200OK)] [Consumes("multipart/form-data")] public async Task> CreateAttachment([FromForm] AttachmentDto input) { return await _attachmentService.Create(input); } [HttpPost("UpdateAttachment")] [ProducesResponseType(StatusCodes.Status200OK)] [Consumes("multipart/form-data")] public async Task UpdateAttachment([FromForm] AttachmentDto input) { await _attachmentService.Update(input); } [HttpDelete("DeleteAttachment")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task DeleteAttachment([FromQuery] long id) { await _attachmentService.Delete(id); } #endregion #region History [HttpPost("CreateTaskHistory")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> CreateTaskHistory([FromBody] UserTaskHistoryDto input) { return await _taskHistoryService.Create(input); } [HttpPost("UpdateTaskHistory")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task UpdateTaskHistory([FromBody] UserTaskHistoryDto input) { await _taskHistoryService.Update(input); } [HttpDelete("DeleteTaskHistory")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task DeleteTaskHistory([FromQuery]long id) { await _taskHistoryService.Delete(id); } [HttpPost("ChangeStatus")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task ChangeStatus([FromBody] TaskStatusDto input) { await _userTaskService.ChangeStatus(input.TaskId, input.StatusId); } #endregion } }