From fe6e8b8a6fa88304c5eaf13cc284177259edce6b Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 8 Feb 2024 10:34:18 +0200 Subject: [PATCH] added billing profile controller for api --- .../api/v1/billing_profiles_controller.rb | 33 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 34 insertions(+) create mode 100644 app/controllers/api/v1/billing_profiles_controller.rb diff --git a/app/controllers/api/v1/billing_profiles_controller.rb b/app/controllers/api/v1/billing_profiles_controller.rb new file mode 100644 index 000000000..4c10f1362 --- /dev/null +++ b/app/controllers/api/v1/billing_profiles_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index af5e66917..9b384cb34 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ end end resources :invoices, only: :index + resources :billing_profiles, only: %i[index update create destroy] end end