Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Five new APIs to facilitate docbot Development #17

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix POST data in bridge/parser. Fix Point POST endpoint
Evan Radkoff committed Aug 26, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 0847f9cedccb046b31e0f33f3833ddcf0ffd180f
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
swagger.yaml
swagger.yaml
.DS_Store
28 changes: 16 additions & 12 deletions functions/internal/Point/POST/v1/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
'req' variable has:
'headers' - object with request headers
'payload' - request body data as a string
'body' - request body as a string
'variables' - object with function variables

'res' variable has:
@@ -25,51 +25,55 @@ type Context = {
export default async ({ req, res, log, error }: Context) => {
const client = new Client()
await client.connect();

// If we upgrade appwrite, req.body should be already parsed
// https://appwrite.io/docs/products/functions/develop#request
const body = JSON.parse(req.body);

if (!req.body || !('case_id' in req.body)) {
if (!body || !('case_id' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'case_id'"), 400);
}

if (!('user_id' in req.body)) {
if (!('user_id' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'user_id'"), 400);
}

if (!('document_id' in req.body)) {
if (!('document_id' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'document_id'"), 400);
}

if (!('service_id' in req.body)) {
if (!('service_id' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'service_id'"), 400);
}

// It seems standard to give the doc source URL
if (!('source' in req.body)) {
if (!('source' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'source'"), 400);
}

// For now this API only exists for docbot, so ensure docbot-specific fields are passed
if (!('docbot_version' in req.body)) {
if (!('docbot_version' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'docbot_version'"), 400);
}
if (!('ml_score' in req.body)) {
if (!('ml_score' in body)) {
await client.end();
return res.json(RESTfulAPI.response(Bitmask.MISSING_PARAMETER, "Missing Parameter 'ml_score'"), 400);
}

const caseObj = await Phoenix.getCase(req.body.case_id, client);
const caseObj = await Phoenix.getCase(body.case_id, client);
const caseId = parseInt(caseObj?.id);
const title = caseObj?.title;

const result = await Phoenix.createPoint(
caseId, req.body.user_id, req.body.document_id, req.body.service_id, 'pending', title,
req.body.source, req.body.analysis, req.body.quote_text, req.body.quote_start, req.body.quote_end,
req.body.docbot_version, req.body.ml_score, client
caseId, body.user_id, body.document_id, body.service_id, 'pending', title,
body.source, body.analysis, body.quote_text, body.quote_start, body.quote_end,
body.docbot_version, body.ml_score, client
);

await client.end();
9 changes: 3 additions & 6 deletions parser/src/index.php
Original file line number Diff line number Diff line change
@@ -12,12 +12,9 @@
try {
require __DIR__ . "/vendor/autoload.php";


$body = match ($_SERVER["REQUEST_METHOD"]) {
"POST" => $_POST,
default => file_get_contents("php://input")
};

// $_POST only handles form data (application/x-www-form-urlencoded or multipart/form-data)
// but for application/json data we'll read from php://input
$body = file_get_contents("php://input");

$client = new Client();