defmodule CustomerService.Lead.Queries do import Ecto.Query alias CustomerService.Projections.QuickLead alias CustomerService.Repo def list_by_org(org_id, params \\ %{}) when is_binary(org_id) do base = from(q in QuickLead, where: q.org_id == ^org_id) Flop.validate_and_run(base, params, for: QuickLead) end def get_by_org(org_id, lead_id) when is_binary(org_id) and is_binary(lead_id) do case Repo.get_by(QuickLead, org_id: org_id, lead_id: lead_id) do nil -> {:error, :not_found} lead -> {:ok, lead} end end end