Skip to content

Commit

Permalink
feat(update_campaigns): add update api
Browse files Browse the repository at this point in the history
add api to allow updates of existing update_campaigns.
it is possible to edit
- UpdateCampaign.name
- UpdateCampaign.rollout_mechanism, but only with
update inputs of the same type
- PushRollout.max_in_progress_updates, but only with an higher
value
- all other PushRollout properties

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
  • Loading branch information
noaccOS committed Jun 22, 2023
1 parent 0ad0c3c commit 59796e1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions backend/lib/edgehog/update_campaigns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,23 @@ defmodule Edgehog.UpdateCampaigns do
end
end

@doc """
Updates an update_campaign.
## Examples
iex> update_update_campaign(update_campaign, %{field: new_value})
{:ok, %UpdateCamapaign{}}
iex> update_update_campaign(update_campaign, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_update_campaign(%UpdateCampaign{} = update_campaign, attrs) do
UpdateCampaign.changeset(update_campaign, attrs)
|> Repo.update()
end

@doc """
Preloads the default associations for a Target or a list of Targets
"""
Expand Down
10 changes: 10 additions & 0 deletions backend/lib/edgehog_web/resolvers/update_campaigns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule EdgehogWeb.Resolvers.UpdateCampaigns do
alias Edgehog.BaseImages
alias Edgehog.UpdateCampaigns
alias Edgehog.UpdateCampaigns.UpdateChannel
alias Edgehog.UpdateCampaigns.UpdateCampaign
import Absinthe.Resolution.Helpers, only: [batch: 3]

def find_target(args, _resolution) do
Expand Down Expand Up @@ -107,6 +108,15 @@ defmodule EdgehogWeb.Resolvers.UpdateCampaigns do
end
end

def update_update_campaign(args, _resolution) do
with {:ok, update_campaign} <-
UpdateCampaigns.fetch_update_campaign(args.update_campaign_id),
{:ok, updated_update_campaign} <-
UpdateCampaigns.update_update_campaign(update_campaign, args) do
{:ok, %{update_campaign: updated_update_campaign}}
end
end

# This moves the type tag from the outer key to the inner map, which adapts the behaviour
# offered by GraphQL to the one required by PolymorphicEmbed in the changeset
defp tag_rollout_mechanism(%{push: push_rollout_mechanism}) do
Expand Down
26 changes: 26 additions & 0 deletions backend/lib/edgehog_web/schema/update_campaigns_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,31 @@ defmodule EdgehogWeb.Schema.UpdateCampaignsTypes do

resolve &Resolvers.UpdateCampaigns.create_update_campaign/2
end

@desc "Updates an existing update campaign."
payload field :update_update_campaign do
input do
@desc "The ID of the update campaign to be updated"
field :update_campaign_id, non_null(:id)

@desc "The name of the Update Campaign."
field :name, :string

@desc "The Rollout Mechanism of the Update Campaign, with its properties"
field :rollout_mechanism, :rollout_mechanism_input
end

output do
@desc "The updated Update Campaign."
field :update_campaign, non_null(:update_campaign)
end

middleware Absinthe.Relay.Node.ParseIDs,
# base_image_id: :base_image,
# update_channel_id: :update_channel,
update_campaign_id: :update_campaign

resolve &Resolvers.UpdateCampaigns.update_update_campaign/2
end
end
end

0 comments on commit 59796e1

Please sign in to comment.