adding docstring to classes

This commit is contained in:
2025-11-10 19:41:52 +01:00
parent ede80f41ea
commit 971631f575

View File

@@ -1,40 +1,47 @@
from datetime import datetime # models/database/user.py
"""
User model with authentication support.
from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Index, This module defines the User model which includes fields for user details,
Integer, String, Text, UniqueConstraint) authentication information, and relationships to other models such as Vendor and Customer.
"""
from sqlalchemy import Boolean, Column, DateTime, Integer, String
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
# Import Base from the central database module instead of creating a new one # Import Base from the central database module instead of creating a new one
from app.core.database import Base from app.core.database import Base
from models.database.base import TimestampMixin from models.database.base import TimestampMixin
class User(Base, TimestampMixin):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True) class User(Base, TimestampMixin):
email = Column(String, unique=True, index=True, nullable=False) """Represents a user in the system."""
username = Column(String, unique=True, index=True, nullable=False)
first_name = Column(String) __tablename__ = "users" # Name of the table in the database
last_name = Column(String)
hashed_password = Column(String, nullable=False) id = Column(Integer, primary_key=True, index=True) # Primary key and indexed column for user ID
role = Column(String, nullable=False, default="user") # user, admin, vendor_owner TODO: Change to customer, vendor, admin? email = Column(String, unique=True, index=True, nullable=False) # Unique, indexed, non-nullable email column
is_active = Column(Boolean, default=True, nullable=False) username = Column(String, unique=True, index=True, nullable=False) # Unique, indexed, non-nullable username column
last_login = Column(DateTime, nullable=True) first_name = Column(String) # Optional first name column
last_name = Column(String) # Optional last name column
hashed_password = Column(String, nullable=False) # Non-nullable hashed password column
role = Column(String, nullable=False, default="user") # Role of the user (default is 'user') //TODO: Change to customer, vendor, admin
is_active = Column(Boolean, default=True, nullable=False) # Active status of the user (default is True)
last_login = Column(DateTime, nullable=True) # Optional last login timestamp column
# Relationships # Relationships
marketplace_import_jobs = relationship( marketplace_import_jobs = relationship("MarketplaceImportJob",
"MarketplaceImportJob", back_populates="user" back_populates="user") # Relationship with import jobs
) owned_vendors = relationship("Vendor", back_populates="owner") # Relationship with vendors owned by this user
vendor_memberships = relationship("VendorUser", foreign_keys="[VendorUser.user_id]",
# Vendor relationships back_populates="user") # Relationship with vendor memberships
owned_vendors = relationship("Vendor", back_populates="owner")
vendor_memberships = relationship("VendorUser", foreign_keys="[VendorUser.user_id]", back_populates="user")
def __repr__(self): def __repr__(self):
"""String representation of the User object."""
return f"<User(id={self.id}, username='{self.username}', email='{self.email}', role='{self.role}')>" return f"<User(id={self.id}, username='{self.username}', email='{self.email}', role='{self.role}')>"
@property @property
def full_name(self): def full_name(self):
"""Returns the full name of the user, combining first and last names if available."""
if self.first_name and self.last_name: if self.first_name and self.last_name:
return f"{self.first_name} {self.last_name}" return f"{self.first_name} {self.last_name}"
return self.username return self.username