Initial Backend
This commit is contained in:
parent
bcf92c21e6
commit
3f6ff87370
15 changed files with 782 additions and 0 deletions
53
backend/Controllers/ServiceController.cs
Normal file
53
backend/Controllers/ServiceController.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using ContainerDashboard.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ContainerDashboard;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ServiceController : ControllerBase
|
||||
{
|
||||
private ILogger<ServiceController> _logger;
|
||||
private IContainerService _service;
|
||||
|
||||
public ServiceController(ILogger<ServiceController> logger, IContainerService service)
|
||||
{
|
||||
_logger = logger;
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpGet()]
|
||||
public async Task<IActionResult> GetContainerList()
|
||||
{
|
||||
var containers = await _service.GetContainers();
|
||||
|
||||
return Ok(containers);
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> ToggleContainer(string containerName, string? containerNamespace, string action)
|
||||
{
|
||||
if (containerName == string.Empty || action == string.Empty)
|
||||
{
|
||||
return BadRequest("Missing required parameter");
|
||||
}
|
||||
|
||||
var container = await _service.GetContainer(containerName, containerNamespace);
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "START":
|
||||
await _service.StartContainer(container);
|
||||
break;
|
||||
|
||||
case "STOP":
|
||||
await _service.StopContainer(container);
|
||||
break;
|
||||
|
||||
default:
|
||||
return BadRequest("Incorrect action");
|
||||
}
|
||||
|
||||
return Ok(container);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue