Skip to content

Commit

Permalink
fix: CD
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Apr 8, 2024
1 parent d2de063 commit f716aa5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
15 changes: 11 additions & 4 deletions lib/atomic/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Atomic.Activities do
alias Atomic.Activities.ActivityEnrollment
alias Atomic.Activities.Speaker
alias Atomic.Feed.Post
alias Atomic.Organizations
alias Atomic.RateLimiter

@doc """
Expand Down Expand Up @@ -195,8 +196,8 @@ defmodule Atomic.Activities do
"""
def create_activity_with_post(attrs \\ %{}, after_save \\ &{:ok, &1}) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_activities(attrs["organization_id"]) do
case Organizations.verify_organization_id?(attrs) and
RateLimiter.limit_activities(Map.get(attrs, :organization_id)) do
:ok ->
Multi.new()
|> Multi.insert(:post, fn _ ->
Expand All @@ -221,19 +222,25 @@ defmodule Atomic.Activities do

{:error, reason} ->
{:error, reason}

false ->
{:error, "Organization ID is required."}
end
end

def create_activity(attrs \\ %{}) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_activities(attrs["organization_id"]) do
case Organizations.verify_organization_id?(attrs) and
RateLimiter.limit_activities(Map.get(attrs, :organization_id)) do
:ok ->
%Activity{}
|> Activity.changeset(attrs)
|> Repo.insert()

{:error, reason} ->
{:error, reason}

false ->
{:error, "Organization ID is required."}
end
end

Expand Down
20 changes: 16 additions & 4 deletions lib/atomic/organizations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ defmodule Atomic.Organizations do
"""
def create_announcement_with_post(attrs \\ %{}) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_announcements(attrs["organization_id"]) do
case verify_organization_id?(attrs) and
RateLimiter.limit_announcements(Map.get(attrs, :organization_id)) do
:ok ->
Multi.new()
|> Multi.insert(:post, fn _ ->
Expand All @@ -758,12 +758,15 @@ defmodule Atomic.Organizations do

{:error, reason} ->
{:error, reason}

false ->
{:error, "Organization ID is required"}
end
end

def create_announcement(attrs \\ %{}) do
case not is_nil(attrs["organization_id"]) and
RateLimiter.limit_announcements(attrs["organization_id"]) do
case verify_organization_id?(attrs) and
RateLimiter.limit_announcements(Map.get(attrs, :organization_id)) do
:ok ->
%Announcement{}
|> Announcement.changeset(attrs)
Expand All @@ -774,6 +777,15 @@ defmodule Atomic.Organizations do
end
end

def verify_organization_id?(attrs) do
if not Map.has_key?(attrs, :organization_id) or
(Map.has_key?(attrs, :organization_id) and is_nil(Map.get(attrs, :organization_id))) do
false
else
true
end
end

@doc """
Updates an announcement.
Expand Down
2 changes: 1 addition & 1 deletion test/atomic/activities_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Atomic.ActivitiesTest do
end

test "create_activity_with_post/2 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Activities.create_activity_with_post(@invalid_attrs)
assert {:error, _reason} = Activities.create_activity_with_post(@invalid_attrs)
end

test "create_activity_with_post/2 with maximum_entries lower than minimum_entries" do
Expand Down
4 changes: 1 addition & 3 deletions test/atomic/organizations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,11 @@ defmodule Atomic.OrganizationsTest do

test "create_announcement_with_post/2 with valid data creates an announcement" do
valid_attrs = params_for(:announcement)

assert {:ok, %Announcement{}} = Organizations.create_announcement_with_post(valid_attrs)
end

test "create_announcement_with_post/2 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} =
Organizations.create_announcement_with_post(@invalid_attrs)
assert {:error, _reason} = Organizations.create_announcement_with_post(@invalid_attrs)
end

test "update_announcement/2 with valid data updates the announcement" do
Expand Down

0 comments on commit f716aa5

Please sign in to comment.