Init Commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using WhatsappPromo.Core.Models;
|
||||
using WhatsappPromo.Core.Services;
|
||||
|
||||
namespace WhatsappPromo.Worker.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ConfigController : ControllerBase
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public ConfigController(IConfigService configService)
|
||||
{
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetConfig()
|
||||
{
|
||||
var config = await _configService.GetConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> UpdateConfig([FromBody] SystemConfig config)
|
||||
{
|
||||
// Validar ruta
|
||||
if (!string.IsNullOrEmpty(config.DownloadPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(config.DownloadPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest($"Ruta inválida: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
await _configService.UpdateConfigAsync(config);
|
||||
return Ok(config);
|
||||
}
|
||||
|
||||
[HttpPost("start")]
|
||||
public async Task<IActionResult> Start()
|
||||
{
|
||||
var config = await _configService.GetConfigAsync();
|
||||
config.IsActive = true;
|
||||
await _configService.UpdateConfigAsync(config);
|
||||
return Ok(new { status = "Starting" });
|
||||
}
|
||||
|
||||
[HttpPost("stop")]
|
||||
public async Task<IActionResult> Stop()
|
||||
{
|
||||
var config = await _configService.GetConfigAsync();
|
||||
config.IsActive = false;
|
||||
await _configService.UpdateConfigAsync(config);
|
||||
return Ok(new { status = "Stopping" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user