1:- module(bc_api_comment, []). 2
3:- use_module(library(dict_schema)). 4:- use_module(library(arouter)). 5
6:- use_module(bc_view). 7:- use_module(bc_api_io). 8:- use_module(bc_api_auth). 9:- use_module(bc_api_error). 10:- use_module(bc_api_actor). 11:- use_module(bc_data_comment). 12:- use_module(bc_comment_question). 13
16
17:- route_get(api/post/Id/comments,
18 bc_auth, comment_tree(Id)). 19
(PostId):-
21 bc_comment_tree(PostId, Comments),
22 bc_reply_success(Comments).
23
26
27:- route_post(api/post/Id/comment,
28 bc_call_handle_error, comment_save(Id)). 29
(PostId):-
31 bc_read_by_schema(bc_comment, Comment),
32 bc_comment_save(PostId, Comment, CommentId),
33 bc_view_purge_cache,
34 bc_reply_success(CommentId).
35
37
38:- route_del(api/comment/EntryId/Id,
39 bc_auth, comment_remove(EntryId, Id)). 40
(EntryId, Id):-
42 bc_actor(Actor),
43 bc_comment_remove(Actor, EntryId, Id),
44 bc_view_purge_cache,
45 bc_reply_success(Id).
46
49
50:- route_get(api/question, comment_question). 51
:-
53 bc_random_question(Id, Question),
54 bc_reply_success(_{ id: Id, question: Question }).
55
58
59:- register_schema(bc_comment, _{
60 type: dict,
61 tag: comment,
62 keys: _{
63 author: _{ type: string, min_length: 1 },
64 content: _{ type: string, min_length: 1 },
65 reply_to: _{ type: atom, min_length: 1 },
66 email: _{ type: string, min_length: 1 },
67 site: _{ type: string, min_length: 1 },
68 question: integer,
69 answer: atom,
70 notify: bool
71 },
72 optional: [ reply_to, email, site, notify ]
73}).