./ct_report/coverage/mongoose_client_api_rooms_users_doc.COVER.html

1 %%% ==================================================================
2 %%% @doc
3 %%% This module provided documentation of MongooseIM client REST API Rooms: /api/rooms/:id/users/[:user]
4 %%% @end
5 %%% ==================================================================
6
7 -module(mongoose_client_api_rooms_users_doc).
8
9 %%% ==================================================================
10 %%% Macros: HTTP Response Codes
11 %%% ==================================================================
12
13 -define(HTTP_204_NO_CONTENT, 204).
14 -define(HTTP_400_BAD_REQUEST, 400).
15 -define(HTTP_401_UNAUTHORIZED, 401).
16 -define(HTTP_403_FORBIDDEN, 403).
17 -define(HTTP_404_NOT_FOUND, 404).
18 -define(HTTP_500_INTERNAL_SERVER_ERROR, 500).
19
20 %%% ==================================================================
21 %%% Trails Callbacks
22 %%% ==================================================================
23
24 -behaviour(trails_handler).
25
26 -export([trails/0]).
27
28 trails() ->
29 %% Definitions
30 15 DefSetUserRoomReq = <<"req-body-client-api-room-set-users">>,
31
32 %% Properties
33 15 PropRoomParticipantReq = #{
34 <<"user">> => #{
35 type => <<"string">>,
36 description => <<"This is the user's JID (Jabber ID) which consist of username and server parts. Example: alice@wonderland.com">>,
37 default => <<"alice@wonderland.com">>
38 }
39 },
40
41 %% Definitions and properties
42 15 DefinitionsAndProperties = [
43 {DefSetUserRoomReq, PropRoomParticipantReq}
44 ],
45
46 %% Add definitions
47 15 lists:foreach(
48 fun({Definition, DefinitionProperties}) ->
49 15 cowboy_swagger:add_definition(Definition, DefinitionProperties)
50 end, DefinitionsAndProperties),
51
52 %% Request Body
53 15 RequestBodyParticipantRoom = #{
54 in => body,
55 name => <<"room">>,
56 type => <<"object">>,
57 description => <<"Room">>,
58 required => true,
59 schema => cowboy_swagger:schema(DefSetUserRoomReq)
60 },
61
62 %% Pushs
63 15 RequestPushRoomId = #{
64 in => path,
65 name => <<"id">>,
66 type => <<"string">>,
67 description => <<"The ID of a room">>,
68 default => <<"1575-564351-207767">>,
69 required => true
70 },
71
72 15 RequestPushRoomUser = #{
73 in => path,
74 name => <<"user">>,
75 type => <<"string">>,
76 description => <<"The JID (ex: alice@wonderalnd.com) of user to remove">>,
77 default => <<"alice@wonderalnd.com">>,
78 required => true
79 },
80
81 %% Meta data
82 15 MetadataClientApiRoomUsers = #{
83 post => #{
84 tags => ["Rooms"],
85 description => <<"Adds a user to a room">>,
86 consumes => ["application/json"],
87 produces => ["application/json"],
88 parameters => [RequestPushRoomId, RequestBodyParticipantRoom],
89 responses => #{
90 ?HTTP_204_NO_CONTENT => #{description => <<"User was successfully added to the room">>},
91 ?HTTP_400_BAD_REQUEST => #{description => <<"Bad Request">>},
92 ?HTTP_401_UNAUTHORIZED => #{description => <<"Unauthorized">>},
93 ?HTTP_403_FORBIDDEN => #{description => <<"When the authenticated user is not allowed to add users to the room">>},
94 ?HTTP_404_NOT_FOUND => #{description => <<"When there is no room with the given ID">>},
95 ?HTTP_500_INTERNAL_SERVER_ERROR => #{description => <<"Internal Server Error">>}
96 }
97 },
98 delete => #{
99 tags => ["Rooms"],
100 description => <<"Removes a user from the room. The owner can remove any user. The occupant can also use this method, but can only remove themself">>,
101 parameters => [RequestPushRoomId, RequestPushRoomUser],
102 responses => #{
103 ?HTTP_204_NO_CONTENT => #{description => <<"User was successfully added to the room">>},
104 ?HTTP_400_BAD_REQUEST => #{description => <<"Bad Request">>},
105 ?HTTP_401_UNAUTHORIZED => #{description => <<"Unauthorized">>},
106 ?HTTP_403_FORBIDDEN => #{description => <<"When the authenticated user is not allowed to add users to the room">>},
107 ?HTTP_404_NOT_FOUND => #{description => <<"When there is no room with the given ID">>},
108 ?HTTP_500_INTERNAL_SERVER_ERROR => #{description => <<"Internal Server Error">>}
109 }
110 }
111 },
112
113 %% Paths
114 15 PathClientApiRoomsConfig = "/api/rooms/:id/users/[:user]",
115
116 %% Options
117 15 StoreOptions = [
118 {PathClientApiRoomsConfig, #{path => PathClientApiRoomsConfig}, MetadataClientApiRoomUsers, mongoose_client_api_rooms_users}
119 ],
120
121 %% Trail all data
122 15 [trails:trail(Path, Module, Options, Metadata) || {Path, Options, Metadata, Module} <- StoreOptions].
Line Hits Source