mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 14:13:12 +00:00
Introduce in-process WeekRolled job with idempotent ledger to increment carriedOver for the SHOC board, plus optional PastDue cache and admin reprocess endpoints while keeping isPastDue derived on-read.
58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
using Api.SeaHavenIndustries.Options;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SeaHaven.Services.DTOs;
|
|
using SeaHaven.Services.Helpers;
|
|
using SeaHaven.Services.Interfaces;
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
{
|
|
/// <summary>Ops-only endpoints for manual domain job reprocessing.</summary>
|
|
[Authorize(Roles = "Admin")]
|
|
[ApiController]
|
|
[Route("api/workorders/jobs")]
|
|
public class WorkOrderJobsController : ControllerBase
|
|
{
|
|
private readonly IWorkOrderWeekRolledService _weekRolledService;
|
|
private readonly IPastDueCacheService _pastDueCacheService;
|
|
|
|
public WorkOrderJobsController(
|
|
IWorkOrderWeekRolledService weekRolledService,
|
|
IPastDueCacheService pastDueCacheService)
|
|
{
|
|
_weekRolledService = weekRolledService;
|
|
_pastDueCacheService = pastDueCacheService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reprocess WeekRolled for a specific operational week (Monday start).
|
|
/// Idempotent via WorkOrderWeekRolledLedger.
|
|
/// </summary>
|
|
[HttpPost("week-rolled")]
|
|
[ProducesResponseType(typeof(WeekRolledJobResult), StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<WeekRolledJobResult>> RunWeekRolled(
|
|
[FromQuery] DateOnly? sourceWeekStart,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var weekStart = sourceWeekStart
|
|
?? WorkOrderOperationalWeek.GetPreviousOperationalWeekStart(DateTime.UtcNow);
|
|
|
|
if (weekStart.DayOfWeek != DayOfWeek.Monday)
|
|
return BadRequest("sourceWeekStart must be a Monday (operational week start).");
|
|
|
|
var result = await _weekRolledService.ProcessWeekRolledAsync(weekStart, cancellationToken);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Refresh optional OperationalFlags.PastDue cache (board isPastDue remains on-read).
|
|
/// </summary>
|
|
[HttpPost("past-due-cache")]
|
|
[ProducesResponseType(typeof(PastDueCacheJobResult), StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PastDueCacheJobResult>> RunPastDueCache(CancellationToken cancellationToken)
|
|
{
|
|
var result = await _pastDueCacheService.RefreshAsync(cancellationToken);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|