[rewrite] Added poetry, and models for new database
This commit is contained in:
1 parent
3d00ae0aad
commit
807d23da51
11 files changed
+990
-148
No files matched your search
@@ -0,0 +1,5 @@
|
||||
from .user_model import *
|
||||
|
||||
__all__ = [
|
||||
*user_model.__all__
|
||||
]
|
||||
@@ -0,0 +1,5 @@
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
__all__ = ["Base"]
|
||||
@@ -1,63 +1,16 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import ForeignKey, Column, Integer, TIMESTAMP, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
class Cart:
|
||||
"""
|
||||
Represents a cart in the system.
|
||||
from .base_model import Base
|
||||
|
||||
:param id: The unique identifier of the cart.
|
||||
:type id: int
|
||||
:param price_total: The total price of the cart.
|
||||
:type price_total: float
|
||||
:param item_count: The count of items in the cart.
|
||||
:type item_count: int
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
cart_id: int = None,
|
||||
price_total: float = 0.00,
|
||||
item_count: int = 0,
|
||||
):
|
||||
self.id = cart_id
|
||||
self.price_total = price_total
|
||||
self.item_count = item_count
|
||||
class Cart(Base):
|
||||
__tablename__ = 'cart'
|
||||
|
||||
def __repr__(self):
|
||||
return f"Cart(id={self.id}, price_total={self.price_total}, item_count={self.item_count})"
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey('user.id'), nullable=False)
|
||||
total = Column(Float, nullable=False)
|
||||
last_updated = Column(TIMESTAMP)
|
||||
|
||||
class CartItem:
|
||||
"""
|
||||
Represents a cart item in the system.
|
||||
|
||||
:param id: The unique identifier of the cart item.
|
||||
:type id: int
|
||||
:param cart_id: The identifier of the cart.
|
||||
:type cart_id: int
|
||||
:param product_id: The identifier of the product.
|
||||
:type product_id: int
|
||||
:param count: The count of the product in the cart.
|
||||
:type count: int
|
||||
:param price_subtotal: The subtotal price of the product in the cart.
|
||||
:type price_subtotal: float
|
||||
:param date_added: The date and time when the item was added to the cart.
|
||||
:type date_added: datetime
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
cart_item_id: int = None,
|
||||
cart_id: int = None,
|
||||
product_id: int = None,
|
||||
count: int = 0,
|
||||
price_subtotal: float = 0.00,
|
||||
date_added: datetime = None,
|
||||
):
|
||||
self.id = cart_item_id
|
||||
self.cart_id = cart_id
|
||||
self.product_id = product_id
|
||||
self.count = count
|
||||
self.price_subtotal = price_subtotal
|
||||
self.date_added = date_added or datetime.now()
|
||||
|
||||
def __repr__(self):
|
||||
return f"CartItem(id={self.id}, cart_id={self.cart_id}, product_id={self.product_id}, count={self.count}, price_subtotal={self.price_subtotal}, date_added={self.date_added})"
|
||||
user = relationship('User', back_populates='carts')
|
||||
entries = relationship('CartEntry', back_populates='cart')
|
||||
@@ -1,38 +0,0 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class Product:
|
||||
"""
|
||||
Represents a product in the system.
|
||||
|
||||
:param id: The unique identifier of the product.
|
||||
:type id: int
|
||||
:param seller_id: The user ID of the seller.
|
||||
:type seller_id: int
|
||||
:param name: The name of the product.
|
||||
:type name: str
|
||||
:param price: The price of the product.
|
||||
:type price: Decimal
|
||||
:param creation_date: The date and time when the product was created.
|
||||
:type creation_date: datetime
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
product_id: int = None,
|
||||
seller_id: int = None,
|
||||
seller_name: str = None,
|
||||
name: str = None,
|
||||
price: Decimal = None,
|
||||
creation_date: datetime = None,
|
||||
):
|
||||
self.product_id = product_id
|
||||
self.seller_id = seller_id
|
||||
self.seller_name = seller_name
|
||||
self.name = name
|
||||
self.price = price
|
||||
self.creation_date = creation_date
|
||||
|
||||
def __repr__(self):
|
||||
return f"Product(product_id={self.product_id}, seller_id={self.seller_id}, seller_name={self.seller_name}, name='{self.name}', price={self.price}, creation_date={self.creation_date!r})"
|
||||
@@ -0,0 +1,26 @@
|
||||
from sqlalchemy import ForeignKey, Column, Integer, JSON, TIMESTAMP, String, Enum, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .base_model import Base
|
||||
|
||||
|
||||
class Shop(Base):
|
||||
__tablename__ = 'shop'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
owner_id = Column(Integer, ForeignKey('user.id'), nullable=False)
|
||||
name = Column(String(100), unique=True, nullable=False)
|
||||
description = Column(String(500), nullable=False)
|
||||
created_at = Column(TIMESTAMP, default='CURRENT_TIMESTAMP')
|
||||
updated_at = Column(TIMESTAMP, default='CURRENT_TIMESTAMP')
|
||||
status = Column(Enum('active', 'inactive', 'suspended'), nullable=False)
|
||||
logo = Column(String(100))
|
||||
contact_email = Column(String(128), unique=True, nullable=False)
|
||||
phone_number = Column(String(15), nullable=False)
|
||||
address = Column(Text, nullable=False)
|
||||
currency = Column(String(3), nullable=False)
|
||||
business_hours = Column(JSON, nullable=False)
|
||||
links = Column(JSON, nullable=False)
|
||||
|
||||
users = relationship('User', back_populates='shop')
|
||||
products = relationship('Product', back_populates='shop')
|
||||
@@ -1,44 +1,32 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import ForeignKey, Column, Integer, JSON, TIMESTAMP, String, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .base_model import Base
|
||||
|
||||
|
||||
class User:
|
||||
"""
|
||||
Represents a user in the system.
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
|
||||
:param user_id: The unique identifier of the user.
|
||||
:type user_id: int
|
||||
:param username: The username of the user.
|
||||
:type username: str
|
||||
:param displayname: The display name of the user.
|
||||
:type displayname: str
|
||||
:param email: The email address of the user.
|
||||
:type email: str
|
||||
:param password: The hashed password of the user.
|
||||
:type password: str
|
||||
:param role_id: The role ID of the user. Defaults to 1.
|
||||
:type role_id: int
|
||||
:param creation_date: The date and time when the user was created.
|
||||
:type creation_date: datetime
|
||||
|
||||
"""
|
||||
id = Column(Integer, primary_key=True)
|
||||
shop_id = Column(Integer, ForeignKey("shop.id"), nullable=True)
|
||||
username = Column(String(64), unique=True, nullable=False)
|
||||
email = Column(String(128), unique=True, nullable=False)
|
||||
password = Column(String(60), nullable=False)
|
||||
role = Column(Enum("customer", "employee", "manager", "owner", "admin", name="user_role"), nullable=False, default="customer")
|
||||
first_name = Column(String(64), nullable=True)
|
||||
last_name = Column(String(64), nullable=True)
|
||||
phone_number = Column(String(15), nullable=True)
|
||||
created_at = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True)
|
||||
updated_at = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True)
|
||||
last_login = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True)
|
||||
profile_picture = Column(String(100), nullable=True)
|
||||
preferences = Column(JSON, nullable=True)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
user_id: str = None,
|
||||
username: str = None,
|
||||
displayname: str = None,
|
||||
email: str = None,
|
||||
password: str = None,
|
||||
role_id: int = 1,
|
||||
creation_date: datetime = None,
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.username = username
|
||||
self.displayname = displayname
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.role_id = role_id
|
||||
self.creation_date = creation_date
|
||||
shop = relationship("Shop", back_populates="users")
|
||||
carts = relationship("Cart", back_populates="user")
|
||||
purchases = relationship("Purchase", back_populates="user")
|
||||
statistics = relationship("UserStatistics", back_populates="user")
|
||||
wishlists = relationship("Wishlist", back_populates="user")
|
||||
|
||||
def __repr__(self):
|
||||
return f"User(id={self.user_id}, username={self.username}, displayname={self.displayname}, email={self.email}, password={self.password}, role_id={self.role_id}, creation_date={self.creation_date})"
|
||||
|
||||
__all__ = ["User"]
|
||||
Reference in new issue
Block a user