При массовом изменении статуса отзывов причина теперь обязательное поле #22
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @doc Административный обработчик отзывов.
|
||||
%%% GET – список отзывов с пагинацией, фильтрацией и сортировкой.
|
||||
%%% PATCH – массовое обновление статусов отзывов.
|
||||
%%% PATCH – массовое обновление статусов отзывов с единой причиной.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(admin_handler_reviews).
|
||||
@@ -43,14 +43,31 @@ trails() ->
|
||||
#{ % PATCH bulk update
|
||||
path => <<"/v1/admin/reviews">>,
|
||||
method => <<"PATCH">>,
|
||||
description => <<"Bulk update review statuses">>,
|
||||
description => <<"Bulk update review statuses with a single reason">>,
|
||||
tags => [<<"Reviews">>],
|
||||
requestBody => #{
|
||||
required => true,
|
||||
content => #{<<"application/json">> => #{schema => #{ type => array, items => #{ type => object, properties => #{ id => #{type => string}, status => #{type => string, enum => [<<"visible">>, <<"hidden">>, <<"deleted">>]} } }}} }
|
||||
content => #{<<"application/json">> => #{schema => #{
|
||||
type => object,
|
||||
required => [<<"operations">>, <<"reason">>],
|
||||
properties => #{
|
||||
<<"operations">> => #{
|
||||
type => array,
|
||||
items => #{
|
||||
type => object,
|
||||
properties => #{
|
||||
<<"id">> => #{type => string},
|
||||
<<"status">> => #{type => string, enum => [<<"visible">>, <<"hidden">>, <<"deleted">>]}
|
||||
}
|
||||
}
|
||||
},
|
||||
<<"reason">> => #{type => string, description => <<"Reason applied to all updates">>}
|
||||
}
|
||||
}}}
|
||||
},
|
||||
responses => #{
|
||||
200 => #{description => <<"Number of updated reviews">>}
|
||||
200 => #{description => <<"Number of updated reviews">>},
|
||||
400 => #{description => <<"Invalid request body or missing reason">>}
|
||||
}
|
||||
}
|
||||
].
|
||||
@@ -111,16 +128,18 @@ bulk_update_reviews(Req) ->
|
||||
{ok, AdminId, Req1} ->
|
||||
try
|
||||
{ok, Body, Req2} = cowboy_req:read_body(Req1),
|
||||
Operations = jsx:decode(Body, [return_maps]),
|
||||
#{<<"operations">> := Operations, <<"reason">> := Reason} = jsx:decode(Body, [return_maps]),
|
||||
true = is_list(Operations),
|
||||
case logic_review:bulk_update_status(Operations) of
|
||||
case logic_review:bulk_update_status(Operations, Reason) of
|
||||
{ok, UpdatedCount} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"bulk_update_reviews">>, <<"review">>, UpdatedCount, Req2),
|
||||
handler_utils:send_json(Req2, 200, #{updated_count => UpdatedCount});
|
||||
{error, Reason} ->
|
||||
handler_utils:send_error(Req2, 400, Reason)
|
||||
{error, ReasonErr} ->
|
||||
handler_utils:send_error(Req2, 400, ReasonErr)
|
||||
end
|
||||
catch
|
||||
error:{badmatch, _} ->
|
||||
handler_utils:send_error(Req1, 400, <<"Missing 'reason' field">>);
|
||||
_:_ -> handler_utils:send_error(Req1, 400, <<"Invalid JSON body">>)
|
||||
end;
|
||||
{error, Code, Msg, Req1} ->
|
||||
|
||||
Reference in New Issue
Block a user