forked from ddrilling/AsbCloudServer
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudInfrastructure.Background;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class BackgroundWorkController : ControllerBase
|
|
{
|
|
private readonly BackgroundWorker backgroundWorker;
|
|
|
|
public BackgroundWorkController(BackgroundWorker backgroundWorker)
|
|
{
|
|
this.backgroundWorker = backgroundWorker;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult GetAll()
|
|
{
|
|
var result = new {
|
|
CurrentWork = (BackgroundWorkDto?)backgroundWorker.CurrentWork,
|
|
RunOnceQueue = backgroundWorker.WorkStore.RunOnceQueue.Select(work => (BackgroundWorkDto)work),
|
|
Periodics = backgroundWorker.WorkStore.Periodics.Select(work => (BackgroundWorkDto)work.Work),
|
|
Felled = backgroundWorker.WorkStore.Felled.Select(work => (BackgroundWorkDto)work),
|
|
};
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("Current")]
|
|
public IActionResult GetCurrent()
|
|
{
|
|
var work = backgroundWorker.CurrentWork;
|
|
if (work == null)
|
|
return NoContent();
|
|
|
|
return Ok(work);
|
|
}
|
|
|
|
[HttpGet("Failed")]
|
|
public IActionResult GetFelled()
|
|
{
|
|
var result = backgroundWorker.WorkStore.Felled.Select(work => (BackgroundWorkDto)work);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|