Various refactoring and typespec improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-24 16:46:42 +02:00
parent d235653876
commit 1893d9f55b
142 changed files with 1854 additions and 1297 deletions

View File

@@ -87,7 +87,7 @@ defmodule Mobilizon.Discussions.Comment do
end
@doc false
@spec changeset(t, map) :: Ecto.Changeset.t()
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
def changeset(%__MODULE__{} = comment, attrs) do
comment
|> common_changeset(attrs)

View File

@@ -59,7 +59,7 @@ defmodule Mobilizon.Discussions.Discussion do
end
@doc false
@spec changeset(t, map) :: Ecto.Changeset.t()
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
def changeset(%__MODULE__{} = discussion, attrs) do
discussion
|> cast(attrs, @attrs)

View File

@@ -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