diff --git a/iebank_api/models.py b/iebank_api/models.py index c56c8eb..049ebfa 100644 --- a/iebank_api/models.py +++ b/iebank_api/models.py @@ -8,15 +8,17 @@ class Account(db.Model): account_number = db.Column(db.String(20), nullable=False, unique=True) balance = db.Column(db.Float, nullable=False, default = 0.0) currency = db.Column(db.String(1), nullable=False, default="€") + country = db.Column(db.String(32), nullable=False, default="Spain") status = db.Column(db.String(10), nullable=False, default="Active") created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def __repr__(self): return '' % self.account_number - def __init__(self, name, currency): + def __init__(self, name, currency, country): self.name = name self.account_number = ''.join(random.choices(string.digits, k=20)) self.currency = currency self.balance = 0.0 - self.status = "Active" \ No newline at end of file + self.status = "Active" + self.country = country \ No newline at end of file diff --git a/iebank_api/routes.py b/iebank_api/routes.py index 0ff1b3b..203b055 100644 --- a/iebank_api/routes.py +++ b/iebank_api/routes.py @@ -32,8 +32,9 @@ def skull(): def create_account(): app.logger.debug('Route /accounts POST called') name = request.json['name'] + country = request.json['country'] currency = request.json['currency'] - account = Account(name, currency) + account = Account(name, currency, country) db.session.add(account) db.session.commit() return format_account(account) @@ -46,13 +47,13 @@ def get_accounts(): @app.route('/accounts/', methods=['GET']) def get_account(id): - app.logger.debug('Route /accounts GET called with id: ' + id) + app.logger.debug('Route /accounts GET called with id: ' + str(id)) account = Account.query.get(id) return format_account(account) @app.route('/accounts/', methods=['PUT']) def update_account(id): - app.logger.debug('Route /accounts PUT called with id: ' + id) + app.logger.debug('Route /accounts PUT called with id: ' + str(id)) account = Account.query.get(id) account.name = request.json['name'] db.session.commit() @@ -60,7 +61,7 @@ def update_account(id): @app.route('/accounts/', methods=['DELETE']) def delete_account(id): - app.logger.debug('Route /accounts DELETE called with id: ' + id) + app.logger.debug('Route /accounts DELETE called with id: ' + str(id)) account = Account.query.get(id) db.session.delete(account) db.session.commit() @@ -73,6 +74,7 @@ def format_account(account): 'account_number': account.account_number, 'balance': account.balance, 'currency': account.currency, + 'country': account.country, 'status': account.status, 'created_at': account.created_at } \ No newline at end of file