This commit is contained in:
2026-04-20 21:04:16 +03:00
parent b24cbc97f3
commit 19f82768e4
18 changed files with 1851 additions and 131 deletions

View File

@@ -24,9 +24,16 @@ create_calendar(Req) ->
#{<<"title">> := Title} ->
Description = maps:get(<<"description">>, Decoded, <<"">>),
Confirmation = parse_confirmation(maps:get(<<"confirmation">>, Decoded, <<"manual">>)),
Tags = maps:get(<<"tags">>, Decoded, []),
Type = parse_type(maps:get(<<"type">>, Decoded, <<"personal">>)),
case logic_calendar:create_calendar(UserId, Title, Description, Confirmation) of
{ok, Calendar} ->
Response = calendar_to_json(Calendar),
% Обновляем теги и тип
Updates = [{tags, Tags}, {type, Type}],
core_calendar:update(Calendar#calendar.id, Updates),
{ok, Updated} = core_calendar:get_by_id(Calendar#calendar.id),
Response = calendar_to_json(Updated),
send_json(Req2, 201, Response);
{error, user_inactive} ->
send_error(Req2, 403, <<"User account is not active">>);
@@ -51,6 +58,10 @@ parse_confirmation(<<"manual">>) -> manual;
parse_confirmation(#{<<"timeout">> := N}) when is_integer(N), N > 0 -> {timeout, N};
parse_confirmation(_) -> manual.
parse_type(<<"personal">>) -> personal;
parse_type(<<"commercial">>) -> commercial;
parse_type(_) -> personal.
%% GET /v1/calendars - список календарей
list_calendars(Req) ->
case handler_auth:authenticate(Req) of