38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
|
|
using HRM.BO;
|
||
|
|
using HRM.UI.Realtime.Jobs;
|
||
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
|
||
|
|
namespace HRM.UI.Controllers.Realtime
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Reading background jobs over plain HTTP. The browser uses it to catch up (page reload, another tab) and as a
|
||
|
|
/// fallback when no SignalR connection can be made; live changes come over the hub.
|
||
|
|
/// </summary>
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/jobs")]
|
||
|
|
[Authorize]
|
||
|
|
public class JobsController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly IJobRunner _jobRunner;
|
||
|
|
|
||
|
|
public JobsController(IJobRunner jobRunner)
|
||
|
|
{
|
||
|
|
_jobRunner = jobRunner;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>One job's current state.</summary>
|
||
|
|
[HttpGet("{runId}")]
|
||
|
|
public ActionResult Get(string runId)
|
||
|
|
{
|
||
|
|
CurrentUser user = CurrentUser.GetCurrentUser(HttpContext.User);
|
||
|
|
JobAccess access = _jobRunner.TryGet(runId, user.UserID, user.PayrollTypeID, out JobSnapshot snapshot);
|
||
|
|
if (access == JobAccess.NotFound)
|
||
|
|
return NotFound("The job could not be found. The application may have restarted.");
|
||
|
|
if (access == JobAccess.Forbidden)
|
||
|
|
return Forbid();
|
||
|
|
return Ok(snapshot);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|