52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
小程序客户路由 —— 客户详情(CUST-1)、客户服务记录(CUST-2)。
|
||
|
||
端点清单:
|
||
- GET /api/xcx/customers/{customer_id} — 客户详情(CUST-1)
|
||
- GET /api/xcx/customers/{customer_id}/records — 客户服务记录(CUST-2)
|
||
|
||
所有端点均需 JWT(approved 状态)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from fastapi import APIRouter, Depends, Query
|
||
|
||
from app.auth.dependencies import CurrentUser
|
||
from app.middleware.permission import require_approved
|
||
from app.schemas.xcx_customers import (
|
||
CustomerDetailResponse,
|
||
CustomerRecordsResponse,
|
||
)
|
||
from app.services import customer_service
|
||
|
||
router = APIRouter(prefix="/api/xcx/customers", tags=["小程序客户"])
|
||
|
||
|
||
@router.get("/{customer_id}", response_model=CustomerDetailResponse)
|
||
async def get_customer_detail(
|
||
customer_id: int,
|
||
user: CurrentUser = Depends(require_approved()),
|
||
):
|
||
"""客户详情(CUST-1)。"""
|
||
return await customer_service.get_customer_detail(
|
||
customer_id, user.site_id
|
||
)
|
||
|
||
|
||
@router.get("/{customer_id}/records", response_model=CustomerRecordsResponse)
|
||
async def get_customer_records(
|
||
customer_id: int,
|
||
year: int = Query(...),
|
||
month: int = Query(..., ge=1, le=12),
|
||
table: str | None = Query(None),
|
||
page: int = Query(1, ge=1),
|
||
page_size: int = Query(20, ge=1, le=100),
|
||
user: CurrentUser = Depends(require_approved()),
|
||
):
|
||
"""客户服务记录(CUST-2)。"""
|
||
return await customer_service.get_customer_records(
|
||
customer_id, user.site_id, year, month, table, page, page_size
|
||
)
|