DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/BackgroundWorkController.cs

51 lines
1.5 KiB
C#
Raw Normal View History

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]
2023-10-10 13:45:48 +05:00
public class BackgroundWorkController : ControllerBase
{
private readonly BackgroundWorker backgroundWorker;
2023-10-10 13:45:48 +05:00
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);
}
2023-10-10 13:45:48 +05:00
[HttpGet("Current")]
public IActionResult GetCurrent()
{
2023-10-12 11:48:55 +05:00
var work = backgroundWorker.CurrentWork;
if (work == null)
return NoContent();
return Ok(work);
2023-10-10 13:45:48 +05:00
}
[HttpGet("Failed")]
public IActionResult GetFelled()
{
var result = backgroundWorker.WorkStore.Felled.Select(work => (BackgroundWorkDto)work);
return Ok(result);
}
}
}