Рефакторинг обработчиков. Часть 1 #21
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
|
||||
-export([create/4, create_recurring/5, get_by_id/1, list_by_calendar/1,
|
||||
update/2, delete/1, materialize_occurrence/3]).
|
||||
-export([generate_id/0]).
|
||||
-export([count_events/0, count_events_by_date/2]).
|
||||
-export([freeze/2, unfreeze/2]).
|
||||
-export([list_all/0]).
|
||||
|
||||
%% Создание одиночного события
|
||||
create(CalendarId, Title, StartTime, Duration) ->
|
||||
Id = generate_id(),
|
||||
Id = infra_utils:generate_id(16),
|
||||
Event = #event{
|
||||
id = Id,
|
||||
calendar_id = CalendarId,
|
||||
@@ -46,7 +45,7 @@ create(CalendarId, Title, StartTime, Duration) ->
|
||||
|
||||
%% Создание повторяющегося события (мастер-запись)
|
||||
create_recurring(CalendarId, Title, StartTime, Duration, RRule) ->
|
||||
Id = generate_id(),
|
||||
Id = infra_utils:generate_id(16),
|
||||
Event = #event{
|
||||
id = Id,
|
||||
calendar_id = CalendarId,
|
||||
@@ -94,7 +93,7 @@ materialize_occurrence(MasterId, OccurrenceStart, SpecialistId) ->
|
||||
case Existing of
|
||||
[] ->
|
||||
% Создаём новый экземпляр
|
||||
InstanceId = generate_id(),
|
||||
InstanceId = infra_utils:generate_id(16),
|
||||
Instance = #event{
|
||||
id = InstanceId,
|
||||
calendar_id = Master#event.calendar_id,
|
||||
@@ -193,10 +192,6 @@ count_events_by_date(From, To) ->
|
||||
|
||||
date_part({{Y,M,D}, _}) -> {Y,M,D}.
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
apply_updates(Event, Updates) ->
|
||||
Updated = lists:foldl(fun({Field, Value}, E) ->
|
||||
set_field(Field, Value, E)
|
||||
|
||||
Reference in New Issue
Block a user