67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
|
|
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" });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|