/__w/shurbej/shurbej/_build/test/cover/ct/shurbej_http_deleted.html

1 -module(shurbej_http_deleted).
2 -export([init/2]).
3
4 init(Req0, State) ->
5 8 case cowboy_req:method(Req0) of
6 <<"GET">> ->
7 7 case shurbej_http_common:authorize(Req0) of
8 {ok, LibRef, _} ->
9 6 case shurbej_http_common:check_lib_perm(read, LibRef) of
10 6 ok -> handle_get(Req0, State);
11 {error, forbidden} ->
12
:-(
Req = shurbej_http_common:error_response(403,
13 <<"Access denied">>, Req0),
14
:-(
{ok, Req, State}
15 end;
16 {error, Reason, _} ->
17 1 Req = shurbej_http_common:auth_error_response(Reason, Req0),
18 1 {ok, Req, State}
19 end;
20 _ ->
21 1 Req = shurbej_http_common:error_response(405, <<"Method not allowed">>, Req0),
22 1 {ok, Req, State}
23 end.
24
25 handle_get(Req0, State) ->
26 6 LibRef = shurbej_http_common:lib_ref(Req0),
27 6 {ok, LibVersion} = shurbej_version:get(LibRef),
28 6 case shurbej_http_common:check_304(Req0, LibVersion) of
29 1 {304, Req} -> {ok, Req, State};
30 continue ->
31 5 Since = shurbej_http_common:get_since(Req0),
32 5 Result = #{
33 <<"collections">> => shurbej_db:list_deleted(LibRef, <<"collection">>, Since),
34 <<"items">> => shurbej_db:list_deleted(LibRef, <<"item">>, Since),
35 <<"searches">> => shurbej_db:list_deleted(LibRef, <<"search">>, Since),
36 <<"tags">> => shurbej_db:list_deleted(LibRef, <<"tag">>, Since),
37 <<"settings">> => shurbej_db:list_deleted(LibRef, <<"setting">>, Since)
38 },
39 5 Req = shurbej_http_common:json_response(200, Result, LibVersion, Req0),
40 5 {ok, Req, State}
41 end.
Line Hits Source