Spaces:
Running
Running
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Http; | |
| using Microsoft.AspNetCore.Mvc; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using TaskTrackingSystem.Shared; | |
| using TaskTrackingSystem.Shared.Enums; | |
| using TaskTrackingSystem.Shared.Models.Report; | |
| using TaskTrackingSystem.Shared.Models.Issue; | |
| using TaskTrackingSystem.WebApi.Infrastructure; | |
| namespace TaskTrackingSystem.WebApi.Features.Report | |
| { | |
| [] | |
| [] | |
| [] | |
| public class ReportController : ControllerBase | |
| { | |
| private readonly ReportService _reportService; | |
| public ReportController(ReportService reportService) | |
| { | |
| _reportService = reportService; | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<Result<List<IssueDto>>>> GetIssuesReport() | |
| { | |
| var result = await _reportService.GetIssuesReportAsync(User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<TaskReportDto>>> GetTasksReport( | |
| [] DateTime? startDate, | |
| [] DateTime? endDate, | |
| [] string? status, | |
| [] int? projectId, | |
| [] bool? assignedToMe, | |
| [] bool? assignedToMyTeam, | |
| [] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var full = await _reportService.GetTasksReportAsync( | |
| startDate, endDate, status, projectId, User.GetRoleId(), User.GetUserId(), assignedToMe, assignedToMyTeam); | |
| return StatusCode(full.StatusCode, full); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging.Limit ?? 0); | |
| var result = await _reportService.GetPagedTasksReportAsync( | |
| startDate, endDate, status, projectId, User.GetRoleId(), User.GetUserId(), page, limit, assignedToMe, assignedToMyTeam); | |
| return Ok(result); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<UserProductivityDto>>> GetUserProductivityReport( | |
| [] PaginationQuery? paging = null) | |
| { | |
| var users = await _reportService.GetUserProductivityReportAsync(User.GetRoleId(), User.GetUserId()); | |
| if (!users.IsSuccess || users.Value == null) | |
| { | |
| return StatusCode(users.StatusCode, new PagedResult<UserProductivityDto>()); | |
| } | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| return StatusCode(users.StatusCode, users); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging?.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging?.Limit ?? 0); | |
| var query = users.Value.AsQueryable(); | |
| var paged = await query.ToPagedResultAsync(page, limit); | |
| return Ok(paged); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<IEnumerable<TaskStatusSummaryDto>>>> GetTaskStatusSummary( | |
| [] string? search, | |
| [] AppTaskStatus? statusId, | |
| [] long? projectId) | |
| { | |
| var result = await _reportService.GetTaskStatusSummaryAsync(search, statusId, projectId, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<IActionResult> DownloadTaskStatusSummaryExcel( | |
| [FromQuery] string? search, | |
| [FromQuery] AppTaskStatus? statusId, | |
| [FromQuery] long? projectId) | |
| { | |
| var result = await _reportService.GetTaskStatusSummaryAsync(search, statusId, projectId, User.GetRoleId(), User.GetUserId()); | |
| if (!result.IsSuccess || result.Value == null) | |
| return BadRequest(new { message = result.ErrorMessage }); | |
| var bytes = _reportService.ExportTaskStatusSummaryToExcel(result.Value); | |
| return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | |
| $"TaskStatusSummary_{DateTime.Today:yyyyMMdd}.xlsx"); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<TeamProductivityReportDto>>> GetTeamProductivity( | |
| [] string? search, | |
| [] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var full = await _reportService.GetTeamProductivityAsync(search, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(full.StatusCode, full); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging?.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging?.Limit ?? 0); | |
| var result = await _reportService.GetPagedTeamProductivityAsync(search, User.GetRoleId(), User.GetUserId(), page, limit); | |
| return Ok(result); | |
| } | |
| [] | |
| public async Task<IActionResult> DownloadTeamProductivityExcel([FromQuery] string? search) | |
| { | |
| var result = await _reportService.GetTeamProductivityAsync(search, User.GetRoleId(), User.GetUserId()); | |
| if (!result.IsSuccess || result.Value == null) | |
| return BadRequest(new { message = result.ErrorMessage }); | |
| var bytes = _reportService.ExportTeamProductivityToExcel(result.Value); | |
| return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | |
| $"TeamProductivity_{DateTime.Today:yyyyMMdd}.xlsx"); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<OverdueCriticalTaskDto>>> GetOverdueCritical( | |
| [] string? search, | |
| [] long? projectId, | |
| [] int? priorityId, | |
| [] string? delayType, | |
| [] bool? assignedToMe, | |
| [] bool? assignedToMyTeam, | |
| [] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var full = await _reportService.GetOverdueCriticalTasksAsync( | |
| search, projectId, User.GetRoleId(), User.GetUserId(), priorityId, delayType, assignedToMe, assignedToMyTeam); | |
| return StatusCode(full.StatusCode, full); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging?.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging?.Limit ?? 0); | |
| var result = await _reportService.GetPagedOverdueCriticalTasksAsync( | |
| search, projectId, User.GetRoleId(), User.GetUserId(), page, limit, priorityId, delayType, assignedToMe, assignedToMyTeam); | |
| return Ok(result); | |
| } | |
| [] | |
| public async Task<IActionResult> DownloadOverdueCriticalExcel( | |
| [FromQuery] string? search, | |
| [FromQuery] long? projectId, | |
| [FromQuery] bool? assignedToMe, | |
| [FromQuery] bool? assignedToMyTeam) | |
| { | |
| var result = await _reportService.GetOverdueCriticalTasksAsync( | |
| search, projectId, User.GetRoleId(), User.GetUserId(), assignedToMe: assignedToMe, assignedToMyTeam: assignedToMyTeam); | |
| if (!result.IsSuccess || result.Value == null) | |
| return BadRequest(new { message = result.ErrorMessage }); | |
| var bytes = _reportService.ExportOverdueCriticalToExcel(result.Value); | |
| return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | |
| $"OverdueCriticalTasks_{DateTime.Today:yyyyMMdd}.xlsx"); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<EmployeeProductivityReportDto>>> GetEmployeeProductivity( | |
| [] string? search, | |
| [] DateTime? startDate, | |
| [] DateTime? endDate, | |
| [] string? status, | |
| [] bool? assignedToMe, | |
| [] bool? assignedToMyTeam, | |
| [] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var reportData = await _reportService.GetEmployeeProductivityReportAsync( | |
| search, startDate, endDate, status, User.GetRoleId(), User.GetUserId(), assignedToMe, assignedToMyTeam); | |
| return StatusCode(reportData.StatusCode, reportData); | |
| } | |
| var reportDataPaged = await _reportService.GetPagedEmployeeProductivityReportAsync( | |
| search, startDate, endDate, status, User.GetRoleId(), User.GetUserId(), | |
| paging.Page ?? 1, paging.Limit ?? 10, assignedToMe, assignedToMyTeam); | |
| return Ok(reportDataPaged); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<PagedResult<ProjectProgressReportDto>>> GetProjectProgress( | |
| [] string? search, | |
| [] DateTime? startDate, | |
| [] DateTime? endDate, | |
| [] string? status, | |
| [] bool? assignedToMe, | |
| [] bool? assignedToMyTeam, | |
| [] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var reportData = await _reportService.GetProjectProgressReportAsync( | |
| search, startDate, endDate, status, User.GetRoleId(), User.GetUserId(), assignedToMe, assignedToMyTeam); | |
| return StatusCode(reportData.StatusCode, reportData); | |
| } | |
| var reportDataPaged = await _reportService.GetPagedProjectProgressReportAsync( | |
| search, startDate, endDate, status, User.GetRoleId(), User.GetUserId(), | |
| paging.Page ?? 1, paging.Limit ?? 10, assignedToMe, assignedToMyTeam); | |
| return Ok(reportDataPaged); | |
| } | |
| } | |
| } | |