Commit 3ce787c1 authored by Sebastian Seufert's avatar Sebastian Seufert
Browse files

- fixed response schema for add bg

- added 'h' in run.pl -> sync db, halt server, halt. (Convenience helper)
parent d9dfdfc6
......@@ -14,8 +14,12 @@ action_reply_success(Code, Msg, Reply) :-
format(atom(Reply), 'Endpoint: ~q', [Msg]),
reply_json(Reply, [status(Code)]).
action_reply_success(Code, Msg, Details, Reply) :-
Reply =_{endpoint:Msg,details:Details},
action_reply_success(Code, Endpoint, Action, Reply) :-
Reply =_{endpoint:Endpoint,action:Action},
reply_json(Reply, [status(Code)]).
action_reply_success(Code, Endpoint, Action, Details, Reply) :-
Reply =_{endpoint:Endpoint,action:Action, details:Details},
reply_json(Reply, [status(Code)]).
generic_reply(Method, Pred, Info) :-
......
......@@ -8,3 +8,6 @@
% :- initialization(guitracer).
:- initialization(server_main).
%% convenience in user module
h :- web_api:http_stop, halt.
\ No newline at end of file
......@@ -17,6 +17,8 @@
% Structure of items & persistency
:- use_module(theory_bg).
init :- server_main.
%%%%%%%%%%%%%%%%
......@@ -117,13 +119,20 @@ set_bg(Req) :-
http_read_json_dict(Req, Dict,[value_string_as(atom), tag(type)]),
(is_list(Dict)
-> maplist(assert_dict, Dict, Accs),
length(Dict,L),
sum_list(Accs,Total)
; assert_dict(Dict, Total)
),
(
Total is 0
-> action_reply_success(204, add, 'fact(s) already present, no change', Reply)
; action_reply_success(201, add, Total, Reply)
; L == Total
-> format(atom(Message), 'Received: ~q, Added: ~q', [L,Total]),
action_reply_success(201, add, Message, Reply)
; Diff is (L - Total),
format(atom(Message), 'Received: ~q, Added: ~q, Skipped: ~q', [L,Total, Diff]),
action_reply_success(201, add, Message, Reply)
).
assert_dict(D,Acc) :-
......@@ -250,4 +259,9 @@ getPath(Dict, Dict.abs_path).
get_field(Dict, Field, Res) :- Res = Dict.Field.
get_all(Type, Res) :- findall(T, (theory_bg:item(_,T), is_dict(T,Type)), Res).
get_one(Type, Res) :- is_dict(Res,Type), !.
match_with(Tag, Field, Dict, Value) :- theory_bg:item(_,Dict), is_dict(Dict,Tag), Dict.Field = Value.
\ No newline at end of file
match_with(Tag, Field, Dict, Value) :- theory_bg:item(_,Dict), is_dict(Dict,Tag), Dict.Field = Value.
%%
h :- http_stop, halt.
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment