Switched usage of POST and PUT verbs.

- POST and PUT were being used counter to typical usage, POST updating existing
  records and PUT creating new ones. Changed to PUT updating existing records
  and POST creating records.
This commit is contained in:
Jonathan Bernard 2011-04-15 13:53:24 -05:00
parent 17c5b9cbd1
commit 5b267ec67b

View File

@ -151,7 +151,7 @@ dispatch_entry(YArg, [UrlUsername, UrlTimelineId]) ->
case HTTPMethod of case HTTPMethod of
'GET' -> list_entries(YArg, Username, TimelineId); 'GET' -> list_entries(YArg, Username, TimelineId);
'PUT' -> put_entry(YArg, Username, TimelineId); 'POST' -> post_entry(YArg, Username, TimelineId);
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}]) _Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}])
end; end;
@ -163,7 +163,7 @@ dispatch_entry(YArg, [UrlUsername, UrlTimelineId, UrlEntryId]) ->
case HTTPMethod of case HTTPMethod of
'GET' -> get_entry(YArg, Username, TimelineId, EntryId); 'GET' -> get_entry(YArg, Username, TimelineId, EntryId);
'POST' -> post_entry(YArg, Username, TimelineId, EntryId); 'PUT' -> put_entry(YArg, Username, TimelineId, EntryId);
'DELETE' -> delete_entry(YArg, Username, TimelineId, EntryId); 'DELETE' -> delete_entry(YArg, Username, TimelineId, EntryId);
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}]) _Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}])
end; end;
@ -275,7 +275,7 @@ get_timeline(YArg, Username, TimelineId) ->
Timeline -> make_json_200(YArg, Timeline) Timeline -> make_json_200(YArg, Timeline)
end. end.
put_timeline(YArg, Username, TimelineId) -> post_timeline(YArg, Username, TimelineId) ->
% parse the request body % parse the request body
EJSON = parse_json_body(YArg), EJSON = parse_json_body(YArg),
@ -303,7 +303,7 @@ put_timeline(YArg, Username, TimelineId) ->
make_json_500(YArg, Error) make_json_500(YArg, Error)
end. end.
post_timeline(YArg, Username, TimelineId) -> put_timeline(YArg, Username, TimelineId) ->
% parse the POST data % parse the POST data
EJSON = parse_json_body(YArg), EJSON = parse_json_body(YArg),
%{struct, Fields} = EJSON, %{struct, Fields} = EJSON,
@ -422,7 +422,7 @@ get_entry(YArg, Username, TimelineId, EntryId) ->
Entry -> make_json_200(YArg, Entry) Entry -> make_json_200(YArg, Entry)
end. end.
put_entry(YArg, Username, TimelineId) -> post_entry(YArg, Username, TimelineId) ->
% parse the request body % parse the request body
EJSON = parse_json_body(YArg), EJSON = parse_json_body(YArg),
@ -449,7 +449,7 @@ put_entry(YArg, Username, TimelineId) ->
make_json_500(YArg, OtherError) make_json_500(YArg, OtherError)
end. end.
post_entry(YArg, Username, TimelineId, EntryId) -> put_entry(YArg, Username, TimelineId, EntryId) ->
% parse the POST data % parse the POST data
EJSON = parse_json_body(YArg), EJSON = parse_json_body(YArg),
@ -464,7 +464,7 @@ post_entry(YArg, Username, TimelineId, EntryId) ->
ok -> make_json_200(YArg, NewRecord); ok -> make_json_200(YArg, NewRecord);
no_record -> make_json_404(YArg, no_record -> make_json_404(YArg,
[{status, "no such entry"}, {see_docs, "/ts_api_doc/entries.html#POST"}]); [{error, "no such entry"}, {see_docs, "/ts_api_doc/entries.html#POST"}]);
Error -> Error ->
error_logger:error_report("TimeStamper: Unable to update entry: ~p", [Error]), error_logger:error_report("TimeStamper: Unable to update entry: ~p", [Error]),