Slon/Api/V1/Markers: Implement /api/v1/markers
This commit is contained in:
parent
e223273300
commit
95aecb9fb1
6 changed files with 93 additions and 0 deletions
48
Slon/Api/V1/Markers.HC
Normal file
48
Slon/Api/V1/Markers.HC
Normal file
|
@ -0,0 +1,48 @@
|
|||
U0 @slon_api_v1_markers_get(SlonHttpSession* session)
|
||||
{
|
||||
if (!@slon_api_authorized(session)) {
|
||||
session->status(401);
|
||||
return;
|
||||
}
|
||||
|
||||
SLON_AUTH_ACCOUNT_ID
|
||||
|
||||
if (db->o("markers")->@(account_id)) {
|
||||
session->send(db->o("markers")->@(account_id));
|
||||
} else {
|
||||
session->send(SLON_EMPTY_JSON_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
U0 @slon_api_v1_markers_post(SlonHttpSession* session)
|
||||
{
|
||||
if (!@slon_api_authorized(session)) {
|
||||
session->status(401);
|
||||
return;
|
||||
}
|
||||
|
||||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
no_warn scratch_buffer;
|
||||
|
||||
SLON_AUTH_ACCOUNT_ID
|
||||
|
||||
U8* updated_at = @slon_api_timestamp_from_cdate(session, Now);
|
||||
|
||||
JsonKey* key = request_json->keys;
|
||||
JsonObject* obj = NULL;
|
||||
I64 version = cnts.jiffies;
|
||||
while (key) {
|
||||
obj = key->value;
|
||||
if (obj) {
|
||||
obj->set("version", version, JSON_NUMBER);
|
||||
obj->set("updated_at", updated_at, JSON_STRING);
|
||||
}
|
||||
key = key->next;
|
||||
}
|
||||
|
||||
db->o("markers")->set(account_id, request_json, JSON_OBJECT);
|
||||
@slon_db_save_markers_to_disk;
|
||||
|
||||
session->send(request_json);
|
||||
@slon_free(session, updated_at);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue