-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsumo_rest_doc.erl
39 lines (31 loc) · 1.38 KB
/
sumo_rest_doc.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%%% @doc Implement this behavior on your entities so the handlers can
%%% properly [un]marshall them.
-module(sumo_rest_doc).
-type json() :: sr_json:json().
-type entity() :: sumo:user_doc().
-export_type([entity/0]).
-type path() :: string().
-export_type([path/0]).
-type reason() :: iodata().
-export_type([reason/0]).
-type duplication_conditions() :: sumo:conditions().
-export_type([duplication_conditions/0]).
-type context() :: #{req := sr_request:req(), state := sr_state:state()}.
-export_type([context/0]).
-callback to_json(entity()) -> json().
-callback from_json(json()) -> {ok, entity()} | {error, reason()}.
-callback from_ctx(context()) -> {ok, entity()} | {error, reason()}.
-callback update(entity(), json()) -> {ok, entity()} | {error, reason()}.
-callback location(entity(), path()) -> binary().
%% it's only needed if dups should raise 422 conflict
-callback duplication_conditions(entity()) -> duplication_conditions().
%% it's only needed if ids are not coming in PUT jsons
-callback from_json(binary(), json()) -> {ok, entity()} | {error, reason()}.
%% it's only needed if ids are different from binary, integer or string
-callback id_from_binding(binary()) -> term().
-optional_callbacks([ duplication_conditions/1
, from_json/1
, from_json/2
, id_from_binding/1
, from_ctx/1
]).