Skip to content

Commit

Permalink
馃殤 user is created if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoJ-A authored and SamuelGuillemet committed Feb 8, 2024
1 parent 6127472 commit e546dde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def init_example_data(self):
self.session.add_all([order1, order2])
self.session.commit()

def create_user(self, username):
user = self.session.query(User).filter_by(username=username).first()
if user is None:
user1 = User(username=username, balance=1000)
self.session.add(user1)
self.session.commit()

def get_user_balance(self, username):
user = self.session.query(User).filter_by(username=username).first()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, username, application, initiator):
# Initialize class attributes
self.database_manager = DatabaseManager("sqlite:///quickfix_client_database.db")
self.username = username
self.database_manager.create_user(username)
self.account_balance = self.database_manager.get_user_balance(self.username)
self.owned_shares = self.database_manager.get_user_shares(self.username)
self.application, self.initiator = application, initiator
Expand Down

0 comments on commit e546dde

Please sign in to comment.