Spaces:
Sleeping
Sleeping
Download src/models/product.py from hashir-qt/keyvault-api: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/spaces/hashir-qt/keyvault-api/resolve/main/src/models/product.py
- Command line
-
hf download hf://spaces/hashir-qt/keyvault-api/src/models/product.py
-
curl -L -o product.py https://huggingface.co/spaces/hashir-qt/keyvault-api/resolve/main/src/models/product.py
2.86 kB
| import uuid | |
| from datetime import datetime, timezone | |
| from enum import Enum | |
| from typing import List, Optional | |
| from sqlalchemy import Column, DateTime, JSON | |
| from sqlmodel import Field, SQLModel | |
| class ProductCategory(str, Enum): | |
| """Type/category of the digital product.""" | |
| GAME_KEY = "game_key" | |
| GIFT_CARD = "gift_card" | |
| SUBSCRIPTION = "subscription" | |
| IN_GAME_CURRENCY = "in_game_currency" | |
| class ProductStatus(str, Enum): | |
| """Visibility/availability status of a product listing.""" | |
| ACTIVE = "active" | |
| INACTIVE = "inactive" | |
| OUT_OF_STOCK = "out_of_stock" | |
| class ProductListing(SQLModel, table=True): | |
| """A product listed for sale by a seller.""" | |
| __tablename__ = "product_listings" | |
| id: str = Field( | |
| default_factory=lambda: str(uuid.uuid4()), | |
| primary_key=True, | |
| ) | |
| seller_id: str = Field(foreign_key="seller_profiles.id", index=True) | |
| title: str = Field(index=True) | |
| description: str | |
| price: float # USD sale price | |
| original_price: Optional[float] = Field(default=None) # for strikethrough display | |
| platform: str # Steam, PlayStation, Xbox, Nintendo, PC, Other | |
| region: str = Field(default="Global") # Global, US, EU, ASIA, etc. | |
| category: ProductCategory | |
| image_url: Optional[str] = Field(default=None) | |
| activation_steps: Optional[List[str]] = Field( | |
| default=None, | |
| sa_column=Column(JSON, nullable=True), | |
| ) | |
| is_flash_deal: bool = Field(default=False) | |
| status: ProductStatus = Field(default=ProductStatus.ACTIVE) | |
| stock_count: int = Field(default=0) | |
| total_sold: int = Field(default=0) | |
| created_at: datetime = Field( | |
| default_factory=lambda: datetime.now(timezone.utc), | |
| sa_column=Column(DateTime(timezone=True), nullable=False), | |
| ) | |
| updated_at: datetime = Field( | |
| default_factory=lambda: datetime.now(timezone.utc), | |
| sa_column=Column(DateTime(timezone=True), nullable=False), | |
| ) | |
| class ProductKey(SQLModel, table=True): | |
| """An individual encrypted product/game key attached to a listing.""" | |
| __tablename__ = "product_keys" | |
| id: str = Field( | |
| default_factory=lambda: str(uuid.uuid4()), | |
| primary_key=True, | |
| ) | |
| product_id: str = Field(foreign_key="product_listings.id", index=True) | |
| encrypted_key: str # Fernet-encrypted raw key | |
| is_sold: bool = Field(default=False) | |
| sold_at: Optional[datetime] = Field( | |
| default=None, | |
| sa_column=Column(DateTime(timezone=True), nullable=True), | |
| ) | |
| order_item_id: Optional[str] = Field(default=None) # FK to order_items (Phase 4) | |
| created_at: datetime = Field( | |
| default_factory=lambda: datetime.now(timezone.utc), | |
| sa_column=Column(DateTime(timezone=True), nullable=False), | |
| ) | |