fix query helpers and add policy type to projections
All checks were successful
Build and Publish / build-release (push) Successful in 1m34s
All checks were successful
Build and Publish / build-release (push) Successful in 1m34s
This commit is contained in:
@@ -8,13 +8,14 @@ defmodule WorkloadService.Projections.Task do
|
||||
import Ecto.Changeset
|
||||
|
||||
@derive {Flop.Schema,
|
||||
filterable: [:status, :org_id, :application_id],
|
||||
filterable: [:status, :org_id, :application_id, :policy_type],
|
||||
sortable: [:inserted_at, :updated_at, :status]}
|
||||
|
||||
@primary_key {:id, :string, []}
|
||||
schema "tasks" do
|
||||
field(:org_id, :string)
|
||||
field(:application_id, :string)
|
||||
field(:policy_type, :string)
|
||||
field(:task_info, :map)
|
||||
field(:submission, :map)
|
||||
field(:attachments, {:array, :string})
|
||||
@@ -37,6 +38,7 @@ defmodule WorkloadService.Projections.Task do
|
||||
:id,
|
||||
:org_id,
|
||||
:application_id,
|
||||
:policy_type,
|
||||
:task_info,
|
||||
:submission,
|
||||
:attachments,
|
||||
|
||||
@@ -14,6 +14,7 @@ defmodule WorkloadService.Projectors.TaskProjector do
|
||||
id: to_string(e.id),
|
||||
org_id: e.id.org_id,
|
||||
application_id: to_string(e.application_id),
|
||||
policy_type: e.application_id.policy_type,
|
||||
task_info: e.task_info,
|
||||
attachments: e.attachments || [],
|
||||
status: "created"
|
||||
|
||||
@@ -6,23 +6,29 @@ defmodule WorkloadServiceWeb.QueryHelpers do
|
||||
@filter_count 3
|
||||
|
||||
def flop(filter_fields, order_fields, other \\ []) do
|
||||
filter_params = build_filter_params(filter_fields, @filter_count)
|
||||
|
||||
[
|
||||
page: [in: :query, schema: %Schema{type: :number, default: 1}],
|
||||
page_size: [in: :query, schema: %Schema{type: :number, default: 20}],
|
||||
"order_by[]": [in: :query, schema: %Schema{type: :array, items: %Schema{type: :string, enum: order_fields}}],
|
||||
"order_directions[]": [in: :query, schema: %Schema{type: :array, items: %Schema{type: :string, enum: ["asc", "desc"]}}]
|
||||
] ++ filter_params ++ other
|
||||
order_by: [
|
||||
in: :query,
|
||||
schema: %Schema{type: :array, items: %Schema{type: :string, enum: order_fields}}
|
||||
],
|
||||
order_directions: [
|
||||
in: :query,
|
||||
schema: %Schema{type: :array, items: %Schema{type: :string, enum: ["asc", "desc"]}}
|
||||
]
|
||||
] ++ build_filter_params(filter_fields) ++ other
|
||||
end
|
||||
|
||||
defp build_filter_params(fields, count) do
|
||||
for i <- 0..(count - 1) do
|
||||
defp build_filter_params(fields) do
|
||||
for i <- 0..(@filter_count - 1) do
|
||||
[
|
||||
{"filters[#{i}][field]", [in: :query, schema: %Schema{type: :string, enum: fields}]},
|
||||
{"filters[#{i}][op]", [in: :query, schema: %Schema{type: :string, enum: Flop.Filter.allowed_operators(:all)}]},
|
||||
{"filters[#{i}][value]", [in: :query, schema: %Schema{type: :string}]}
|
||||
{:"filters_#{i}_field", [in: :query, schema: %Schema{type: :string, enum: fields}]},
|
||||
{:"filters_#{i}_op",
|
||||
[in: :query, schema: %Schema{type: :string, enum: Flop.Filter.allowed_operators(:all)}]},
|
||||
{:"filters_#{i}_value", [in: :query, schema: %Schema{type: :string}]}
|
||||
]
|
||||
end |> List.flatten()
|
||||
end
|
||||
|> List.flatten()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user