Skip to content

Commit

Permalink
added billing profile controller for api
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Hasjanov authored and Oleg Hasjanov committed Feb 8, 2024
1 parent 2b4179a commit fe6e8b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/controllers/api/v1/billing_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Api
module V1
class BillingProfilesController < ApplicationController
before_action :authenticate_user!
respond_to :json

skip_before_action :verify_authenticity_token

def index
@billing_profiles = current_user.billing_profiles

render json: { billing_profiles: @billing_profiles }
end

def update
@billing_profile = current_user.billing_profiles.find(params[:id])

if @billing_profile.update(billing_profile_params)
render json: { billing_profile: @billing_profile }
else
render json: { errors: @billing_profile.errors }, status: 422
end
end

private

def billing_profile_params
params.require(:billing_profile).permit(:name, :vat_code, :street, :city, :state, :postal_code,
:alpha_two_country_code, :uuid)
end
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
end
end
resources :invoices, only: :index
resources :billing_profiles, only: %i[index update create destroy]
end
end

Expand Down

0 comments on commit fe6e8b8

Please sign in to comment.