I have the following action in my Phoenix app controller:
def index(conn, params) do
studios =
if params["search"] do
Studio.search(Studio, params["search"])
else
Studio
end
|> Repo.all
|> Repo.preload(:address)
render conn, studios: studios
end
When my run mix credo
it returns following warning:
┃ [F] → Pipe chain should start with a raw value.
┃ lib/tattoo_backend/web/controllers/api/v1/studio_controller.ex:21 #(TattooBackend.Web.API.V1.StudioController.index)
I've tried to refactor that but I didn't find solution that will makes credo happy. Any ideas how to solve this?
queryable =
if params["search"] do
Studio.search(Studio, params["search"])
else
Studio
end
queryable
|> Repo.all()
|> Repo.preload(:address)
Using pattern matching:
def index(conn, params) do
params
|> search
|> Repo.all()
|> Repo.preload(:address)
end
defp search(%{"search" => search}) do
Studio.search(Studio, search)
end
defp search(_), do: Studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With