Project structure and classes
Project structure and classes created and initialized
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
class Item:
|
||||||
|
def __init__(self, id, name, price) -> None:
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.price = float(price)
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return {"id": self.id, "name": self.name, "price": self.price}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(data):
|
||||||
|
return Item(data["id"], data["name"], data["price"])
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction:
|
||||||
|
def __init__(self, id, user_id, item_id, amount, timestamp=None) -> None:
|
||||||
|
self.id = id
|
||||||
|
self.user_id = user_id
|
||||||
|
self.item_id = item_id
|
||||||
|
self.amount = float(amount)
|
||||||
|
self.timestamp = timestamp or datetime.now().isoformat()
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"user_id": self.user_id,
|
||||||
|
"item_id": self.item_id,
|
||||||
|
"amount": self.amount,
|
||||||
|
"timestamp": self.timestamp,
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(data):
|
||||||
|
return Transaction(
|
||||||
|
data["id"],
|
||||||
|
data["user_id"],
|
||||||
|
data["item_id"],
|
||||||
|
data["amount"],
|
||||||
|
data["timestamp"],
|
||||||
|
)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
class User:
|
||||||
|
def __init__(self, id, name) -> None:
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.debt = 0.0
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return {"id": self.id, "name": self.name, "debt": self.debt}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(data):
|
||||||
|
user = User(data["id"], data["name"])
|
||||||
|
user.debt = data["debt"]
|
||||||
|
return user
|
||||||
Reference in New Issue
Block a user