Merge branch 'master' into refactoring-based-on-credo-and-dialyzer

This commit is contained in:
miffigriffi
2019-09-21 23:59:07 +02:00
126 changed files with 3311 additions and 2255 deletions

View File

@@ -13,6 +13,8 @@ defmodule Mobilizon.Reports.Note do
@required_attrs [:content, :moderator_id, :report_id]
@attrs @required_attrs
@timestamps_opts [type: :utc_datetime]
@type t :: %__MODULE__{
content: String.t(),
report: Report.t(),

View File

@@ -23,10 +23,12 @@ defmodule Mobilizon.Reports.Report do
notes: [Note.t()]
}
@required_attrs [:content, :uri, :reported_id, :reporter_id]
@optional_attrs [:status, :manager_id, :event_id]
@required_attrs [:uri, :reported_id, :reporter_id]
@optional_attrs [:content, :status, :manager_id, :event_id]
@attrs @required_attrs ++ @optional_attrs
@timestamps_opts [type: :utc_datetime]
@derive {Jason.Encoder, only: [:status, :uri]}
schema "reports" do
field(:content, :string)

View File

@@ -76,14 +76,29 @@ defmodule Mobilizon.Reports do
@doc """
Returns the list of reports.
"""
@spec list_reports(integer | nil, integer | nil, atom, atom) :: [Report.t()]
def list_reports(page \\ nil, limit \\ nil, sort \\ :updated_at, direction \\ :asc) do
list_reports_query()
@spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus) :: [Report.t()]
def list_reports(
page \\ nil,
limit \\ nil,
sort \\ :updated_at,
direction \\ :asc,
status \\ :open
) do
status
|> list_reports_query()
|> Page.paginate(page, limit)
|> sort(sort, direction)
|> Repo.all()
end
@doc """
Counts opened reports.
"""
@spec count_opened_reports :: integer
def count_opened_reports do
Repo.aggregate(count_reports_query(), :count, :id)
end
@doc """
Gets a single note.
"""
@@ -131,14 +146,20 @@ defmodule Mobilizon.Reports do
from(r in Report, where: r.uri == ^url)
end
@spec list_reports_query :: Ecto.Query.t()
defp list_reports_query do
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
defp list_reports_query(status) do
from(
r in Report,
preload: [:reported, :reporter, :manager, :event, :comments, :notes]
preload: [:reported, :reporter, :manager, :event, :comments, :notes],
where: r.status == ^status
)
end
@spec count_reports_query :: Ecto.Query.t()
defp count_reports_query do
from(r in Report, where: r.status == ^:open)
end
@spec list_notes_for_report_query(integer | String.t()) :: Ecto.Query.t()
defp list_notes_for_report_query(report_id) do
from(