
- Set up project structure and FastAPI application - Create database models for users, products, and inventory - Configure SQLAlchemy and Alembic for database management - Implement JWT authentication - Create API endpoints for user, product, and inventory management - Add admin-only routes and authorization middleware - Add health check endpoint - Update README with documentation - Lint and fix code issues
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import enum
|
|
import uuid
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, Enum, String
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
"""Enum for user roles."""
|
|
ADMIN = "admin"
|
|
CUSTOMER = "customer"
|
|
STAFF = "staff"
|
|
|
|
|
|
class User(Base):
|
|
"""User model."""
|
|
__tablename__ = "users"
|
|
|
|
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
|
email = Column(String, unique=True, index=True, nullable=False)
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=False)
|
|
full_name = Column(String, nullable=True)
|
|
role = Column(Enum(UserRole), default=UserRole.CUSTOMER, nullable=False)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
# Audit timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) |