Skip to content

Commit

Permalink
Create accounts_controller.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 20, 2024
1 parent 3f9544b commit 404c053
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions global_business/business/controllers/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Api
module V1
class AccountsController < ApplicationController
before_action :authenticate_user!
before_action :set_account, only: [:show, :update, :destroy]

def create
@account = Account.new(account_params)
if @account.save
render json: @account, status: :created
else
render json: { errors: @account.errors }, status: :unprocessable_entity
end
end

def show
render json: @account
end

def update
if @account.update(account_params)
render json: @account
else
render json: { errors: @account.errors }, status: :unprocessable_entity
end
end

def destroy
@account.destroy
render json: { message: "Account deleted successfully" }, status: :ok
end

private

def account_params
params.require(:account).permit(:account_number, :routing_number, :account_type, :user_id)
end

def set_account
@account = Account.find(params[:id])
end
end
end
end

0 comments on commit 404c053

Please sign in to comment.