Skip to content

Commit

Permalink
Create banking.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 22, 2024
1 parent 32da932 commit c6dbf1d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions bank_integration/banks/banking_app/app/banking/banking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from flask import request, jsonify, current_app
from flask_jwt_extended import jwt_required
from .models import Account
from .schemas import AccountSchema

@banking_blueprint.route("/accounts", methods=["GET"])
@jwt_required
def get_accounts():
accounts = Account.query.all()
return jsonify([AccountSchema().dump(account) for account in accounts])

@banking_blueprint.route("/accounts", methods=["POST"])
@jwt_required
def create_account():
account_number = request.json.get("account_number")
account = Account(account_number=account_number)
db.session.add(account)
db.session.commit()
return jsonify(message="Account created successfully")

@banking_blueprint.route("/accounts/<int:account_id>", methods=["GET"])
@jwt_required
def get_account(account_id):
account = Account.query.get(account_id)
if account:
return jsonify(AccountSchema().dump(account))
return jsonify(error="Account not found"), 404

@banking_blueprint.route("/accounts/<int:account_id>", methods=["PUT"])
@jwt_required
def update_account(account_id):
account = Account.query.get(account_id)
if account:
account.account_number = request.json.get("account_number")
db.session.commit()
return jsonify(message="Account updated successfully")
return jsonify(error="Account not found"), 404

@banking_blueprint.route("/accounts/<int:account_id>", methods=["DELETE"])
@jwt_required
def delete_account(account_id):
account = Account.query.get(account_id)
if account:
db.session.delete(account)
db.session.commit()
return jsonify(message="Account deleted successfully")
return jsonify(error="Account not found"), 404

0 comments on commit c6dbf1d

Please sign in to comment.