feat: add endpoint for schedule

This commit is contained in:
2024-05-29 03:46:16 +03:00
parent 17961ccefc
commit f9750ef039
2 changed files with 55 additions and 2 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Security.Cryptography;
using Cronos;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite;
@ -17,6 +16,10 @@ using Npgsql;
using StackExchange.Redis;
using System;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text.Json;
namespace Mirea.Api.Endpoint.Controllers.Configuration;
@ -240,6 +243,27 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
return true;
}
[HttpPost("SetSchedule")]
[TokenAuthentication]
[BadRequestResponse]
public ActionResult<bool> SetSchedule([FromBody] ScheduleConfigurationRequest request)
{
var general = GeneralConfig;
general.ScheduleSettings = new ScheduleSettings
{
// every 6 hours
CronUpdateSchedule = request.CronUpdateSchedule ?? "0 */6 * * *",
StartTerm = request.StartTerm,
PairPeriod = request.PairPeriod.ConvertFromDto()
};
if (!CronExpression.TryParse(general.ScheduleSettings.CronUpdateSchedule, CronFormat.Standard, out _))
throw new ControllerArgumentException("The Cron task could not be parsed. Check the format of the entered data.");
GeneralConfig = general;
return true;
}