|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
#include "json/json.h"
|
|
|
|
|
#include "json/layout.h"
|
|
|
|
|
#include "collections/array.h"
|
|
|
|
|
|
|
|
|
|
#include "http/server/request.h"
|
|
|
|
|
#include "model/status.h"
|
|
|
|
@ -40,12 +41,49 @@ void show_status( struct http_request* req, struct status* s )
|
|
|
|
|
|
|
|
|
|
api_status_write_as_json(s,f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Route: /api/v1/statuses/%d{s->id}/context
|
|
|
|
|
void show_status_context( struct http_request* req, struct status* s )
|
|
|
|
|
{
|
|
|
|
|
http_request_send_headers( req, 200, "application/json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
|
|
|
|
|
fprintf( f, "{\"ancestors\":[],\"descendants\":[]}" );
|
|
|
|
|
struct {
|
|
|
|
|
struct status** items;
|
|
|
|
|
int count;
|
|
|
|
|
} ancestors, replies;
|
|
|
|
|
status_get_context( s, &ancestors, &replies );
|
|
|
|
|
/*
|
|
|
|
|
memset( &ancestors, 0, sizeof(ancestors));
|
|
|
|
|
memset( &replies, 0, sizeof(replies));
|
|
|
|
|
struct status* test = status_from_id( 111 );
|
|
|
|
|
array_append( &ancestors, sizeof(test), &test );
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
fprintf( f, "{\"ancestors\":[" );
|
|
|
|
|
for( int i = 0; i < ancestors.count; ++i ) {
|
|
|
|
|
struct status* s = ancestors.items[i];
|
|
|
|
|
api_status_write_as_json(s,f);
|
|
|
|
|
status_free(s);
|
|
|
|
|
|
|
|
|
|
if( i != ancestors.count - 1 ) {
|
|
|
|
|
fprintf( f, "," );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(ancestors.items);
|
|
|
|
|
|
|
|
|
|
fprintf( f, "],\"descendants\":[" );
|
|
|
|
|
for( int i = 0; i < replies.count; ++i ) {
|
|
|
|
|
struct status* s = replies.items[i];
|
|
|
|
|
api_status_write_as_json(s,f);
|
|
|
|
|
status_free(s);
|
|
|
|
|
|
|
|
|
|
if( i != replies.count - 1 ) {
|
|
|
|
|
fprintf( f, "," );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(replies.items);
|
|
|
|
|
fprintf( f, "]}" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_statuses( struct http_request* req, struct status** ss, int count )
|
|
|
|
|