-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove JaResource/Canary from StripePlatformCardController (#1021)
- Loading branch information
1 parent
b1adc19
commit 2cb10dd
Showing
4 changed files
with
34 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 19 additions & 10 deletions
29
lib/code_corps_web/controllers/stripe_platform_card_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
defmodule CodeCorpsWeb.StripePlatformCardController do | ||
use CodeCorpsWeb, :controller | ||
use JaResource | ||
|
||
alias CodeCorps.StripePlatformCard | ||
alias CodeCorps.StripeService.StripePlatformCardService | ||
alias CodeCorps.{StripePlatformCard, User} | ||
|
||
plug :load_and_authorize_resource, model: StripePlatformCard, only: [:show], preload: [:user] | ||
plug :load_and_authorize_changeset, model: StripePlatformCard, only: [:create] | ||
action_fallback CodeCorpsWeb.FallbackController | ||
plug CodeCorpsWeb.Plug.DataToAttributes | ||
plug CodeCorpsWeb.Plug.IdsToIntegers | ||
|
||
plug JaResource | ||
|
||
@spec model :: module | ||
def model, do: CodeCorps.StripePlatformCard | ||
@spec show(Conn.t, map) :: Conn.t | ||
def show(%Conn{} = conn, %{"id" => id} = params) do | ||
with %User{} = current_user <- conn |> Guardian.Plug.current_resource, | ||
%StripePlatformCard{} = stripe_platform_card <- StripePlatformCard |> Repo.get(id), | ||
{:ok, :authorized} <- current_user |> Policy.authorize(:show, stripe_platform_card, params) do | ||
conn |> render("show.json-api", data: stripe_platform_card) | ||
end | ||
end | ||
|
||
def handle_create(_conn, attributes) do | ||
attributes |> StripePlatformCardService.create | ||
@spec create(Plug.Conn.t, map) :: Conn.t | ||
def create(%Conn{} = conn, %{} = params) do | ||
with %User{} = current_user <- conn |> Guardian.Plug.current_resource, | ||
{:ok, :authorized} <- current_user |> Policy.authorize(:create, %StripePlatformCard{}, params), | ||
{:ok, %StripePlatformCard{} = stripe_platform_card} <- StripePlatformCardService.create(params) do | ||
conn |> put_status(:created) |> render("show.json-api", data: stripe_platform_card) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters