mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using SeaHaven.Services.DTOs;
|
|
using SeaHaven.Services.Interfaces;
|
|
|
|
namespace SeaHaven.Services.Implementation
|
|
{
|
|
public class WorkOrderBoardMapper : IWorkOrderBoardMapper
|
|
{
|
|
private readonly IWorkOrderStatusMapper _statusMapper;
|
|
|
|
public WorkOrderBoardMapper(IWorkOrderStatusMapper statusMapper)
|
|
{
|
|
_statusMapper = statusMapper;
|
|
}
|
|
|
|
public WorkOrderBoardItemDto MapToBoardItem(WorkOrderBoardRowDto row, DateOnly? today = null)
|
|
{
|
|
var effectiveToday = today ?? DateOnly.FromDateTime(DateTime.UtcNow);
|
|
var isUnassigned = string.IsNullOrWhiteSpace(row.AssigneeId);
|
|
var isPastDue = ComputeIsPastDue(row, effectiveToday);
|
|
|
|
var presentation = new BoardRowPresentation(
|
|
StatusDisplay: _statusMapper.ToDisplay(row.Status, isUnassigned),
|
|
IsPastDue: isPastDue,
|
|
WorkOrderTypeDisplay: string.IsNullOrWhiteSpace(row.WorkOrderType) ? null : row.WorkOrderType.Trim()
|
|
);
|
|
|
|
return new WorkOrderBoardItemDto(row, presentation);
|
|
}
|
|
|
|
private bool ComputeIsPastDue(WorkOrderBoardRowDto row, DateOnly today)
|
|
{
|
|
if (!row.ScheduledDate.HasValue)
|
|
return false;
|
|
|
|
if (_statusMapper.IsTerminal(row.Status))
|
|
return false;
|
|
|
|
return row.ScheduledDate.Value < today;
|
|
}
|
|
}
|
|
}
|