|
@@ -8,11 +8,19 @@ handle(Req, _Args) ->
|
|
|
%% Delegate to our handler function
|
|
|
handle(Req#req.method, elli_request:path(Req), Req).
|
|
|
|
|
|
+%% Plaintext test route
|
|
|
+handle('GET', [<<"plaintext">>], _Req) ->
|
|
|
+ %% Reply with a normal response. 'ok' can be used instead of '200'
|
|
|
+ %% to signal success.
|
|
|
+ {ok,[{<<"Content-Type">>, <<"text/plain">>}], <<"Hello, World!">>};
|
|
|
+
|
|
|
+%% Json test route
|
|
|
handle('GET',[<<"json">>], _Req) ->
|
|
|
%% Reply with a normal response. 'ok' can be used instead of '200'
|
|
|
%% to signal success.
|
|
|
{ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode({[{<<"message">>, <<"Hello, World!">>}]})};
|
|
|
|
|
|
+%% db test route (Single Database Query)
|
|
|
handle('GET',[<<"db">>], Req) ->
|
|
|
random:seed(erlang:now()),
|
|
|
JSON = case elli_request:get_arg(<<"queries">>, Req) of
|
|
@@ -27,19 +35,22 @@ handle('GET',[<<"db">>], Req) ->
|
|
|
end,
|
|
|
{ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(lists:nth(1,JSON))};
|
|
|
|
|
|
-handle('GET',[<<"query">>], Req) ->
|
|
|
- random:seed(erlang:now()),
|
|
|
- JSON = case elli_request:get_arg(<<"queries">>, Req) of
|
|
|
- undefined ->
|
|
|
- {result_packet, _, _, [[ID, Rand]], _} = emysql:execute(test_pool, db_stmt, [random:uniform(10000)]),
|
|
|
- [{[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]}];
|
|
|
- N ->
|
|
|
- I = list_to_integer(binary_to_list(N)),
|
|
|
- Res = [ {[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]} ||
|
|
|
- {result_packet, _, _, [[ID, Rand]], _} <- [emysql:execute(test_pool, db_stmt, [random:uniform(10000)]) || _ <- lists:seq(1, I) ]],
|
|
|
- Res
|
|
|
- end,
|
|
|
- {ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(JSON)};
|
|
|
+%% TODO : Finish this function with correct logic.
|
|
|
+%% Please check TFB document
|
|
|
+%% Multiple query test route
|
|
|
+% handle('GET',[<<"query">>], Req) ->
|
|
|
+% random:seed(erlang:now()),
|
|
|
+% JSON = case elli_request:get_arg(<<"queries">>, Req) of
|
|
|
+% undefined ->
|
|
|
+% {result_packet, _, _, [[ID, Rand]], _} = emysql:execute(test_pool, db_stmt, [random:uniform(10000)]),
|
|
|
+% [{[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]}];
|
|
|
+% N ->
|
|
|
+% I = list_to_integer(binary_to_list(N)),
|
|
|
+% Res = [ {[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]} ||
|
|
|
+% {result_packet, _, _, [[ID, Rand]], _} <- [emysql:execute(test_pool, db_stmt, [random:uniform(10000)]) || _ <- lists:seq(1, I) ]],
|
|
|
+% Res
|
|
|
+% end,
|
|
|
+% {ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(JSON)};
|
|
|
|
|
|
handle(_, _, _Req) ->
|
|
|
{404, [], <<"Not Found">>}.
|