Skip to content

Commit

Permalink
Add: Country column
Browse files Browse the repository at this point in the history
  • Loading branch information
alguadam committed Oct 8, 2023
1 parent 7f65c30 commit be75b09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions iebank_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<Event %r>' % 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"
self.status = "Active"
self.country = country
10 changes: 6 additions & 4 deletions iebank_api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -46,21 +47,21 @@ def get_accounts():

@app.route('/accounts/<int:id>', 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/<int:id>', 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()
return format_account(account)

@app.route('/accounts/<int:id>', 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()
Expand All @@ -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
}

0 comments on commit be75b09

Please sign in to comment.