-
Notifications
You must be signed in to change notification settings - Fork 10
/
sr_single_element_handler.erl
71 lines (67 loc) · 1.86 KB
/
sr_single_element_handler.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
%%% @doc GET|PUT|DELETE /elements/:id handler
-module(sr_single_element_handler).
-behaviour(trails_handler).
-include_lib("mixer/include/mixer.hrl").
-mixin([{ sr_single_entity_handler
, [ init/3
, rest_init/2
, allowed_methods/2
, resource_exists/2
, content_types_accepted/2
, content_types_provided/2
, handle_get/2
, handle_put/2
, handle_patch/2
, delete_resource/2
]
}]).
-export([ trails/0
]).
-spec trails() -> trails:trails().
trails() ->
RequestBody =
#{ name => <<"request body">>
, in => body
, description => <<"request body (as json)">>
, required => true
},
Id =
#{ name => id
, in => path
, description => <<"Element Key">>
, required => true
, type => string
},
Metadata =
#{ get =>
#{ tags => ["elements"]
, description => "Returns an element"
, produces => ["application/json"]
, parameters => [Id]
}
, patch =>
#{ tags => ["elements"]
, description => "Updates an element"
, consumes => ["application/json", "application/json; charset=utf-8"]
, produces => ["application/json"]
, parameters => [RequestBody, Id]
}
, put =>
#{ tags => ["elements"]
, description => "Updates or creates a new element"
, consumes => ["application/json", "application/json; charset=utf-8"]
, produces => ["application/json"]
, parameters => [RequestBody, Id]
}
, delete =>
#{ tags => ["elements"]
, description => "Deletes an element"
, parameters => [Id]
}
},
Path = "/elements/:id",
Opts = #{ path => Path
, model => elements
, verbose => true
},
[trails:trail(Path, ?MODULE, Opts, Metadata)].