-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7d8add
commit 26ffd32
Showing
20 changed files
with
129 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
from app import db | ||
import uuid | ||
from app import db | ||
|
||
class Base(db.Model): | ||
""" | ||
Base represents the base table in the database. | ||
Attributes: | ||
id (str): The ID of the base. | ||
created_at (datetime): The date and time the base was created. | ||
updated_at (datetime): The date and time the base was last updated. | ||
""" | ||
|
||
__abstract__ = True | ||
|
||
id = db.Column('id', db.Text, default=lambda: str(uuid.uuid4()), primary_key=True) | ||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp()) | ||
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) | ||
|
||
def save(self): | ||
""" | ||
Save the Base instance to the database. | ||
""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
""" | ||
Delete the Base instance from the database. | ||
""" | ||
db.session.delete(self) | ||
db.session.commit() | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,84 @@ | ||
from app import db | ||
from api.base.models import Base | ||
|
||
|
||
class TransactionModel(Base): | ||
""" | ||
TransactionModel represents the transaction table in the database. | ||
Attributes: | ||
user_id (str): The ID of the user associated with the transaction. | ||
categories_id (str): The ID of the category associated with the transaction. | ||
account_id (str): The ID of the account associated with the transaction. | ||
amount (float): The amount of the transaction. | ||
type (str): The type of the transaction. | ||
external_id (str): The external ID of the transaction. | ||
""" | ||
|
||
__tablename__ = 'transaction' | ||
user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) | ||
categories_id = db.Column('categories_id', db.Text, db.ForeignKey('categories.id'), nullable=False) | ||
account_id = db.Column('account_id', db.Text, db.ForeignKey('account.id'), nullable=False) | ||
amount = db.Column(db.Float, nullable=False) | ||
transaction_type = db.Column(db.String(255), nullable=False) | ||
external_id = db.Column(db.String(255), nullable=False) | ||
|
||
def __init__(self, user_id, categories_id, account_id, amount, transaction_type, external_id): | ||
""" | ||
Initialize a TransactionModel instance. | ||
def __init__(self, user_id, categories_id, account_id, amount, transaction_type): | ||
Args: | ||
user_id (str): The ID of the user associated with the transaction. | ||
categories_id (str): The ID of the category associated with the transaction. | ||
account_id (str): The ID of the account associated with the transaction. | ||
amount (float): The amount of the transaction. | ||
transaction_type (str): The transaction_type of the transaction. | ||
external_id (str): The external ID of the transaction. | ||
""" | ||
self.user_id = user_id | ||
self.categories_id = categories_id | ||
self.account_id = account_id | ||
self.amount = amount | ||
self.transaction_type = transaction_type | ||
self.external_id = external_id | ||
|
||
def __repr__(self): | ||
return '<Transaction %r>' % self.id | ||
|
||
""" | ||
Return a string representation of the TransactionModel instance. | ||
Returns: | ||
str: String representation of the transaction. | ||
""" | ||
return f'<Transaction {self.id!r}>' | ||
|
||
def to_dict(self): | ||
""" | ||
Convert the TransactionModel instance to a dictionary. | ||
Returns: | ||
dict: Dictionary representation of the transaction. | ||
""" | ||
return { | ||
'id': self.id, | ||
'user_id': self.user_id, | ||
'categories_id': self.categories_id, | ||
'account_id': self.account_id, | ||
'amount': self.amount, | ||
'transaction_type': self.transaction_type, | ||
'external_id': self.external_id, | ||
'created_at': self.created_at, | ||
'updated_at': self.updated_at | ||
} | ||
|
||
def save(self): | ||
""" | ||
Save the TransactionModel instance to the database. | ||
""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
""" | ||
Delete the TransactionModel instance from the database. | ||
""" | ||
db.session.delete(self) | ||
db.session.commit() | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
db = SQLAlchemy() | ||
db = SQLAlchemy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
app = create_app() | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
app.run(debug=True) |
Oops, something went wrong.