feat(booking): studio journal and instance inbox. Refs EventHub/EventHubFront#60
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
-export([init/2]).
|
||||
-export([trails/0]).
|
||||
-export([item_to_json/1]).
|
||||
|
||||
-include("records.hrl").
|
||||
|
||||
@@ -76,7 +77,7 @@ list_requests(Req) ->
|
||||
{ok, UserId, Req1} ->
|
||||
case logic_booking:list_user_booking_requests(UserId) of
|
||||
{ok, Items} ->
|
||||
Response = [request_to_json(I) || I <- Items],
|
||||
Response = [item_to_json(I) || I <- Items],
|
||||
handler_utils:send_json(Req1, 200, Response);
|
||||
{error, _} ->
|
||||
handler_utils:send_error(Req1, 500, <<"Internal server error">>)
|
||||
@@ -85,8 +86,8 @@ list_requests(Req) ->
|
||||
handler_utils:send_error(Req1, Code, Message)
|
||||
end.
|
||||
|
||||
-spec request_to_json({#booking{}, #event{}, owner | specialist}) -> map().
|
||||
request_to_json({Booking, Event, Role}) ->
|
||||
-spec item_to_json({#booking{}, #event{}, owner | specialist}) -> map().
|
||||
item_to_json({Booking, Event, Role}) ->
|
||||
CalendarTitle = case core_calendar:get_by_id(Event#event.calendar_id) of
|
||||
{ok, Cal} -> Cal#calendar.title;
|
||||
_ -> null
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @doc Confirmed + pending bookings on calendars the user owns or staffs.
|
||||
%%% GET /v1/user/studio-bookings
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(handler_user_studio_bookings).
|
||||
-behaviour(cowboy_handler).
|
||||
|
||||
-export([init/2]).
|
||||
-export([trails/0]).
|
||||
|
||||
-include("records.hrl").
|
||||
|
||||
-spec init(cowboy_req:req(), any()) -> {ok, cowboy_req:req(), any()}.
|
||||
init(Req, Opts) ->
|
||||
handle(Req, Opts).
|
||||
|
||||
-spec trails() -> [map()].
|
||||
trails() ->
|
||||
[
|
||||
#{
|
||||
path => <<"/v1/user/studio-bookings">>,
|
||||
method => <<"GET">>,
|
||||
description => <<"Pending and confirmed bookings on owned/staffed calendars">>,
|
||||
tags => [<<"Bookings">>],
|
||||
responses => #{
|
||||
200 => #{
|
||||
description => <<"Array of enriched studio bookings">>,
|
||||
content => #{<<"application/json">> => #{schema => #{
|
||||
type => array,
|
||||
items => #{type => object}
|
||||
}}}
|
||||
},
|
||||
401 => #{description => <<"Unauthorized">>}
|
||||
}
|
||||
}
|
||||
].
|
||||
|
||||
-spec handle(cowboy_req:req(), any()) -> {ok, cowboy_req:req(), any()}.
|
||||
handle(Req, _Opts) ->
|
||||
case cowboy_req:method(Req) of
|
||||
<<"GET">> -> list_studio(Req);
|
||||
_ -> handler_utils:send_error(Req, 405, <<"Method not allowed">>)
|
||||
end.
|
||||
|
||||
-spec list_studio(cowboy_req:req()) -> {ok, cowboy_req:req(), any()}.
|
||||
list_studio(Req) ->
|
||||
case handler_utils:auth_user(Req) of
|
||||
{ok, UserId, Req1} ->
|
||||
case logic_booking:list_user_studio_bookings(UserId) of
|
||||
{ok, Items} ->
|
||||
Response = [handler_user_booking_requests:item_to_json(I) || I <- Items],
|
||||
handler_utils:send_json(Req1, 200, Response);
|
||||
{error, _} ->
|
||||
handler_utils:send_error(Req1, 500, <<"Internal server error">>)
|
||||
end;
|
||||
{error, Code, Message, Req1} ->
|
||||
handler_utils:send_error(Req1, Code, Message)
|
||||
end.
|
||||
Reference in New Issue
Block a user