1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00
fab-manager/app/controllers/api/subscriptions_controller.rb

42 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type Subscription
2016-03-23 18:39:41 +01:00
class API::SubscriptionsController < API::ApiController
2021-10-08 19:14:47 +02:00
before_action :set_subscription, only: %i[show payment_details edit update destroy]
2016-03-23 18:39:41 +01:00
before_action :authenticate_user!
def show
authorize @subscription
end
def update
authorize @subscription
res = Subscriptions::Subscribe.new(current_user.invoicing_profile.id)
2021-10-12 14:07:35 +02:00
.extend_subscription(@subscription, subscription_update_params[:expired_at])
2018-12-11 17:27:25 +01:00
if res.is_a?(Subscription)
@subscription = res
render status: :created
elsif res
2016-03-23 18:39:41 +01:00
render status: :ok
else
render status: :unprocessable_entity
end
end
2021-10-08 19:14:47 +02:00
def payment_details
authorize @subscription
end
2016-03-23 18:39:41 +01:00
private
# Use callbacks to share common setup or constraints between actions.
def set_subscription
@subscription = Subscription.find(params[:id])
end
2016-03-23 18:39:41 +01:00
def subscription_update_params
params.require(:subscription).permit(:expired_at)
end
2016-03-23 18:39:41 +01:00
end