Fixed empty returns if some value were null

This commit is contained in:
glax 2023-05-24 23:52:40 +02:00
parent fc89537f63
commit d6e75fda31

View File

@ -82,23 +82,45 @@ app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string?
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) => app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>
{ {
try
{
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType); TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
if (searchString is null) if (searchString is null || connectorName is null)
return taskManager.GetAllTasks().Where(tTask => tTask.task == task && tTask.connectorName == connectorName); return taskManager.GetAllTasks().Where(tTask => tTask.task == task);
else else
return taskManager.GetAllTasks().Where(tTask => return taskManager.GetAllTasks().Where(tTask =>
tTask.task == task && tTask.connectorName == connectorName && tTask.ToString() tTask.task == task && tTask.connectorName == connectorName && tTask.ToString()
.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)); .Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
}
catch (ArgumentException)
{
return Array.Empty<TrangaTask>();
}
}); });
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) => app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
{ {
try
{
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType); TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask => TrangaTask? task = null;
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName); if (connectorName is null || publicationId is null)
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask);
else
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
tTask.connectorName == connectorName);
if (task is null) if (task is null)
return; return;
taskManager.ExecuteTaskNow(task); taskManager.ExecuteTaskNow(task);
}
catch (ArgumentException)
{
return;
}
}); });
app.MapGet("/Tasks/GetRunningTasks", app.MapGet("/Tasks/GetRunningTasks",
@ -109,22 +131,50 @@ app.MapGet("/Queue/GetList",
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) => app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
{ {
try
{
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType); TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask => TrangaTask? task = null;
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName); if (connectorName is null || publicationId is null)
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask);
else
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
tTask.connectorName == connectorName);
if (task is null) if (task is null)
return; return;
taskManager.AddTaskToQueue(task); taskManager.AddTaskToQueue(task);
}
catch (ArgumentException)
{
return;
}
}); });
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) => app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
{ {
try
{
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType); TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask => TrangaTask? task = null;
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName); if (connectorName is null || publicationId is null)
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask);
else
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
tTask.connectorName == connectorName);
if (task is null) if (task is null)
return; return;
taskManager.RemoveTaskFromQueue(task); taskManager.RemoveTaskFromQueue(task);
}
catch (ArgumentException)
{
return;
}
}); });
app.MapGet("/Settings/Get", () => taskManager.settings); app.MapGet("/Settings/Get", () => taskManager.settings);