File tree Expand file tree Collapse file tree 1 file changed +44
-1
lines changed
Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,47 @@ C++ Implementation for JsonRPC 2.0
77## Features
88
99* Collect all handlers for jsonrpc20
10- * Including system of define validators
10+ * Including system of define validators
11+ *
12+
13+
14+ ## Example
15+
16+ ``` cpp
17+
18+ // method: order_remove or remove_order
19+
20+ MethodJsonRpc20_OrderRemove::MethodJsonRpc20_OrderRemove ()
21+ : WsjcppJsonRpc20Base({"order_remove", "remove_order"}, "Remove order by id") {
22+
23+ // restriction for different roles
24+ setAccessUnauthorized(false); // this define "false" says that UserSession will be not nullptr
25+ setAccessUser(true);
26+ setAccessAdmin(true);
27+
28+ // just information for documentation
29+ setActivatedFromVersion("0.2.32");
30+
31+ // validation and description input fields
32+ requireIntegerParam("id", "Id of user");
33+ }
34+
35+ void MethodJsonRpc20_OrderRemove::handle(ModelRequest * pRequest) {
36+ WsjcppUserSession * pUserSession = pRequest->getUserSession();
37+
38+ int nId = pRequest->getInputInteger("id", -1);
39+
40+ // find id in database if not then return NOT_FOUND
41+
42+ if (nId == -1) {
43+ pRequest->fail(404, "NOT_FOUND");
44+ return;
45+ }
46+
47+ // do remove order here
48+
49+ nlohmann::json jsonResponse;
50+ pRequest->done(jsonResponse);
51+ }
52+
53+ ```
You can’t perform that action at this time.
0 commit comments