Continue to implement the API.
Started implementing ts_api:list_entries/3 Implemented ts_api:get_entry_by_id/4
This commit is contained in:
parent
309d6915fc
commit
098cd4cbb9
@ -64,7 +64,7 @@ dispatch_entry_by_id(YArg, Username, Timeline, []) ->
|
||||
dispatch_entry_by_id(YArg, Username, Timeline, [H|T]) ->
|
||||
|
||||
EventId = list_to_integer(H), % TODO: guard against bad input
|
||||
get_entry_by_id(Username, Timeline, EventId).
|
||||
get_entry_by_id(YArg, Username, Timeline, EventId).
|
||||
|
||||
dispatch_entry_by_date(YArg, Username, Timeline, Params) -> todo.
|
||||
|
||||
@ -103,7 +103,7 @@ put_timeline(YArg, Username, TimelineId) ->
|
||||
EJSONRec = ts_json:record_to_ejson(NewRecord)
|
||||
JSONReturn = json:encode({struct, [
|
||||
{status, "ok"},
|
||||
{record, EJSONRec}
|
||||
{timeline, EJSONRec}
|
||||
]}),
|
||||
|
||||
% return the new record
|
||||
@ -115,7 +115,7 @@ put_timeline(YArg, Username, TimelineId) ->
|
||||
EJSONRec = ts_json:record_to_ejson(ExistingRecord),
|
||||
JSONReturn = json:encode({struct, [
|
||||
{status, "ignored"},
|
||||
{record, EJSONRec},
|
||||
{timeline, EJSONRec},
|
||||
{see_docs, "/ts_api_doc/timeline#PUT"}
|
||||
]}),
|
||||
|
||||
@ -138,7 +138,7 @@ post_timeline(YArg, Username, TimelineId) ->
|
||||
EJSONRec = ts_json:record_to_ejson(NewRecord),
|
||||
JSONReturn = json:encode({struct, [
|
||||
{status, "updated"},
|
||||
{record, EJSONRec}
|
||||
{timeline, EJSONRec}
|
||||
]}),
|
||||
|
||||
{content, "application/json", JSONReturn};
|
||||
@ -149,7 +149,40 @@ post_timeline(YArg, Username, TimelineId) ->
|
||||
_Error -> make_json_500(YArg)
|
||||
end.
|
||||
|
||||
delete_timeline(YArg, Username, TimelineId) -> todo.
|
||||
delete_timeline(YArg, Username, TimelineId) -> {status, 405}.
|
||||
|
||||
list_entries(YArg, Username, Timeline) ->
|
||||
% pull out the POST data
|
||||
PostData = yaws_api:parse_post(YArg),
|
||||
|
||||
% read or default the Start
|
||||
Start = case lists:keyfind(start, 1, PostData) of
|
||||
{start, StartVal} -> StartVal; false -> 0 end.
|
||||
|
||||
% read or default the Length
|
||||
Length = case lists:keyfind(length, 1, PostData)
|
||||
|
||||
% read or default the sort order
|
||||
|
||||
get_entry_by_id(YArg, Username, Timeline, EventId) ->
|
||||
case ts_entry:lookup(Username, Timeline, EventId) of
|
||||
|
||||
% no such record
|
||||
no_record -> make_json_404(YArg);
|
||||
|
||||
% record found
|
||||
Entry ->
|
||||
% convert to EJSON
|
||||
EJSONRec = ts_json:record_to_ejson(Entry),
|
||||
|
||||
% create response
|
||||
JSONReturn = json:encode({struct, [
|
||||
{status, "ok"},
|
||||
{entry, EJSONRec}
|
||||
]}),
|
||||
|
||||
{content, "application/json", JSONReturn}
|
||||
end.
|
||||
|
||||
% ============================== %
|
||||
% ======== UTIL METHODS ======== %
|
||||
|
Loading…
x
Reference in New Issue
Block a user