Skip to content

Commit

Permalink
fix: CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Apr 8, 2024
1 parent 253e621 commit d2de063
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/atomic/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ defmodule Atomic.Activities do
"""
def create_activity_with_post(attrs \\ %{}, after_save \\ &{:ok, &1}) do
case RateLimiter.limit_activities(attrs["organization_id"]) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_activities(attrs["organization_id"]) do
:ok ->
Multi.new()
|> Multi.insert(:post, fn _ ->
Expand Down Expand Up @@ -224,7 +225,8 @@ defmodule Atomic.Activities do
end

def create_activity(attrs \\ %{}) do
case RateLimiter.limit_activities(attrs["organization_id"]) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_activities(attrs["organization_id"]) do
:ok ->
%Activity{}
|> Activity.changeset(attrs)
Expand Down
6 changes: 4 additions & 2 deletions lib/atomic/organizations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ defmodule Atomic.Organizations do
"""
def create_announcement_with_post(attrs \\ %{}) do
case RateLimiter.limit_announcements(attrs["organization_id"]) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_announcements(attrs["organization_id"]) do
:ok ->
Multi.new()
|> Multi.insert(:post, fn _ ->
Expand Down Expand Up @@ -761,7 +762,8 @@ defmodule Atomic.Organizations do
end

def create_announcement(attrs \\ %{}) do
case RateLimiter.limit_announcements(attrs["organization_id"]) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_announcements(attrs["organization_id"]) do
:ok ->
%Announcement{}
|> Announcement.changeset(attrs)
Expand Down
6 changes: 3 additions & 3 deletions lib/atomic/rate_limiter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule Atomic.RateLimiter do
Rate limiter module for Atomic.
"""
use Atomic.Context
alias Atomic.Organizations.Announcement
alias Atomic.Activities.Activity
alias Atomic.Organizations.Announcement
alias Atomic.Repo
@activities_limit_per_day Application.compile_env!(:atomic, :activities_limit_per_day)
@announcements_limit_per_day Application.compile_env!(:atomic, :announcements_limit_per_day)
Expand All @@ -22,7 +22,7 @@ defmodule Atomic.RateLimiter do
"""
def limit_activities(organization_id) do
current_time = DateTime.utc_now()
twenty_four_hours_ago = DateTime.add(current_time, -86400)
twenty_four_hours_ago = DateTime.add(current_time, -86_400)

activity_count =
Repo.all(
Expand Down Expand Up @@ -52,7 +52,7 @@ defmodule Atomic.RateLimiter do
"""
def limit_announcements(organization_id) do
current_time = DateTime.utc_now()
twenty_four_hours_ago = DateTime.add(current_time, -86400)
twenty_four_hours_ago = DateTime.add(current_time, -86_400)

announcement_count =
Repo.all(
Expand Down

0 comments on commit d2de063

Please sign in to comment.