// Endpoints
app.MapPost("/api/contracts/upload", async (
HttpContext context,
PdfService pdfService,
ContractAnalysisService analysisService,
DatabaseService dbService) =>
{
try
{
var file = context.Request.Form.Files[0];
if (file == null || file.Length == 0)
return Results.BadRequest("No file uploaded");
var text = await pdfService.ExtractTextFromPdf(file);
var contractInfo = await analysisService.AnalyzeContract(text);
await dbService.SaveContract(contractInfo);
return Results.Ok(contractInfo);
}
catch (Exception ex)
{
return Results.Problem(ex.Message);
}
});
app.MapGet("/api/contracts/{id}", async (
string id,
DatabaseService dbService) =>
{
try
{
var contract = await dbService.GetContract(id);
return contract != null ? Results.Ok(contract) : Results.NotFound();
}
catch (Exception ex)
{
return Results.Problem(ex.Message);
}
});
app.Run();