-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule AppApi.Tags do | ||
@moduledoc """ | ||
The Tags context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias AppApi.Repo | ||
|
||
alias AppApi.Tags.Tag | ||
|
||
@doc """ | ||
Returns the list of tags. | ||
## Examples | ||
iex> list_tags() | ||
[%Tag{}, ...] | ||
""" | ||
def list_tags do | ||
Repo.all(Tag) | ||
end | ||
|
||
@doc """ | ||
Returns the list of tags created by a person | ||
i.e. default tags | ||
""" | ||
def get_tags_by_id_person(id_person) do | ||
query = | ||
from t in Tag, | ||
where: t.id_person == ^id_person, | ||
order_by: [asc: t.text] | ||
|
||
Repo.all(query) | ||
end | ||
|
||
@doc """ | ||
Returns the list of tags where the person is not defined | ||
i.e. default tags | ||
""" | ||
def get_default_tags() do | ||
query = | ||
from t in Tag, | ||
where: is_nil(t.id_person), | ||
order_by: [asc: t.text] | ||
|
||
Repo.all(query) | ||
end | ||
|
||
@doc """ | ||
Creates a tag. | ||
""" | ||
def create_tag(attrs \\ %{}) do | ||
%Tag{} | ||
|> Tag.changeset(attrs) | ||
|> Repo.insert!() | ||
end | ||
end |
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