-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactoring opportunities (#275)
* chore: move session service to mindwendel.services, instead of mindwendel_service * chore: split brainstorming repository into multipler smaller repositories
- Loading branch information
1 parent
7e773ea
commit 6ccd5b7
Showing
26 changed files
with
590 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule Mindwendel.IdeaLabels do | ||
@moduledoc """ | ||
The Brainstormings context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Mindwendel.Repo | ||
|
||
alias Mindwendel.Brainstormings.Idea | ||
alias Mindwendel.Brainstormings | ||
alias Mindwendel.Ideas | ||
alias Mindwendel.Brainstormings.IdeaLabel | ||
alias Mindwendel.Brainstormings.IdeaIdeaLabel | ||
|
||
require Logger | ||
|
||
def get_idea_label(id) when not is_nil(id) do | ||
Repo.get(IdeaLabel, id) | ||
rescue | ||
Ecto.Query.CastError -> nil | ||
end | ||
|
||
def get_idea_label(id) when is_nil(id) do | ||
nil | ||
end | ||
|
||
def add_idea_label_to_idea(%Idea{} = idea, %IdeaLabel{} = idea_label) do | ||
idea = Repo.preload(idea, :idea_labels) | ||
|
||
idea_labels = | ||
(idea.idea_labels ++ [idea_label]) | ||
|> Enum.map(&Ecto.Changeset.change/1) | ||
|
||
idea | ||
|> Ecto.Changeset.change() | ||
|> Ecto.Changeset.put_assoc(:idea_labels, idea_labels) | ||
|> Repo.update() | ||
|> Brainstormings.broadcast(:idea_updated) | ||
end | ||
|
||
def remove_idea_label_from_idea(%Idea{} = idea, %IdeaLabel{} = idea_label) do | ||
from(idea_idea_label in IdeaIdeaLabel, | ||
where: | ||
idea_idea_label.idea_id == ^idea.id and | ||
idea_idea_label.idea_label_id == ^idea_label.id | ||
) | ||
|> Repo.delete_all() | ||
|
||
{:ok, Ideas.get_idea!(idea.id)} |> Brainstormings.broadcast(:idea_updated) | ||
end | ||
end |
Oops, something went wrong.