[ADD/WIP] Add some HTTP request code

We can now *register* users!
This commit is contained in:
LDA 2024-06-13 09:35:57 +02:00
commit 0fa95c2d14
12 changed files with 320 additions and 11 deletions

52
src/Routes/Transactions.c Normal file
View file

@ -0,0 +1,52 @@
#include <Routes.h>
#include <Cytoplasm/Log.h>
#include <Matrix.h>
#include <AS.h>
RouteHead(RouteTxns, arr, argp)
{
ParseeHttpArg *args = argp;
HashMap *request = NULL;
HashMap *response = NULL;
Array *events;
size_t i;
Log(LOG_INFO, "Caught one!");
response = ASVerifyRequest(args);
if (response)
{
Log(LOG_INFO, ":(");
goto end;
}
if (HttpRequestMethodGet(args->ctx) != HTTP_PUT)
{
HttpResponseStatus(args->ctx, HTTP_METHOD_NOT_ALLOWED);
response = MatrixCreateError(
"M_UNRECOGNIZED",
"Path /transactions only accepts PUT as a valid method."
);
goto end;
}
Log(LOG_INFO, "Caught a decent one!");
RequestJSON();
/* TODO: Do a thing with these. */
events = JsonValueAsArray(HashMapGet(request, "events"));
for (i = 0; i < ArraySize(events); i++)
{
HashMap *event = JsonValueAsObject(ArrayGet(events, i));
Log(LOG_INFO, "Event by '%s', with type '%s'",
JsonValueAsString(HashMapGet(event, "sender")),
JsonValueAsString(HashMapGet(event, "type"))
);
}
Log(LOG_INFO, "OK!");
response = HashMapCreate();
end:
JsonFree(request);
return response;
}