Packages
shopifex
0.3.4
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.20
2.1.19
2.1.18
2.1.17
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
1.1.1
1.1.0
1.0.1
1.0.0
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Phoenix boilerplate for Shopify Embedded App SDK
Current section
Files
Jump to
Current section
Files
lib/shopifex_web/controllers/grant_controller.ex
defmodule ShopifexWeb.GrantController do
use ShopifexWeb, :controller
alias Shopifex.Shops
def grant_schema, do: Application.fetch_env!(:shopifex, :grant_schema)
def index(conn, _params) do
grants = Shops.list_grants()
render(conn, "index.html", grants: grants)
end
def new(conn, _params) do
changeset = Shops.change_grant(struct!(grant_schema()))
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"grant" => grant_params}) do
case Shops.create_grant(grant_params) do
{:ok, grant} ->
conn
|> put_flash(:info, "Grant created successfully.")
|> redirect(to: Routes.grant_path(conn, :show, grant))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
grant = Shops.get_grant!(id)
render(conn, "show.html", grant: grant)
end
def edit(conn, %{"id" => id}) do
grant = Shops.get_grant!(id)
changeset = Shops.change_grant(grant)
render(conn, "edit.html", grant: grant, changeset: changeset)
end
def update(conn, %{"id" => id, "grant" => grant_params}) do
grant = Shops.get_grant!(id)
case Shops.update_grant(grant, grant_params) do
{:ok, grant} ->
conn
|> put_flash(:info, "Grant updated successfully.")
|> redirect(to: Routes.grant_path(conn, :show, grant))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", grant: grant, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
grant = Shops.get_grant!(id)
{:ok, _grant} = Shops.delete_grant(grant)
conn
|> put_flash(:info, "Grant deleted successfully.")
|> redirect(to: Routes.grant_path(conn, :index))
end
end