Stage 10 final
This commit is contained in:
+13
-11
@@ -28,6 +28,7 @@ create_booking(UserId, EventId) ->
|
||||
case core_booking:create(ActualEventId, UserId) of
|
||||
{ok, Booking} ->
|
||||
handle_confirmation_policy(Booking, Event, Calendar),
|
||||
logic_notification:notify_booking(UserId, Booking), % ← Уведомление
|
||||
{ok, Booking};
|
||||
Error ->
|
||||
Error
|
||||
@@ -63,23 +64,24 @@ confirm_booking(UserId, BookingId, Action) when Action =:= confirm; Action =:= d
|
||||
{ok, Calendar} ->
|
||||
case logic_calendar:can_edit(UserId, Calendar) of
|
||||
true ->
|
||||
case Action of
|
||||
confirm ->
|
||||
core_booking:update_status(BookingId, confirmed);
|
||||
decline ->
|
||||
core_booking:update_status(BookingId, cancelled)
|
||||
NewStatus = case Action of
|
||||
confirm -> confirmed;
|
||||
decline -> cancelled
|
||||
end,
|
||||
case core_booking:update_status(BookingId, NewStatus) of
|
||||
{ok, Updated} ->
|
||||
logic_notification:notify_booking(Updated#booking.user_id, Updated),
|
||||
{ok, Updated};
|
||||
Error -> Error
|
||||
end;
|
||||
false ->
|
||||
{error, access_denied}
|
||||
end;
|
||||
Error ->
|
||||
Error
|
||||
Error -> Error
|
||||
end;
|
||||
Error ->
|
||||
Error
|
||||
Error -> Error
|
||||
end;
|
||||
Error ->
|
||||
Error
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
%% Отмена бронирования (участником)
|
||||
|
||||
@@ -16,6 +16,12 @@ create_report(ReporterId, TargetType, TargetId, Reason) ->
|
||||
true ->
|
||||
case core_report:create(ReporterId, TargetType, TargetId, Reason) of
|
||||
{ok, Report} ->
|
||||
logic_notification:notify_admin(report_created, #{
|
||||
report_id => Report#report.id,
|
||||
target_type => TargetType,
|
||||
target_id => TargetId,
|
||||
reason => Reason
|
||||
}),
|
||||
% Проверяем порог для авто-модерации
|
||||
check_auto_freeze(TargetType, TargetId),
|
||||
{ok, Report};
|
||||
@@ -116,7 +122,7 @@ freeze_calendar(AdminId, CalendarId) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_calendar:get_by_id(CalendarId) of
|
||||
{ok, Calendar} ->
|
||||
{ok, _Calendar} ->
|
||||
core_calendar:update(CalendarId, [{status, frozen}]);
|
||||
Error -> Error
|
||||
end;
|
||||
@@ -128,7 +134,7 @@ unfreeze_calendar(AdminId, CalendarId) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_calendar:get_by_id(CalendarId) of
|
||||
{ok, Calendar} ->
|
||||
{ok, _Calendar} ->
|
||||
core_calendar:update(CalendarId, [{status, active}]);
|
||||
Error -> Error
|
||||
end;
|
||||
@@ -140,7 +146,7 @@ freeze_event(AdminId, EventId) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_event:get_by_id(EventId) of
|
||||
{ok, Event} ->
|
||||
{ok, _Event} ->
|
||||
core_event:update(EventId, [{status, frozen}]);
|
||||
Error -> Error
|
||||
end;
|
||||
@@ -152,7 +158,7 @@ unfreeze_event(AdminId, EventId) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_event:get_by_id(EventId) of
|
||||
{ok, Event} ->
|
||||
{ok, _Event} ->
|
||||
core_event:update(EventId, [{status, active}]);
|
||||
Error -> Error
|
||||
end;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
-module(logic_notification).
|
||||
-include("records.hrl").
|
||||
|
||||
-export([notify_booking/2]).
|
||||
-export([notify_calendar_update/1]).
|
||||
-export([notify_event_update/1]).
|
||||
-export([notify_admin/2]).
|
||||
|
||||
%% Уведомление о бронировании
|
||||
notify_booking(UserId, Booking) ->
|
||||
Data = #{
|
||||
booking_id => Booking#booking.id,
|
||||
event_id => Booking#booking.event_id,
|
||||
status => Booking#booking.status
|
||||
},
|
||||
broadcast_to_user(UserId, booking_update, Data).
|
||||
|
||||
%% Уведомление об обновлении календаря
|
||||
notify_calendar_update(Calendar) ->
|
||||
Data = #{
|
||||
calendar_id => Calendar#calendar.id,
|
||||
title => Calendar#calendar.title,
|
||||
status => Calendar#calendar.status
|
||||
},
|
||||
broadcast_to_calendar_subscribers(Calendar#calendar.id, calendar_update, Data).
|
||||
|
||||
%% Уведомление об обновлении события
|
||||
notify_event_update(Event) ->
|
||||
Data = #{
|
||||
event_id => Event#event.id,
|
||||
calendar_id => Event#event.calendar_id,
|
||||
title => Event#event.title,
|
||||
status => Event#event.status,
|
||||
start_time => Event#event.start_time
|
||||
},
|
||||
broadcast_to_calendar_subscribers(Event#event.calendar_id, event_update, Data).
|
||||
|
||||
%% Уведомление для администраторов
|
||||
notify_admin(Type, Data) ->
|
||||
Message = {admin_notification, Type, Data},
|
||||
% Отправляем всем админам
|
||||
[Pid ! Message || Pid <- pg:get_members(eventhub_admin_ws)],
|
||||
% Также отправляем в каналы
|
||||
[Pid ! Message || Pid <- pg:get_members({eventhub_admin_channel, Type})],
|
||||
ok.
|
||||
|
||||
%% Внутренние функции
|
||||
broadcast_to_user(UserId, Type, Data) ->
|
||||
Message = {notification, Type, Data#{user_id => UserId}},
|
||||
[Pid ! Message || Pid <- pg:get_members(eventhub_ws)].
|
||||
|
||||
broadcast_to_calendar_subscribers(_CalendarId, _Type, _Data) ->
|
||||
% В будущем можно фильтровать по подпискам
|
||||
% Сейчас отправляем всем подключённым пользователям
|
||||
Message = {notification, calendar_update, _Data},
|
||||
[Pid ! Message || Pid <- pg:get_members(eventhub_ws)].
|
||||
@@ -60,7 +60,7 @@ cancel_subscription(AdminId, SubscriptionId) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_subscription:get_by_id(SubscriptionId) of
|
||||
{ok, Subscription} ->
|
||||
{ok, _Subscription} ->
|
||||
core_subscription:update_status(SubscriptionId, cancelled);
|
||||
Error -> Error
|
||||
end;
|
||||
|
||||
@@ -58,7 +58,7 @@ resolve_ticket(AdminId, TicketId, ResolutionNote) ->
|
||||
case is_admin(AdminId) of
|
||||
true ->
|
||||
case core_ticket:add_resolution(TicketId, ResolutionNote) of
|
||||
{ok, Ticket} ->
|
||||
{ok, _Ticket} ->
|
||||
core_ticket:update_status(TicketId, resolved);
|
||||
Error -> Error
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user