use new query helper
All checks were successful
Build and Publish / build-release (push) Successful in 1m25s

This commit is contained in:
2026-04-22 14:39:00 -05:00
parent e209879898
commit 4383080696
2 changed files with 38 additions and 26 deletions

View File

@@ -0,0 +1,33 @@
defmodule PolicyServiceWeb.QueryHelpers do
@moduledoc false
alias OpenApiSpex.Schema
def flop(filter_fields, order_fields, other \\ []) do
[
filters: [in: :query, schema: filters(filter_fields)],
order_by: [in: :query, schema: order_by(order_fields)],
page: [in: :query, schema: %Schema{type: :number, default: 1}],
page_size: [in: :query, schema: %Schema{type: :number, default: 20}]
] ++ other
end
defp filters(fields) do
%Schema{
type: :array,
items: %Schema{
type: :object,
properties: %{
field: %Schema{type: :string, enum: fields},
value: %Schema{type: :any},
op: %Schema{type: :string, enum: Flop.Filter.allowed_operators(:all)}
},
required: [:field, :value]
}
}
end
defp order_by(fields) do
%Schema{type: :array, items: %Schema{type: :string, enum: fields}}
end
end