From ac05923f9faaaa0154981cb740ee0b7d14bab42a Mon Sep 17 00:00:00 2001 From: hylom Date: Mon, 31 Oct 2016 21:36:10 +0900 Subject: [PATCH] Controller::API::Comment: implement create method done --- .../lib/Newslash/Web/Controller/API/Comment.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm b/src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm index a4692840..6cd45cec 100644 --- a/src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm +++ b/src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm @@ -56,10 +56,19 @@ EOT elsif ($params->{action} eq 'post') { my $cid = $comments->create($params, $user, $extra_params, $opts); if ($cid) { - $data->{type} = "comment"; - $data->{id} = $cid; - $data->{cid} = $cid; - $c->render(json => $data); + my $ret = {}; + my $result = $comments->select(cid => $cid); + if ($result) { + $ret->{type} = "comment"; + $ret->{id} = $cid; + $ret->{cid} = $cid; + $ret->{new_comment} = $result; + $c->render(json => $ret); + } + else { + $c->render(json => { error => 1, message => "cannot get created comment" }); + $c->rendered(500); + } } else { warn $comments->last_error; -- 2.11.0