Seprated the service ID in task list from filter
This commit is contained in:
parent
162d735d16
commit
0d4d4c3754
@ -5,6 +5,7 @@
|
|||||||
public List<Guid>? BuildingIds { get; set; }
|
public List<Guid>? BuildingIds { get; set; }
|
||||||
public List<Guid>? FloorIds { get; set; }
|
public List<Guid>? FloorIds { get; set; }
|
||||||
public List<Guid>? ActivityIds { get; set; }
|
public List<Guid>? ActivityIds { get; set; }
|
||||||
public List<Guid>? ServiceIds { get; set; }
|
public DateTime? dateFrom { get; set; }
|
||||||
|
public DateTime? dateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,37 +430,14 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("list")]
|
[HttpGet("list")]
|
||||||
public async Task<IActionResult> GetTasksList([FromQuery] Guid projectId, [FromQuery] string? filter, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20,
|
public async Task<IActionResult> GetTasksList([FromQuery] Guid projectId, [FromQuery] string? filter, [FromQuery] Guid? serviceId,
|
||||||
[FromQuery] string? dateFrom = null, [FromQuery] string? dateTo = null)
|
[FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20)
|
||||||
{
|
{
|
||||||
_logger.LogInfo("GetTasksList called for projectId: {ProjectId}, dateFrom: {DateFrom}, dateTo: {DateTo}", projectId, dateFrom ?? "", dateTo ?? "");
|
_logger.LogInfo("GetTasksList called for projectId: {ProjectId}", projectId);
|
||||||
|
|
||||||
Guid tenantId = GetTenantId();
|
Guid tenantId = GetTenantId();
|
||||||
DateTime fromDate = new DateTime();
|
|
||||||
DateTime toDate = new DateTime();
|
|
||||||
|
|
||||||
// 1. Parse and validate dateFrom
|
// 1. Get task allocations in the specified date range
|
||||||
if (dateFrom != null && !DateTime.TryParse(dateFrom, out fromDate))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Invalid starting date provided: {DateFrom}", dateFrom);
|
|
||||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Parse and validate dateTo
|
|
||||||
if (dateTo != null && !DateTime.TryParse(dateTo, out toDate))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Invalid ending date provided: {DateTo}", dateTo);
|
|
||||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid ending date.", "Invalid ending date.", 400));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Set default date range if not provided
|
|
||||||
fromDate = dateFrom == null ? DateTime.UtcNow.Date : fromDate;
|
|
||||||
toDate = dateTo == null ? fromDate.AddDays(1) : toDate;
|
|
||||||
|
|
||||||
|
|
||||||
_logger.LogInfo("Fetching task allocations between {FromDate} and {ToDate}", fromDate, toDate);
|
|
||||||
|
|
||||||
// 4. Get task allocations in the specified date range
|
|
||||||
var taskAllocationQuery = _context.TaskAllocations
|
var taskAllocationQuery = _context.TaskAllocations
|
||||||
.Include(t => t.Employee)
|
.Include(t => t.Employee)
|
||||||
.Include(t => t.ReportedBy)
|
.Include(t => t.ReportedBy)
|
||||||
@ -481,8 +458,6 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
t.WorkItem.WorkArea.Floor != null &&
|
t.WorkItem.WorkArea.Floor != null &&
|
||||||
t.WorkItem.WorkArea.Floor.Building != null &&
|
t.WorkItem.WorkArea.Floor.Building != null &&
|
||||||
t.WorkItem.WorkArea.Floor.Building.ProjectId != projectId &&
|
t.WorkItem.WorkArea.Floor.Building.ProjectId != projectId &&
|
||||||
t.AssignmentDate.Date >= fromDate.Date &&
|
|
||||||
t.AssignmentDate.Date <= toDate.Date &&
|
|
||||||
t.TenantId == tenantId);
|
t.TenantId == tenantId);
|
||||||
|
|
||||||
var taskFilter = TryDeserializeFilter(filter);
|
var taskFilter = TryDeserializeFilter(filter);
|
||||||
@ -507,15 +482,21 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
||||||
taskFilter.ActivityIds.Contains(t.WorkItem.ActivityId));
|
taskFilter.ActivityIds.Contains(t.WorkItem.ActivityId));
|
||||||
}
|
}
|
||||||
if (taskFilter.ServiceIds?.Any() ?? false)
|
if (taskFilter.dateFrom.HasValue && taskFilter.dateTo.HasValue)
|
||||||
{
|
{
|
||||||
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
taskAllocationQuery = taskAllocationQuery.Where(t => t.AssignmentDate.Date >= taskFilter.dateFrom.Value.Date &&
|
||||||
t.WorkItem.ActivityMaster != null &&
|
t.AssignmentDate.Date <= taskFilter.dateTo.Value.Date);
|
||||||
t.WorkItem.ActivityMaster.ActivityGroup != null &&
|
|
||||||
taskFilter.ServiceIds.Contains(t.WorkItem.ActivityMaster.ActivityGroup.ServiceId));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (serviceId.HasValue)
|
||||||
|
{
|
||||||
|
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
||||||
|
t.WorkItem.ActivityMaster != null &&
|
||||||
|
t.WorkItem.ActivityMaster.ActivityGroup != null &&
|
||||||
|
t.WorkItem.ActivityMaster.ActivityGroup.ServiceId == serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int totalRecords = await taskAllocationQuery.CountAsync();
|
int totalRecords = await taskAllocationQuery.CountAsync();
|
||||||
int totalPages = (int)Math.Ceiling((double)totalRecords / pageSize);
|
int totalPages = (int)Math.Ceiling((double)totalRecords / pageSize);
|
||||||
@ -528,14 +509,14 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
var taskIds = taskAllocations.Select(t => t.Id).ToList();
|
var taskIds = taskAllocations.Select(t => t.Id).ToList();
|
||||||
|
|
||||||
// 5. Load team members
|
// 2. Load team members
|
||||||
_logger.LogInfo("Loading task members and related employee data.");
|
_logger.LogInfo("Loading task members and related employee data.");
|
||||||
var teamMembers = await _context.TaskMembers
|
var teamMembers = await _context.TaskMembers
|
||||||
.Include(t => t.Employee)
|
.Include(t => t.Employee)
|
||||||
.Where(t => taskIds.Contains(t.TaskAllocationId))
|
.Where(t => taskIds.Contains(t.TaskAllocationId))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// 6. Load task comments
|
// 3. Load task comments
|
||||||
_logger.LogInfo("Fetching comments and attachments.");
|
_logger.LogInfo("Fetching comments and attachments.");
|
||||||
var allComments = await _context.TaskComments
|
var allComments = await _context.TaskComments
|
||||||
.Include(c => c.Employee)
|
.Include(c => c.Employee)
|
||||||
@ -543,14 +524,14 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
var commentIds = allComments.Select(c => c.Id).ToList();
|
var commentIds = allComments.Select(c => c.Id).ToList();
|
||||||
|
|
||||||
// 7. Load all attachments (task and comment)
|
// 4. Load all attachments (task and comment)
|
||||||
var attachments = await _context.TaskAttachments
|
var attachments = await _context.TaskAttachments
|
||||||
.Where(t => taskIds.Contains(t.ReferenceId) || commentIds.Contains(t.ReferenceId))
|
.Where(t => taskIds.Contains(t.ReferenceId) || commentIds.Contains(t.ReferenceId))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var documentIds = attachments.Select(t => t.DocumentId).ToList();
|
var documentIds = attachments.Select(t => t.DocumentId).ToList();
|
||||||
|
|
||||||
// 8. Load actual documents from attachment references
|
// 5. Load actual documents from attachment references
|
||||||
var documents = await _context.Documents
|
var documents = await _context.Documents
|
||||||
.Where(d => documentIds.Contains(d.Id))
|
.Where(d => documentIds.Contains(d.Id))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user