Рефакторинг обработчиков. Часть 1 #21

This commit is contained in:
2026-05-10 22:14:38 +03:00
parent a35d6f7acc
commit 6403f061df
46 changed files with 3082 additions and 2091 deletions

View File

@@ -1,18 +1,36 @@
-module(admin_handler_health).
-behaviour(cowboy_handler).
-export([init/2]).
init(Req, State) ->
-export([init/2]).
-export([trails/0]).
%%% cowboy_handler callback
init(Req, _State) ->
case cowboy_req:method(Req) of
<<"GET">> ->
Body = jsx:encode(#{status => <<"ok">>}),
Req2 = cowboy_req:reply(200, #{<<"content-type">> => <<"application/json">>}, Body, Req),
{ok, Req2, State};
handler_utils:send_json(Req, 200, #{status => <<"ok">>});
_ ->
send_error(Req, 405, <<"Method not allowed">>)
handler_utils:send_error(Req, 405, <<"Method not allowed">>)
end.
send_error(Req, Status, Message) ->
Body = jsx:encode(#{error => Message}),
Req2 = cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
{ok, Req2, []}.
%%% Swagger metadata
trails() ->
[
#{
path => <<"/v1/admin/health">>,
method => <<"GET">>,
description => <<"Admin API health check">>,
tags => [<<"Health">>],
responses => #{
200 => #{
description => <<"API is healthy">>,
content => #{<<"application/json">> => #{schema => #{
type => object,
properties => #{
status => #{type => string}
}
}}}
}
}
}
].