fix: add Pydantic models for customer/inventory endpoints and align JS rules
- Add Pydantic response models for vendor customer endpoints - Add InventoryMessageResponse for delete endpoint - Align JS rule IDs between YAML and validation script (JS-001=logger, JS-002=apiClient) - Add exception for init-*.js files in console logging check 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -432,6 +432,8 @@ javascript_rules:
|
|||||||
exceptions:
|
exceptions:
|
||||||
- "// eslint-disable"
|
- "// eslint-disable"
|
||||||
- "console.log('✅" # Bootstrap messages allowed
|
- "console.log('✅" # Bootstrap messages allowed
|
||||||
|
auto_exclude_files:
|
||||||
|
- "init-*.js" # Init files run before logger is available
|
||||||
|
|
||||||
- id: "JS-002"
|
- id: "JS-002"
|
||||||
name: "Use lowercase apiClient for API calls"
|
name: "Use lowercase apiClient for API calls"
|
||||||
|
|||||||
58
app/api/v1/vendor/customers.py
vendored
58
app/api/v1/vendor/customers.py
vendored
@@ -15,12 +15,20 @@ from app.api.deps import get_current_vendor_api
|
|||||||
from app.core.database import get_db
|
from app.core.database import get_db
|
||||||
from app.services.vendor_service import vendor_service
|
from app.services.vendor_service import vendor_service
|
||||||
from models.database.user import User
|
from models.database.user import User
|
||||||
|
from models.schema.customer import (
|
||||||
|
CustomerDetailResponse,
|
||||||
|
CustomerMessageResponse,
|
||||||
|
CustomerOrdersResponse,
|
||||||
|
CustomerStatisticsResponse,
|
||||||
|
CustomerUpdate,
|
||||||
|
VendorCustomerListResponse,
|
||||||
|
)
|
||||||
|
|
||||||
router = APIRouter(prefix="/customers")
|
router = APIRouter(prefix="/customers")
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=VendorCustomerListResponse)
|
||||||
def get_vendor_customers(
|
def get_vendor_customers(
|
||||||
skip: int = Query(0, ge=0),
|
skip: int = Query(0, ge=0),
|
||||||
limit: int = Query(100, ge=1, le=1000),
|
limit: int = Query(100, ge=1, le=1000),
|
||||||
@@ -39,16 +47,16 @@ def get_vendor_customers(
|
|||||||
- Return paginated results
|
- Return paginated results
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {
|
return VendorCustomerListResponse(
|
||||||
"customers": [],
|
customers=[],
|
||||||
"total": 0,
|
total=0,
|
||||||
"skip": skip,
|
skip=skip,
|
||||||
"limit": limit,
|
limit=limit,
|
||||||
"message": "Customer management coming in Slice 4",
|
message="Customer management coming in Slice 4",
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{customer_id}")
|
@router.get("/{customer_id}", response_model=CustomerDetailResponse)
|
||||||
def get_customer_details(
|
def get_customer_details(
|
||||||
customer_id: int,
|
customer_id: int,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
@@ -64,10 +72,10 @@ def get_customer_details(
|
|||||||
- Include total spent, etc.
|
- Include total spent, etc.
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {"message": "Customer details coming in Slice 4"}
|
return CustomerDetailResponse(message="Customer details coming in Slice 4")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{customer_id}/orders")
|
@router.get("/{customer_id}/orders", response_model=CustomerOrdersResponse)
|
||||||
def get_customer_orders(
|
def get_customer_orders(
|
||||||
customer_id: int,
|
customer_id: int,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
@@ -82,13 +90,13 @@ def get_customer_orders(
|
|||||||
- Return order details
|
- Return order details
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {"orders": [], "message": "Customer orders coming in Slice 5"}
|
return CustomerOrdersResponse(orders=[], message="Customer orders coming in Slice 5")
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{customer_id}")
|
@router.put("/{customer_id}", response_model=CustomerMessageResponse)
|
||||||
def update_customer(
|
def update_customer(
|
||||||
customer_id: int,
|
customer_id: int,
|
||||||
customer_data: dict,
|
customer_data: CustomerUpdate,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
@@ -101,10 +109,10 @@ def update_customer(
|
|||||||
- Update customer preferences
|
- Update customer preferences
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {"message": "Customer update coming in Slice 4"}
|
return CustomerMessageResponse(message="Customer update coming in Slice 4")
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{customer_id}/status")
|
@router.put("/{customer_id}/status", response_model=CustomerMessageResponse)
|
||||||
def toggle_customer_status(
|
def toggle_customer_status(
|
||||||
customer_id: int,
|
customer_id: int,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
@@ -119,10 +127,10 @@ def toggle_customer_status(
|
|||||||
- Log the change
|
- Log the change
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {"message": "Customer status toggle coming in Slice 4"}
|
return CustomerMessageResponse(message="Customer status toggle coming in Slice 4")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{customer_id}/stats")
|
@router.get("/{customer_id}/stats", response_model=CustomerStatisticsResponse)
|
||||||
def get_customer_statistics(
|
def get_customer_statistics(
|
||||||
customer_id: int,
|
customer_id: int,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
@@ -138,10 +146,10 @@ def get_customer_statistics(
|
|||||||
- Last order date
|
- Last order date
|
||||||
"""
|
"""
|
||||||
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id) # noqa: F841
|
||||||
return {
|
return CustomerStatisticsResponse(
|
||||||
"total_orders": 0,
|
total_orders=0,
|
||||||
"total_spent": 0.0,
|
total_spent=0.0,
|
||||||
"average_order_value": 0.0,
|
average_order_value=0.0,
|
||||||
"last_order_date": None,
|
last_order_date=None,
|
||||||
"message": "Customer statistics coming in Slice 4",
|
message="Customer statistics coming in Slice 4",
|
||||||
}
|
)
|
||||||
|
|||||||
5
app/api/v1/vendor/inventory.py
vendored
5
app/api/v1/vendor/inventory.py
vendored
@@ -18,6 +18,7 @@ from models.schema.inventory import (
|
|||||||
InventoryAdjust,
|
InventoryAdjust,
|
||||||
InventoryCreate,
|
InventoryCreate,
|
||||||
InventoryListResponse,
|
InventoryListResponse,
|
||||||
|
InventoryMessageResponse,
|
||||||
InventoryReserve,
|
InventoryReserve,
|
||||||
InventoryResponse,
|
InventoryResponse,
|
||||||
InventoryUpdate,
|
InventoryUpdate,
|
||||||
@@ -123,7 +124,7 @@ def update_inventory(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/inventory/{inventory_id}")
|
@router.delete("/inventory/{inventory_id}", response_model=InventoryMessageResponse)
|
||||||
def delete_inventory(
|
def delete_inventory(
|
||||||
inventory_id: int,
|
inventory_id: int,
|
||||||
current_user: User = Depends(get_current_vendor_api),
|
current_user: User = Depends(get_current_vendor_api),
|
||||||
@@ -131,4 +132,4 @@ def delete_inventory(
|
|||||||
):
|
):
|
||||||
"""Delete inventory entry."""
|
"""Delete inventory entry."""
|
||||||
inventory_service.delete_inventory(db, current_user.token_vendor_id, inventory_id)
|
inventory_service.delete_inventory(db, current_user.token_vendor_id, inventory_id)
|
||||||
return {"message": "Inventory deleted successfully"}
|
return InventoryMessageResponse(message="Inventory deleted successfully")
|
||||||
|
|||||||
@@ -172,3 +172,74 @@ class CustomerPreferencesUpdate(BaseModel):
|
|||||||
language: str | None = Field(None, max_length=10)
|
language: str | None = Field(None, max_length=10)
|
||||||
currency: str | None = Field(None, max_length=3)
|
currency: str | None = Field(None, max_length=3)
|
||||||
notification_preferences: dict[str, bool] | None = None
|
notification_preferences: dict[str, bool] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Vendor Customer Management Response Schemas
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerMessageResponse(BaseModel):
|
||||||
|
"""Simple message response for customer operations."""
|
||||||
|
|
||||||
|
message: str
|
||||||
|
|
||||||
|
|
||||||
|
class VendorCustomerListResponse(BaseModel):
|
||||||
|
"""Schema for vendor customer list with skip/limit pagination."""
|
||||||
|
|
||||||
|
customers: list[CustomerResponse] = []
|
||||||
|
total: int = 0
|
||||||
|
skip: int = 0
|
||||||
|
limit: int = 100
|
||||||
|
message: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerDetailResponse(BaseModel):
|
||||||
|
"""Detailed customer response for vendor management."""
|
||||||
|
|
||||||
|
id: int | None = None
|
||||||
|
vendor_id: int | None = None
|
||||||
|
email: str | None = None
|
||||||
|
first_name: str | None = None
|
||||||
|
last_name: str | None = None
|
||||||
|
phone: str | None = None
|
||||||
|
customer_number: str | None = None
|
||||||
|
marketing_consent: bool | None = None
|
||||||
|
last_order_date: datetime | None = None
|
||||||
|
total_orders: int | None = None
|
||||||
|
total_spent: Decimal | None = None
|
||||||
|
is_active: bool | None = None
|
||||||
|
created_at: datetime | None = None
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
message: str | None = None
|
||||||
|
|
||||||
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerOrderInfo(BaseModel):
|
||||||
|
"""Basic order info for customer order history."""
|
||||||
|
|
||||||
|
id: int
|
||||||
|
order_number: str
|
||||||
|
status: str
|
||||||
|
total: Decimal
|
||||||
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerOrdersResponse(BaseModel):
|
||||||
|
"""Response for customer order history."""
|
||||||
|
|
||||||
|
orders: list[CustomerOrderInfo] = []
|
||||||
|
total: int = 0
|
||||||
|
message: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerStatisticsResponse(BaseModel):
|
||||||
|
"""Response for customer statistics."""
|
||||||
|
|
||||||
|
total_orders: int = 0
|
||||||
|
total_spent: float = 0.0
|
||||||
|
average_order_value: float = 0.0
|
||||||
|
last_order_date: datetime | None = None
|
||||||
|
message: str | None = None
|
||||||
|
|||||||
@@ -82,3 +82,9 @@ class InventoryListResponse(BaseModel):
|
|||||||
total: int
|
total: int
|
||||||
skip: int
|
skip: int
|
||||||
limit: int
|
limit: int
|
||||||
|
|
||||||
|
|
||||||
|
class InventoryMessageResponse(BaseModel):
|
||||||
|
"""Simple message response for inventory operations."""
|
||||||
|
|
||||||
|
message: str
|
||||||
|
|||||||
@@ -334,14 +334,32 @@ class ArchitectureValidator:
|
|||||||
"""Validate a single JavaScript file"""
|
"""Validate a single JavaScript file"""
|
||||||
print("🟨 Validating JavaScript...")
|
print("🟨 Validating JavaScript...")
|
||||||
|
|
||||||
# JS-001: Check for window.apiClient
|
# JS-001: Check for console usage (must use centralized logger)
|
||||||
|
# Skip init-*.js files - they run before logger is available
|
||||||
|
if not file_path.name.startswith("init-"):
|
||||||
|
for i, line in enumerate(lines, 1):
|
||||||
|
if re.search(r"console\.(log|warn|error)", line):
|
||||||
|
if "//" in line or "✅" in line or "eslint-disable" in line:
|
||||||
|
continue
|
||||||
|
self._add_violation(
|
||||||
|
rule_id="JS-001",
|
||||||
|
rule_name="Use centralized logger",
|
||||||
|
severity=Severity.WARNING,
|
||||||
|
file_path=file_path,
|
||||||
|
line_number=i,
|
||||||
|
message="Use centralized logger instead of console",
|
||||||
|
context=line.strip()[:80],
|
||||||
|
suggestion="Use window.LogConfig.createLogger('moduleName')",
|
||||||
|
)
|
||||||
|
|
||||||
|
# JS-002: Check for window.apiClient (must use lowercase apiClient)
|
||||||
for i, line in enumerate(lines, 1):
|
for i, line in enumerate(lines, 1):
|
||||||
if "window.apiClient" in line:
|
if "window.apiClient" in line:
|
||||||
before_occurrence = line[: line.find("window.apiClient")]
|
before_occurrence = line[: line.find("window.apiClient")]
|
||||||
if "//" not in before_occurrence:
|
if "//" not in before_occurrence:
|
||||||
self._add_violation(
|
self._add_violation(
|
||||||
rule_id="JS-001",
|
rule_id="JS-002",
|
||||||
rule_name="Use apiClient directly",
|
rule_name="Use lowercase apiClient",
|
||||||
severity=Severity.WARNING,
|
severity=Severity.WARNING,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
line_number=i,
|
line_number=i,
|
||||||
@@ -350,22 +368,6 @@ class ArchitectureValidator:
|
|||||||
suggestion="Replace window.apiClient with apiClient",
|
suggestion="Replace window.apiClient with apiClient",
|
||||||
)
|
)
|
||||||
|
|
||||||
# JS-002: Check for console usage
|
|
||||||
for i, line in enumerate(lines, 1):
|
|
||||||
if re.search(r"console\.(log|warn|error)", line):
|
|
||||||
if "//" in line or "✅" in line or "eslint-disable" in line:
|
|
||||||
continue
|
|
||||||
self._add_violation(
|
|
||||||
rule_id="JS-002",
|
|
||||||
rule_name="Use centralized logger",
|
|
||||||
severity=Severity.WARNING,
|
|
||||||
file_path=file_path,
|
|
||||||
line_number=i,
|
|
||||||
message="Use centralized logger instead of console",
|
|
||||||
context=line.strip()[:80],
|
|
||||||
suggestion="Use window.LogConfig.createLogger('moduleName')",
|
|
||||||
)
|
|
||||||
|
|
||||||
def _validate_html_file(self, file_path: Path, content: str, lines: list[str]):
|
def _validate_html_file(self, file_path: Path, content: str, lines: list[str]):
|
||||||
"""Validate a single HTML template file"""
|
"""Validate a single HTML template file"""
|
||||||
print("📄 Validating template...")
|
print("📄 Validating template...")
|
||||||
@@ -870,15 +872,35 @@ class ArchitectureValidator:
|
|||||||
content = file_path.read_text()
|
content = file_path.read_text()
|
||||||
lines = content.split("\n")
|
lines = content.split("\n")
|
||||||
|
|
||||||
# JS-001: Check for window.apiClient
|
# JS-001: Check for console usage (must use centralized logger)
|
||||||
|
# Skip init-*.js files - they run before logger is available
|
||||||
|
if not file_path.name.startswith("init-"):
|
||||||
|
for i, line in enumerate(lines, 1):
|
||||||
|
if re.search(r"console\.(log|warn|error)", line):
|
||||||
|
# Skip if it's a comment or bootstrap message
|
||||||
|
if "//" in line or "✅" in line or "eslint-disable" in line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self._add_violation(
|
||||||
|
rule_id="JS-001",
|
||||||
|
rule_name="Use centralized logger",
|
||||||
|
severity=Severity.WARNING,
|
||||||
|
file_path=file_path,
|
||||||
|
line_number=i,
|
||||||
|
message="Use centralized logger instead of console",
|
||||||
|
context=line.strip()[:80],
|
||||||
|
suggestion="Use window.LogConfig.createLogger('moduleName')",
|
||||||
|
)
|
||||||
|
|
||||||
|
# JS-002: Check for window.apiClient (must use lowercase apiClient)
|
||||||
for i, line in enumerate(lines, 1):
|
for i, line in enumerate(lines, 1):
|
||||||
if "window.apiClient" in line:
|
if "window.apiClient" in line:
|
||||||
# Check if it's not in a comment
|
# Check if it's not in a comment
|
||||||
before_occurrence = line[: line.find("window.apiClient")]
|
before_occurrence = line[: line.find("window.apiClient")]
|
||||||
if "//" not in before_occurrence:
|
if "//" not in before_occurrence:
|
||||||
self._add_violation(
|
self._add_violation(
|
||||||
rule_id="JS-001",
|
rule_id="JS-002",
|
||||||
rule_name="Use apiClient directly",
|
rule_name="Use lowercase apiClient",
|
||||||
severity=Severity.WARNING,
|
severity=Severity.WARNING,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
line_number=i,
|
line_number=i,
|
||||||
@@ -887,24 +909,6 @@ class ArchitectureValidator:
|
|||||||
suggestion="Replace window.apiClient with apiClient",
|
suggestion="Replace window.apiClient with apiClient",
|
||||||
)
|
)
|
||||||
|
|
||||||
# JS-002: Check for console usage
|
|
||||||
for i, line in enumerate(lines, 1):
|
|
||||||
if re.search(r"console\.(log|warn|error)", line):
|
|
||||||
# Skip if it's a comment or bootstrap message
|
|
||||||
if "//" in line or "✅" in line or "eslint-disable" in line:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self._add_violation(
|
|
||||||
rule_id="JS-002",
|
|
||||||
rule_name="Use centralized logger",
|
|
||||||
severity=Severity.WARNING,
|
|
||||||
file_path=file_path,
|
|
||||||
line_number=i,
|
|
||||||
message="Use centralized logger instead of console",
|
|
||||||
context=line.strip()[:80],
|
|
||||||
suggestion="Use window.LogConfig.createLogger('moduleName')",
|
|
||||||
)
|
|
||||||
|
|
||||||
def _validate_templates(self, target_path: Path):
|
def _validate_templates(self, target_path: Path):
|
||||||
"""Validate template patterns"""
|
"""Validate template patterns"""
|
||||||
print("📄 Validating templates...")
|
print("📄 Validating templates...")
|
||||||
|
|||||||
Reference in New Issue
Block a user