worked up to evidence uploads
This commit is contained in:
parent
cf6cccffa5
commit
d02f1d447c
@ -578,11 +578,36 @@ public static partial class APIHandler
|
||||
await runner.WriteJsonResponse(StatusCodes.Status202Accepted, "Proker draft submitted.", PKIDList);
|
||||
});
|
||||
})
|
||||
.Map("/pushproker", proker =>
|
||||
.Map("/pkevidence", proker =>
|
||||
{
|
||||
proker.Run(async runner =>
|
||||
{
|
||||
await runner.WriteJsonResponse(StatusCodes.Status501NotImplemented, "Not yet finished.");
|
||||
if (!await runner.RequestValidated(3, "POST", true) || !Auth.TryGetUser(runner, out SafeUser CurrUser) ||
|
||||
await runner.TryGetBodyJsonAsync(["prokerid", "notes", "evidence"], CTS.Token) is not Dictionary<string, JsonElement> InElement) return;
|
||||
if (
|
||||
InElement["prokerid"].GetString() is not string ProkerID || ProkerID.Equals(string.Empty) ||
|
||||
InElement["notes"].GetString() is not string Notes || Notes.Equals(string.Empty) ||
|
||||
InElement["evidence"].GetString() is not string Evidence || Evidence.Equals(string.Empty)
|
||||
)
|
||||
{
|
||||
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Required property values is invalid or out of allowed range.");
|
||||
return;
|
||||
}
|
||||
byte[] PDFBytes = Convert.FromBase64String(Evidence);
|
||||
string FileName = $"{Crc32.Compute(PDFBytes):X8}.pdf";
|
||||
string FilePath = Path.Combine(AppContext.BaseDirectory , "wwwroot/uploads/dokumen" , FileName);
|
||||
if (!File.Exists(FilePath)) await File.WriteAllBytesAsync(FilePath, PDFBytes, CTS.Token);
|
||||
await RunNonQueryAsync(CS, "INSERT INTO [proker_journal] VALUES (@pjid, @pkid, @owid, 4, @nots, @docs, @tstp)", Query =>
|
||||
{
|
||||
DateTime Now = DateTime.Now;
|
||||
Query.Parameters.AddWithValue("@pjid", GenerateUuidV7(Now));
|
||||
Query.Parameters.AddWithValue("@pkid", ProkerID);
|
||||
Query.Parameters.AddWithValue("@owid", CurrUser.AgentID);
|
||||
Query.Parameters.AddWithValue("@nots", Notes);
|
||||
Query.Parameters.AddWithValue("@docs", FileName);
|
||||
Query.Parameters.AddWithValue("@tstp", Now);
|
||||
}, CTS.Token);
|
||||
await runner.WriteJsonResponse(StatusCodes.Status201Created, "Proker evidence accepted. Journal created successfully.");
|
||||
});
|
||||
})
|
||||
.Map("/evalproker", proker=>
|
||||
|
Loading…
x
Reference in New Issue
Block a user