Код: Выделить всё
proposalApi.MapGet("/proposals", () => {
try
{
DirectoryInfo dir = new DirectoryInfo(ProposalsDirectory);
var files = dir.GetFiles("*.txt").Select(x => x.Name).ToList();
var data = files.Select(x => new
{
index = int.Parse(new String(x.Where(Char.IsDigit).ToArray())),
value = x
}).OrderByDescending(x => x.index).Select(x => x.value).ToArray();
return data.Count() == 0 ? Results.NotFound() : Results.Ok(data);
}
catch (Exception ex)
{
return ErrorDetails(ex);
}
});
proposalApi.MapGet("/proposals/{fileName}", (int fileName) => {
try
{
string content = File.ReadAllText(ProposalsDirectory + fileName);
return Results.Ok(content);
}
catch (Exception ex)
{
return ErrorDetails(ex);
}
});
https://localhost:44312/proposals/proposals
https:/ /localhost:44312/proposals/
Точки останова:
[img]https://i. sstatic.net/cw0epwFg.png[/img]
Путь к коду проекта веб-API (скрипт):
https://github.com/nitinjs /upworkify/tree/main/ProposalAPI.Core
Подробнее здесь: https://stackoverflow.com/questions/791 ... -being-hit