Skip to content

Commit

Permalink
Completed PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
careo committed Nov 16, 2008
1 parent 62fcf86 commit 1671335
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/mochirest_web.erl
Expand Up @@ -76,9 +76,13 @@ read(Req, DocRoot) ->
Req:respond({200, [], rfc4627:encode(Doc) }).

update(Req, DocRoot) ->
Doc = from_json(id_from_file(file_from_req(Req)), Req:recv_body()),
save(Doc, DocRoot),
Req:respond({200, [], [to_json(Doc)]}).
Body = Req:recv_body(),
io:format("Update: ~p~n", [Body]),
{ok, Doc,_} = rfc4627:decode(Body),
io:format("... Doc: ~p~n", [Doc]),

put_doc(Doc),
Req:respond({200, [], rfc4627:encode(Doc)}).

delete(Req, DocRoot) ->
DocId = doc_id(Req),
Expand Down Expand Up @@ -186,3 +190,12 @@ delete_doc(DocId) ->
io:format(" ... result: ~p~n", [Result]),
Result.

put_doc(Doc) ->
io:format("PUT ~p~n", [Doc]),
{obj,DocYargh} = Doc,
[DocId | _] = [ X || {"_id", X} <- DocYargh],
io:format("PUT to Couch -- Doc: ~p~n -- DocId: ~p~n", [Doc,DocId]),
Result = ecouch:doc_update("documents", DocId, Doc),
io:format(" ... result: ~p~n", [Result]),
Result.

0 comments on commit 1671335

Please sign in to comment.