Class: Magnetik::CreditCardsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/magnetik/credit_cards_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/magnetik/credit_cards_controller.rb', line 13

def create
  token = create_params[:token]
  card_params = create_params.except(:token)
  @use_case = CreateCreditCard.perform(customer, token, card_params)

  if @use_case.success?
    render json: { credit_card: @use_case.local_card }, status: :created
  else
    render json: { errors: @use_case.errors }, status: :unprocessable_entity
  end
end

#destroyObject



36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/magnetik/credit_cards_controller.rb', line 36

def destroy
  @credit_card = CreditCard.find(params[:id])
  @use_case = DestroyCreditCard.perform(@credit_card)

  if @use_case.success?
    render nothing: true, status: :no_content
  else
    render json: { errors: @use_case.errors }, status: :unprocessable_entity
  end
end

#indexObject



9
10
11
# File 'app/controllers/magnetik/credit_cards_controller.rb', line 9

def index
  render json: { credit_cards: collection }
end

#updateObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/magnetik/credit_cards_controller.rb', line 25

def update
  @credit_card = CreditCard.find(params[:id])
  @use_case = UpdateCreditCard.perform(@credit_card, update_params)

  if @use_case.success?
    render json: { credit_card: @credit_card }, status: :ok
  else
    render json: { errors: @use_case.errors }, status: :unprocessable_entity
  end
end