commit cdcdd4e988c9cf8af69e5fd298e730c1db4b6601
parent 493e35eff83e75c1022f07284bf48ce795eeed08
Author: srfsh <dev@srf.sh>
Date: Tue, 15 Nov 2022 00:02:10 +0300
Zenflows.VF.Organization: rename Filter to Query
Diffstat:
3 files changed, 50 insertions(+), 50 deletions(-)
diff --git a/src/zenflows/vf/organization/domain.ex b/src/zenflows/vf/organization/domain.ex
@@ -20,7 +20,7 @@ defmodule Zenflows.VF.Organization.Domain do
alias Ecto.{Changeset, Multi}
alias Zenflows.DB.{Page, Repo, Schema}
-alias Zenflows.VF.{Organization, Organization.Filter}
+alias Zenflows.VF.{Organization, Organization.Query}
@spec one(Ecto.Repo.t(), Schema.id() | map() | Keyword.t())
:: {:ok, Organization.t()} | {:error, String.t()}
@@ -43,7 +43,7 @@ end
@spec all(Page.t()) :: {:ok, [Organization.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
diff --git a/src/zenflows/vf/organization/filter.ex b/src/zenflows/vf/organization/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.Organization.Filter do
-@moduledoc false
-
-import Ecto.Query
-
-alias Ecto.{Changeset, Queryable}
-alias Zenflows.DB.{Page, Schema, Validate}
-alias Zenflows.VF.Organization
-
-@spec all(Page.t()) :: {:ok, Queryable.t()} | {:error, Changeset.t()}
-def all(%{filter: nil}), do: {:ok, where(Organization, type: :org)}
-def all(%{filter: params}) do
- with {:ok, filters} <- all_validate(params) do
- {:ok, Enum.reduce(filters, where(Organization, type: :org), &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/organization/query.ex b/src/zenflows/vf/organization/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.Organization.Query do
+@moduledoc false
+
+import Ecto.Query
+
+alias Ecto.{Changeset, Queryable}
+alias Zenflows.DB.{Page, Schema, Validate}
+alias Zenflows.VF.Organization
+
+@spec all(Page.t()) :: {:ok, Queryable.t()} | {:error, Changeset.t()}
+def all(%{filter: nil}), do: {:ok, where(Organization, type: :org)}
+def all(%{filter: params}) do
+ with {:ok, filters} <- all_validate(params) do
+ {:ok, Enum.reduce(filters, where(Organization, type: :org), &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