2
0

API: Fix nullable bug on Getchapters

This commit is contained in:
glax 2023-06-15 21:15:44 +02:00
parent 5b2546fdbc
commit dda4054d34

View File

@ -75,21 +75,26 @@ app.MapGet("/Publications/GetFromConnector", (string connectorName, string title
return taskManager.GetPublicationsFromConnector(connector, title); return taskManager.GetPublicationsFromConnector(connector, title);
}); });
app.MapGet("/Publications/GetChapters", (string connectorName, string internalId, bool onlyNew, bool onlyExisting, string? language) => app.MapGet("/Publications/GetChapters",
{ (string connectorName, string internalId, string? onlyNew, string? onlyExisting, string? language) =>
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value; {
if (connector is null) string[] yes = { "true", "yes", "1", "y" };
return Array.Empty<Chapter>(); bool newOnly = onlyNew is not null && yes.Contains(onlyNew);
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId); bool existingOnly = onlyExisting is not null && yes.Contains(onlyExisting);
if (publication is null)
return Array.Empty<Chapter>(); Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
if (connector is null)
if(onlyNew) return Array.Empty<Chapter>();
return taskManager.GetNewChaptersList(connector, (Publication)publication, language??"en").ToArray(); Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
else if (onlyExisting) if (publication is null)
return taskManager.GetExistingChaptersList(connector, (Publication)publication, language ?? "en").ToArray(); return Array.Empty<Chapter>();
else
return connector.GetChapters((Publication)publication, language??"en"); if(newOnly)
return taskManager.GetNewChaptersList(connector, (Publication)publication, language??"en").ToArray();
else if (existingOnly)
return taskManager.GetExistingChaptersList(connector, (Publication)publication, language ?? "en").ToArray();
else
return connector.GetChapters((Publication)publication, language??"en");
}); });
app.MapGet("/Tasks/GetTypes", () => Enum.GetNames(typeof(TrangaTask.Task))); app.MapGet("/Tasks/GetTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));