feat: booking JSON user_nickname/email for owner UI. Refs EventHub/EventHubBack#56
CI / test (push) Successful in 7m4s
CI / deploy-ift (push) Successful in 2m29s
CI / e2e-ift (push) Successful in 1m26s
CI / deploy-stage (push) Successful in 2m22s
CI / e2e-stage (push) Successful in 1m13s

This commit is contained in:
2026-07-23 13:20:33 +03:00
parent 571f04737d
commit e3013075cc
4 changed files with 42 additions and 42 deletions
+1 -14
View File
@@ -181,17 +181,4 @@ cancel_booking(Req) ->
%% Учитывает все поля из records.hrl.
-spec booking_to_json(#booking{}) -> map().
booking_to_json(Booking) ->
#{
id => Booking#booking.id,
event_id => Booking#booking.event_id,
user_id => Booking#booking.user_id,
status => Booking#booking.status,
notes => Booking#booking.notes,
reminder_sent => Booking#booking.reminder_sent,
confirmed_at => case Booking#booking.confirmed_at of
undefined -> null;
Dt -> handler_utils:datetime_to_iso8601(Dt)
end,
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
}.
handler_utils:booking_to_json(Booking).
+1 -14
View File
@@ -167,17 +167,4 @@ list_bookings(Req) ->
%% @private Формирует JSON-представление записи #booking{}.
-spec booking_to_json(#booking{}) -> map().
booking_to_json(Booking) ->
#{
id => Booking#booking.id,
event_id => Booking#booking.event_id,
user_id => Booking#booking.user_id,
status => Booking#booking.status,
notes => Booking#booking.notes,
reminder_sent => Booking#booking.reminder_sent,
confirmed_at => case Booking#booking.confirmed_at of
undefined -> null;
Dt -> handler_utils:datetime_to_iso8601(Dt)
end,
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
}.
handler_utils:booking_to_json(Booking).
+1 -14
View File
@@ -89,17 +89,4 @@ list_user_bookings(Req) ->
%% @private Формирует JSON-представление записи #booking{}.
-spec booking_to_json(#booking{}) -> map().
booking_to_json(Booking) ->
#{
id => Booking#booking.id,
event_id => Booking#booking.event_id,
user_id => Booking#booking.user_id,
status => Booking#booking.status,
notes => Booking#booking.notes,
reminder_sent => Booking#booking.reminder_sent,
confirmed_at => case Booking#booking.confirmed_at of
undefined -> null;
Dt -> handler_utils:datetime_to_iso8601(Dt)
end,
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
}.
handler_utils:booking_to_json(Booking).
+39
View File
@@ -26,6 +26,7 @@
ticket_to_json/1,
calendar_to_json/1,
subscription_to_json/1,
booking_to_json/1,
trails_for_crud/4,
is_superadmin/1,
pagination_headers/2,
@@ -473,6 +474,44 @@ subscription_to_json(Subscription) ->
updated_at => datetime_to_iso8601(Subscription#subscription.updated_at)
}.
%% @doc Booking JSON with optional booker nickname/email for owner UI.
-spec booking_to_json(#booking{}) -> map().
booking_to_json(Booking) ->
Base = #{
id => Booking#booking.id,
event_id => Booking#booking.event_id,
user_id => Booking#booking.user_id,
status => Booking#booking.status,
notes => Booking#booking.notes,
reminder_sent => Booking#booking.reminder_sent,
confirmed_at => case Booking#booking.confirmed_at of
undefined -> null;
Dt -> datetime_to_iso8601(Dt)
end,
created_at => datetime_to_iso8601(Booking#booking.created_at),
updated_at => datetime_to_iso8601(Booking#booking.updated_at)
},
maps:merge(Base, booking_user_fields(Booking#booking.user_id)).
%% @private
booking_user_fields(UserId) when is_binary(UserId) ->
case core_user:get_by_id(UserId) of
{ok, #user{nickname = Nick, email = Email}} ->
#{
user_nickname => empty_to_null(Nick),
user_email => empty_to_null(Email)
};
_ ->
#{user_nickname => null, user_email => null}
end;
booking_user_fields(_) ->
#{user_nickname => null, user_email => null}.
empty_to_null(undefined) -> null;
empty_to_null(null) -> null;
empty_to_null(<<>>) -> null;
empty_to_null(V) -> V.
%%%===================================================================
%%% Вспомогательные внутренние функции
%%%===================================================================