refactor(jobs): centralize status lifecycle

This commit is contained in:
cesnimda
2026-08-31 11:59:49 +02:00
parent 5f0c0b0549
commit ba7748193b
7 changed files with 92 additions and 107 deletions
@@ -14,6 +14,26 @@ namespace JobTrackerApi.Services;
// docs/architecture/application-workspace.md.
public static class JobLifecycleEvents
{
/// <summary>
/// Keeps the application date aligned with the pipeline stage and preserves a cleared date in
/// the event ledger. Both full-record and status-only updates use this single boundary.
/// </summary>
public static void SyncAppliedDateWithHistory(JobTrackerContext db, JobApplication job, DateTime at)
{
var cleared = JobPipeline.SyncAppliedDate(job, at);
if (cleared is null) return;
db.JobEvents.Add(new JobEvent
{
JobApplicationId = job.Id,
Type = JobPipeline.AppliedDateClearedEvent,
OldValue = cleared.Value.ToString("o"),
NewValue = null,
Note = $"Moved to {job.Status} before applying; application date cleared.",
At = at,
});
}
// Records the status change itself plus, when the transition warrants it, one lifecycle event.
// Replaces the hand-written StatusChanged block at each call site.
public static void RecordStatusChange(JobTrackerContext db, JobApplication job, string? oldStatus, DateTime at)