Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -71,7 +71,7 @@ defmodule Mobilizon.Discussions do
|
||||
We only get first comment of thread, and count replies.
|
||||
Read: https://hexdocs.pm/absinthe/ecto.html#dataloader
|
||||
"""
|
||||
@spec query(atom(), map()) :: Ecto.Queryable.t()
|
||||
@spec query(atom(), map()) :: Ecto.Query.t()
|
||||
def query(Comment, %{top_level: true}) do
|
||||
Comment
|
||||
|> join(:left, [c], r in Comment, on: r.origin_comment_id == c.id)
|
||||
@@ -158,7 +158,7 @@ defmodule Mobilizon.Discussions do
|
||||
Gets a comment by its URL, with all associations loaded.
|
||||
Raises `Ecto.NoResultsError` if the comment does not exist.
|
||||
"""
|
||||
@spec get_comment_from_url_with_preload(String.t()) :: Comment.t()
|
||||
@spec get_comment_from_url_with_preload!(String.t()) :: Comment.t()
|
||||
def get_comment_from_url_with_preload!(url) do
|
||||
Comment
|
||||
|> Repo.get_by!(url: url)
|
||||
@@ -168,7 +168,7 @@ defmodule Mobilizon.Discussions do
|
||||
@doc """
|
||||
Gets a comment by its UUID, with all associations loaded.
|
||||
"""
|
||||
@spec get_comment_from_uuid_with_preload(String.t()) :: Comment.t()
|
||||
@spec get_comment_from_uuid_with_preload(String.t()) :: Comment.t() | nil
|
||||
def get_comment_from_uuid_with_preload(uuid) do
|
||||
Comment
|
||||
|> Repo.get_by(uuid: uuid)
|
||||
@@ -355,7 +355,7 @@ defmodule Mobilizon.Discussions do
|
||||
@doc """
|
||||
Get a discussion by it's slug
|
||||
"""
|
||||
@spec get_discussion_by_slug(String.t()) :: Discussion.t()
|
||||
@spec get_discussion_by_slug(String.t()) :: Discussion.t() | nil
|
||||
def get_discussion_by_slug(discussion_slug) do
|
||||
Discussion
|
||||
|> Repo.get_by(slug: discussion_slug)
|
||||
@@ -494,11 +494,11 @@ defmodule Mobilizon.Discussions do
|
||||
)
|
||||
end
|
||||
|
||||
@spec filter_comments_under_events(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
@spec filter_comments_under_events(Ecto.Queryable.t()) :: Ecto.Query.t()
|
||||
defp filter_comments_under_events(query) do
|
||||
where(query, [c], is_nil(c.discussion_id) and not is_nil(c.event_id))
|
||||
end
|
||||
|
||||
@spec preload_for_comment(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
@spec preload_for_comment(Ecto.Queryable.t()) :: Ecto.Query.t()
|
||||
defp preload_for_comment(query), do: preload(query, ^@comment_preloads)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user