aboutsummaryrefslogtreecommitdiff
path: root/apps/dreki_web/src/dreki_web_admin_tasks.erl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dreki_web/src/dreki_web_admin_tasks.erl')
-rw-r--r--apps/dreki_web/src/dreki_web_admin_tasks.erl30
1 files changed, 30 insertions, 0 deletions
diff --git a/apps/dreki_web/src/dreki_web_admin_tasks.erl b/apps/dreki_web/src/dreki_web_admin_tasks.erl
new file mode 100644
index 0000000..adc2689
--- /dev/null
+++ b/apps/dreki_web/src/dreki_web_admin_tasks.erl
@@ -0,0 +1,30 @@
+-module(dreki_web_admin_tasks).
+-behaviour(cowboy_rest).
+-export([init/2]).
+-export([allowed_methods/2]).
+-export([content_types_accepted/2]).
+-export([content_types_provided/2]).
+
+init(Req, State) ->
+ {cowboy_rest, Req, State}.
+
+allowed_methods(Req, State) ->
+ {[<<"GET">>, <<"HEAD">>, <<"OPTIONS">>, <<"POST">>], Req, State}.
+
+content_types_accepted(Req, State) ->
+ dreki_web:content_types_accepted(Req, State).
+
+content_types_provided(Req, State) ->
+ dreki_web:content_types_provided(Req, State).
+
+list(Req, State, Format) ->
+ {ok, Db} = dreki_tasks:open(),
+ {ok, Tasks} = dreki_tasks:all(Db),
+ MTasks = lists:foldl(fun (T, Acc) -> [dreki_task:to_map(T) | Acc] end, [], Tasks),
+ dreki_web:reply(Req, 200, #{error => false, tasks => MTasks}, [], Format).
+
+to_json(Req, State) ->
+ list(Req, State, json).
+
+to_yaml(Req, State) ->
+ list(Req, State, yaml).