commit a7ce1dfe58aa490035176b5c0f0c835797064535
parent b8cfb52f95badf7fcc1eb5333200f898dcf7840a
Author: srfsh <dev@srf.sh>
Date: Mon, 14 Nov 2022 23:58:49 +0300
Zenflows.VF.Agent: rename Filter to Query
Diffstat:
3 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/src/zenflows/vf/agent/domain.ex b/src/zenflows/vf/agent/domain.ex
@@ -20,7 +20,7 @@ defmodule Zenflows.VF.Agent.Domain do
alias Ecto.Changeset
alias Zenflows.DB.{Page, Repo, Schema}
-alias Zenflows.VF.{Agent, Agent.Filter}
+alias Zenflows.VF.{Agent, Agent.Query}
@spec one(Ecto.Repo.t(), Schema.id() | map() | Keyword.t())
:: {:ok, Agent.t()} | {:error, String.t()}
@@ -34,22 +34,22 @@ def one(repo, clauses) do
end
@spec one!(Ecto.Repo.t(), Schema.id() | map() | Keyword.t()) :: Agent.t()
-def one!(repo \\ Repo, x) do
- {:ok, found} = one(repo, x)
- found
+def one!(repo \\ Repo, id_or_clauses) do
+ {:ok, value} = one(repo, id_or_clauses)
+ value
end
@spec all(Page.t()) :: {:ok, [Agent.t()]} | {:error, Changeset.t()}
def all(page \\ Page.new()) do
- with {:ok, q} <- Filter.all(page) do
+ with {:ok, q} <- Query.all(page) do
{:ok, Page.all(q, page)}
end
end
@spec all!(Page.t()) :: [Agent.t()]
def all!(page \\ Page.new()) do
- {:ok, q} = Filter.all(page)
- Page.all(q, page)
+ {:ok, value} = all(page)
+ value
end
@spec preload(Agent.t(), :images | :primary_location) :: Agent.t()
diff --git a/src/zenflows/vf/agent/filter.ex b/src/zenflows/vf/agent/filter.ex
@@ -1,48 +0,0 @@
-# Zenflows is designed to implement the Valueflows vocabulary,
-# written and maintained by srfsh <info@dyne.org>.
-# Copyright (C) 2021-2022 Dyne.org foundation <foundation@dyne.org>.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-defmodule Zenflows.VF.Agent.Filter do
-@moduledoc false
-
-import Ecto.Query
-
-alias Ecto.{Changeset, Queryable}
-alias Zenflows.DB.{Page, Schema, Validate}
-alias Zenflows.VF.Agent
-
-@spec all(Page.t()) :: {:ok, Queryable.t()} | {:error, Changeset.t()}
-def all(%{filter: nil}), do: {:ok, Agent}
-def all(%{filter: params}) do
- with {:ok, filters} <- all_validate(params) do
- {:ok, Enum.reduce(filters, Agent, &all_f(&2, &1))}
- end
-end
-
-@spec all_f(Queryable.t(), {atom(), term()}) :: Queryable.t()
-defp all_f(q, {:name, v}),
- do: where(q, [x], ilike(x.name, ^"%#{v}%"))
-
-@spec all_validate(Schema.params())
- :: {:ok, Changeset.data()} | {:error, Changeset.t()}
-defp all_validate(params) do
- {%{}, %{name: :string}}
- |> Changeset.cast(params, [:name])
- |> Validate.name(:name)
- |> Validate.escape_like(:name)
- |> Changeset.apply_action(nil)
-end
-end
diff --git a/src/zenflows/vf/agent/query.ex b/src/zenflows/vf/agent/query.ex
@@ -0,0 +1,48 @@
+# Zenflows is designed to implement the Valueflows vocabulary,
+# written and maintained by srfsh <info@dyne.org>.
+# Copyright (C) 2021-2022 Dyne.org foundation <foundation@dyne.org>.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+defmodule Zenflows.VF.Agent.Query do
+@moduledoc false
+
+import Ecto.Query
+
+alias Ecto.{Changeset, Queryable}
+alias Zenflows.DB.{Page, Schema, Validate}
+alias Zenflows.VF.Agent
+
+@spec all(Page.t()) :: {:ok, Queryable.t()} | {:error, Changeset.t()}
+def all(%{filter: nil}), do: {:ok, Agent}
+def all(%{filter: params}) do
+ with {:ok, filters} <- all_validate(params) do
+ {:ok, Enum.reduce(filters, Agent, &all_f(&2, &1))}
+ end
+end
+
+@spec all_f(Queryable.t(), {atom(), term()}) :: Queryable.t()
+defp all_f(q, {:name, v}),
+ do: where(q, [x], ilike(x.name, ^"%#{v}%"))
+
+@spec all_validate(Schema.params())
+ :: {:ok, Changeset.data()} | {:error, Changeset.t()}
+defp all_validate(params) do
+ {%{}, %{name: :string}}
+ |> Changeset.cast(params, [:name])
+ |> Validate.name(:name)
+ |> Validate.escape_like(:name)
+ |> Changeset.apply_action(nil)
+end
+end