Статистика для дашборда #7
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
-export([create/2, get_by_id/1, get_by_event_and_user/2, list_by_event/1, list_by_user/1]).
|
||||
-export([update_status/2, delete/1]).
|
||||
-export([generate_id/0]).
|
||||
-export([count_bookings/0]).
|
||||
|
||||
%% Создание бронирования
|
||||
create(EventId, UserId) ->
|
||||
@@ -97,6 +98,8 @@ delete(Id) ->
|
||||
{aborted, Reason} -> {error, Reason}
|
||||
end.
|
||||
|
||||
count_bookings() -> mnesia:table_info(booking, size).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
-export([create/4, create/5, get_by_id/1, list_by_owner/1, update/2, delete/1]).
|
||||
-export([generate_id/0]).
|
||||
-export([count_calendars/0]).
|
||||
|
||||
%% Создание календаря
|
||||
create(OwnerId, Title, Description, Confirmation) ->
|
||||
@@ -95,6 +96,8 @@ update(Id, Updates) ->
|
||||
delete(Id) ->
|
||||
update(Id, [{status, deleted}]).
|
||||
|
||||
count_calendars() -> mnesia:table_info(calendar, size).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
-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]).
|
||||
|
||||
%% Создание одиночного события
|
||||
create(CalendarId, Title, StartTime, Duration) ->
|
||||
@@ -167,6 +168,9 @@ update(Id, Updates) ->
|
||||
delete(Id) ->
|
||||
update(Id, [{status, deleted}]).
|
||||
|
||||
count_events() ->
|
||||
mnesia:table_info(event, size).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
-export([create/4, get_by_id/1, list_by_target/2, list_by_reporter/1, list_all/0]).
|
||||
-export([update_status/3, get_count_by_target/2]).
|
||||
-export([generate_id/0]).
|
||||
-export([count_reports_by_status/1, count_reports_by_admin/2]).
|
||||
|
||||
%% Создание жалобы
|
||||
create(ReporterId, TargetType, TargetId, Reason) ->
|
||||
@@ -83,6 +84,14 @@ get_count_by_target(TargetType, TargetId) ->
|
||||
Reports = mnesia:dirty_match_object(Match),
|
||||
length(Reports).
|
||||
|
||||
count_reports_by_status(Status) ->
|
||||
Match = #report{status = Status, _ = '_'},
|
||||
length(mnesia:dirty_match_object(Match)).
|
||||
|
||||
count_reports_by_admin(AdminId, Status) ->
|
||||
Match = #report{resolved_by = AdminId, status = Status, _ = '_'},
|
||||
length(mnesia:dirty_match_object(Match)).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
@@ -5,6 +5,7 @@
|
||||
update/2, delete/1, hide/1, unhide/1]).
|
||||
-export([get_average_rating/2, has_user_reviewed/3]).
|
||||
-export([generate_id/0]).
|
||||
-export([count_reviews/0]).
|
||||
|
||||
%% Создание отзыва
|
||||
create(UserId, TargetType, TargetId, Rating, Comment) ->
|
||||
@@ -113,6 +114,8 @@ has_user_reviewed(UserId, TargetType, TargetId) ->
|
||||
_ -> true
|
||||
end.
|
||||
|
||||
count_reviews() -> mnesia:table_info(review, size).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
update_subscription/2,
|
||||
delete_subscription/1
|
||||
]).
|
||||
-export([count_subscription/0]).
|
||||
|
||||
-define(TRIAL_DAYS, 30).
|
||||
|
||||
@@ -214,4 +215,6 @@ apply_updates(Sub, Updates) ->
|
||||
Acc#subscription{expires_at = Value, updated_at = calendar:universal_time()};
|
||||
_ -> Acc
|
||||
end
|
||||
end, Sub, maps:to_list(Updates)).
|
||||
end, Sub, maps:to_list(Updates)).
|
||||
|
||||
count_subscription() -> mnesia:table_info(subscription, size).
|
||||
@@ -7,6 +7,7 @@
|
||||
stats/0,
|
||||
create_ticket/1,
|
||||
list_by_user/1]).
|
||||
-export([count_tickets_by_status/1, count_tickets_by_admin/2]).
|
||||
|
||||
list_all() ->
|
||||
mnesia:dirty_match_object(#ticket{_ = '_'}).
|
||||
@@ -83,4 +84,12 @@ apply_updates(Ticket, Updates) ->
|
||||
end, Ticket, maps:to_list(Updates)).
|
||||
|
||||
count_by_status(Status, Tickets) ->
|
||||
length([T || T <- Tickets, T#ticket.status =:= Status]).
|
||||
length([T || T <- Tickets, T#ticket.status =:= Status]).
|
||||
|
||||
count_tickets_by_status(Status) ->
|
||||
Match = #ticket{status = Status, _ = '_'},
|
||||
length(mnesia:dirty_match_object(Match)).
|
||||
|
||||
count_tickets_by_admin(AdminId, Status) ->
|
||||
Match = #ticket{assigned_to = AdminId, status = Status, _ = '_'},
|
||||
length(mnesia:dirty_match_object(Match)).
|
||||
@@ -6,6 +6,7 @@
|
||||
-export([generate_id/0]).
|
||||
-export([list_users/0]).
|
||||
-export([block/1, unblock/1]).
|
||||
-export([count_users/0]).
|
||||
|
||||
%% Создание пользователя
|
||||
create(Email, Password) ->
|
||||
@@ -122,6 +123,9 @@ unblock(Id) ->
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
count_users() ->
|
||||
mnesia:table_info(user, size).
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
Reference in New Issue
Block a user