feat(booking): materialize occurrence on POST bookings. Refs EventHub/EventHubBack#67

This commit is contained in:
2026-08-14 10:52:24 +03:00
parent e3403f6ed6
commit 8a5f254c2a
5 changed files with 220 additions and 35 deletions
+23 -1
View File
@@ -4,7 +4,7 @@
-export([create_event/5, create_event/6, create_recurring_event/6, create_recurring_event/7,
get_event/2, list_events/2, update_event/3, delete_event/2]).
-export([validate_event_time/1, validate_event_time/2, get_occurrences/3, cancel_occurrence/3]).
-export([materialize_for_booking/3]).
-export([materialize_for_booking/3, validate_occurrence/2]).
-export([list_all_events/1, get_event_admin/1, update_event_admin/2, delete_event_admin/1]).
-export([search_events/1]).
@@ -147,6 +147,28 @@ cancel_occurrence(UserId, MasterId, OccurrenceStart) ->
materialize_for_booking(MasterId, OccurrenceStart, SpecialistId) ->
core_event:materialize_occurrence(MasterId, OccurrenceStart, SpecialistId).
%% Проверка, что OccurrenceStart — неотменённое вхождение серии.
validate_occurrence(#event{event_type = recurring} = Event, OccurrenceStart) ->
try
Decoded = jsx:decode(Event#event.recurrence_rule, [return_maps]),
RRuleMap = case Decoded of
Map when is_map(Map) -> Map;
_ -> #{}
end,
{ok, ParsedRule} = logic_recurrence:parse_rrule(RRuleMap),
Occurrences = logic_recurrence:generate_occurrences(
Event#event.start_time, ParsedRule, OccurrenceStart),
Valid = filter_cancelled(Occurrences, get_exceptions(Event#event.id)),
case lists:member(OccurrenceStart, Valid) of
true -> ok;
false -> {error, invalid_occurrence}
end
catch
_:_ -> {error, invalid_occurrence}
end;
validate_occurrence(_, _) ->
{error, not_recurring}.
%% Получение события с проверкой доступа
get_event(UserId, EventId) ->
case core_event:get_by_id(EventId) of