use new query helper
All checks were successful
Build and Publish / build-release (push) Successful in 1m25s
All checks were successful
Build and Publish / build-release (push) Successful in 1m25s
This commit is contained in:
33
lib/policy_service_web/query_helpers.ex
Normal file
33
lib/policy_service_web/query_helpers.ex
Normal 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
|
||||
Reference in New Issue
Block a user