Skip to content

Commit

Permalink
feat: Preparing lenra application for apps settings management (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-martinez authored May 2, 2022
1 parent 1e17857 commit 948db2e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/lenra/lib/lenra/services/lenra_application_services.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ defmodule Lenra.LenraApplicationServices do
|> Repo.transaction()
end

def update(app, params) do
Ecto.Multi.new()
|> Ecto.Multi.update(:updated_application, LenraApplication.update(app, params))
|> Repo.transaction()
end

def delete(app) do
Ecto.Multi.new()
|> Ecto.Multi.delete(:deleted_application, app)
Expand Down
16 changes: 16 additions & 0 deletions apps/lenra/test/lenra/services/lenra_application_services_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,20 @@ defmodule LenraWeb.LenraApplicationServicesTest do
assert apps == []
end
end

describe "update" do
test "application successfully", %{user: user, random_user: _random_user} do
{:ok, app} = LenraApplicationServices.fetch_by(name: "public-app")

LenraApplicationServices.update(app, %{
repository: "new_repo"
})

{:ok, updated_app} = LenraApplicationServices.fetch_by(name: "public-app")

assert app.repository != updated_app.repository
assert app.repository == nil
assert updated_app.repository == "new_repo"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ defmodule LenraWeb.AppsController do
end
end

def update(conn, %{"id" => app_id} = params) do
with {:ok, app} <- LenraApplicationServices.fetch(app_id),
:ok <- allow(conn, app),
{:ok, %{updated_application: app}} <- LenraApplicationServices.update(app, params) do
conn
|> assign_data(:updated_application, app)
|> reply
end
end

def delete(conn, %{"id" => app_id}) do
with {:ok, app} <- LenraApplicationServices.fetch(app_id),
:ok <- allow(conn, app),
Expand Down
2 changes: 1 addition & 1 deletion apps/lenra_web/lib/lenra_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule LenraWeb.Router do
get("/cgu/me/accepted_latest", CguController, :user_accepted_latest_cgu)

pipe_through([:ensure_cgu_accepted])
resources("/apps", AppsController, only: [:index, :create, :delete])
resources("/apps", AppsController, only: [:index, :create, :update, :delete])
get("/apps/:app_id/main_environment", ApplicationMainEnvController, :index)
resources("/apps/:app_id/environments", EnvsController, only: [:index, :create])
patch("/apps/:app_id/environments/:env_id", EnvsController, :update)
Expand Down

0 comments on commit 948db2e

Please sign in to comment.