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
|
import Ecto.Changeset
|
||||||
|
|
||||||
@derive {Flop.Schema,
|
@derive {Flop.Schema,
|
||||||
filterable: [:status, :org_id, :application_id],
|
filterable: [:status, :org_id, :application_id, :policy_type],
|
||||||
sortable: [:inserted_at, :updated_at, :status]}
|
sortable: [:inserted_at, :updated_at, :status]}
|
||||||
|
|
||||||
@primary_key {:id, :string, []}
|
@primary_key {:id, :string, []}
|
||||||
schema "tasks" do
|
schema "tasks" do
|
||||||
field(:org_id, :string)
|
field(:org_id, :string)
|
||||||
field(:application_id, :string)
|
field(:application_id, :string)
|
||||||
|
field(:policy_type, :string)
|
||||||
field(:task_info, :map)
|
field(:task_info, :map)
|
||||||
field(:submission, :map)
|
field(:submission, :map)
|
||||||
field(:attachments, {:array, :string})
|
field(:attachments, {:array, :string})
|
||||||
@@ -37,6 +38,7 @@ defmodule WorkloadService.Projections.Task do
|
|||||||
:id,
|
:id,
|
||||||
:org_id,
|
:org_id,
|
||||||
:application_id,
|
:application_id,
|
||||||
|
:policy_type,
|
||||||
:task_info,
|
:task_info,
|
||||||
:submission,
|
:submission,
|
||||||
:attachments,
|
:attachments,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ defmodule WorkloadService.Projectors.TaskProjector do
|
|||||||
id: to_string(e.id),
|
id: to_string(e.id),
|
||||||
org_id: e.id.org_id,
|
org_id: e.id.org_id,
|
||||||
application_id: to_string(e.application_id),
|
application_id: to_string(e.application_id),
|
||||||
|
policy_type: e.application_id.policy_type,
|
||||||
task_info: e.task_info,
|
task_info: e.task_info,
|
||||||
attachments: e.attachments || [],
|
attachments: e.attachments || [],
|
||||||
status: "created"
|
status: "created"
|
||||||
|
|||||||
@@ -6,23 +6,29 @@ defmodule WorkloadServiceWeb.QueryHelpers do
|
|||||||
@filter_count 3
|
@filter_count 3
|
||||||
|
|
||||||
def flop(filter_fields, order_fields, other \\ []) do
|
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: [in: :query, schema: %Schema{type: :number, default: 1}],
|
||||||
page_size: [in: :query, schema: %Schema{type: :number, default: 20}],
|
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_by: [
|
||||||
"order_directions[]": [in: :query, schema: %Schema{type: :array, items: %Schema{type: :string, enum: ["asc", "desc"]}}]
|
in: :query,
|
||||||
] ++ filter_params ++ other
|
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
|
end
|
||||||
|
|
||||||
defp build_filter_params(fields, count) do
|
defp build_filter_params(fields) do
|
||||||
for i <- 0..(count - 1) do
|
for i <- 0..(@filter_count - 1) do
|
||||||
[
|
[
|
||||||
{"filters[#{i}][field]", [in: :query, schema: %Schema{type: :string, enum: fields}]},
|
{:"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}_op",
|
||||||
{"filters[#{i}][value]", [in: :query, schema: %Schema{type: :string}]}
|
[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
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ defmodule WorkloadService.Repo.Migrations.CreateTasks do
|
|||||||
add(:id, :string, primary_key: true)
|
add(:id, :string, primary_key: true)
|
||||||
add(:org_id, :string, null: false)
|
add(:org_id, :string, null: false)
|
||||||
add(:application_id, :string, null: false)
|
add(:application_id, :string, null: false)
|
||||||
|
add(:policy_type, :string)
|
||||||
add(:task_info, :map, default: %{})
|
add(:task_info, :map, default: %{})
|
||||||
add(:submission, :map)
|
add(:submission, :map)
|
||||||
add(:attachments, {:array, :string}, default: [])
|
add(:attachments, {:array, :string}, default: [])
|
||||||
@@ -17,5 +18,6 @@ defmodule WorkloadService.Repo.Migrations.CreateTasks do
|
|||||||
create(index(:tasks, [:application_id]))
|
create(index(:tasks, [:application_id]))
|
||||||
create(index(:tasks, [:org_id]))
|
create(index(:tasks, [:org_id]))
|
||||||
create(index(:tasks, [:status]))
|
create(index(:tasks, [:status]))
|
||||||
|
create(index(:tasks, [:policy_type]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user