Spaces:
Sleeping
Sleeping
| from sqlalchemy import Column, String, Integer, Float, Boolean, ForeignKey | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from sqlalchemy.orm import relationship | |
| from backend.app.models.base import BaseDBModel | |
| class User(BaseDBModel): | |
| __tablename__ = "users" | |
| name = Column(String, nullable=False) | |
| phone = Column(String, unique=True, index=True, nullable=False) | |
| role = Column(String, index=True, nullable=False) # admin, customer, worker, mediator | |
| password_hash = Column(String, nullable=True) # can be null for demo OTP bypass | |
| city = Column(String, nullable=False, default="Jaipur") | |
| is_active = Column(Boolean, nullable=False, default=True) | |
| # Relationships | |
| worker_profile = relationship("WorkerProfile", back_populates="user", uselist=False, cascade="all, delete-orphan") | |
| customer_profile = relationship("CustomerProfile", back_populates="user", uselist=False, cascade="all, delete-orphan") | |
| notifications = relationship("Notification", back_populates="user", cascade="all, delete-orphan") | |
| wallet_transactions = relationship("WalletTransaction", back_populates="user", cascade="all, delete-orphan") | |
| roster_workers = relationship("RosterWorker", back_populates="mediator", cascade="all, delete-orphan") | |
| class WorkerProfile(BaseDBModel): | |
| __tablename__ = "worker_profiles" | |
| user_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), unique=True, index=True, nullable=False) | |
| skill = Column(String, index=True, nullable=False) # Mason, Electrician, Painter, etc. | |
| rate = Column(Integer, nullable=False) # Daily wage in INR | |
| rating = Column(Float, nullable=False, default=4.5) | |
| distance = Column(Float, nullable=False, default=1.5) # Simulated distance in km | |
| online = Column(Boolean, nullable=False, default=True) | |
| verified = Column(Boolean, nullable=False, default=False) # Aadhaar verified | |
| completed_jobs = Column(Integer, nullable=False, default=0) | |
| completion_rate = Column(Integer, nullable=False, default=90) # percentage | |
| map_x = Column(Integer, nullable=False, default=50) # Coordinate x on simulated map | |
| map_y = Column(Integer, nullable=False, default=50) # Coordinate y on simulated map | |
| # Relationships | |
| user = relationship("User", back_populates="worker_profile") | |
| class CustomerProfile(BaseDBModel): | |
| __tablename__ = "customer_profiles" | |
| user_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), unique=True, index=True, nullable=False) | |
| wallet_balance = Column(Integer, nullable=False, default=8200) | |
| # Relationships | |
| user = relationship("User", back_populates="customer_profile") | |