2023-10-09 13:12:45 +05:00
|
|
|
|
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
|
2023-10-09 13:12:45 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly BackgroundWorker backgroundWorker;
|
|
|
|
|
|
2023-10-10 13:45:48 +05:00
|
|
|
|
public BackgroundWorkController(BackgroundWorker backgroundWorker)
|
2023-10-09 13:12:45 +05:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
2023-10-09 13:12:45 +05:00
|
|
|
|
}
|
|
|
|
|
}
|