This commit is contained in:
19
lib/customer_service/customer/filters.ex
Normal file
19
lib/customer_service/customer/filters.ex
Normal file
@@ -0,0 +1,19 @@
|
||||
defmodule CustomerService.Customers.Filters do
|
||||
import Ecto.Query
|
||||
|
||||
def search(query, %Flop.Filter{value: value}, _opts) do
|
||||
term = "%#{value}%"
|
||||
|
||||
where(
|
||||
query,
|
||||
[c],
|
||||
ilike(c.first_name, ^term) or
|
||||
ilike(c.last_name, ^term) or
|
||||
ilike(c.legal_name, ^term) or
|
||||
ilike(c.email, ^term) or
|
||||
ilike(c.phone, ^term) or
|
||||
ilike(c.document_id, ^term) or
|
||||
ilike(c.ruc, ^term)
|
||||
)
|
||||
end
|
||||
end
|
||||
15
lib/customer_service/customer/queries.ex
Normal file
15
lib/customer_service/customer/queries.ex
Normal file
@@ -0,0 +1,15 @@
|
||||
defmodule CustomerService.Customer.Queries do
|
||||
alias CustomerService.Projections.Customer
|
||||
alias CustomerService.Repo
|
||||
|
||||
def list_customers(params \\ %{}) do
|
||||
Flop.validate_and_run(Customer, params, for: Customer)
|
||||
end
|
||||
|
||||
def get_customer(id) do
|
||||
case Repo.get(Customer, id) do
|
||||
nil -> {:error, :not_found}
|
||||
customer -> {:ok, customer}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user