}
}
+sub get {
+ my $c = shift;
+
+ my $users = $c->model('users');
+ my $comments = $c->model('comments');
+ my $user = $c->stash('user');
+
+ my $data = $c->req->query_params->to_hash;
+ my ($key, $value);
+
+ if ($data->{discussion_id}) {
+ $key = 'discussion_id';
+ $value = $data->{discussion_id};
+ }
+ elsif ($data->{cid}) {
+ $key = 'cid';
+ $value = $data->{cid};
+ }
+ elsif ($data->{pid}) {
+ $key = 'pid';
+ $value = $data->{pid};
+ }
+
+ my $comments_ref = $comments->select($key => $value);
+ if (!defined $comments_ref) {
+ $c->render(json => { error => 1, message => 'invalid request' });
+ $c->rendered(400);
+ return;
+ }
+ $c->render(json => { $key => $value, comments => $comments_ref });
+ return;
+}
+
1;