23a31f7c00
- Add silent WeChat login for MP/browser environments - Fix Python 3.6 compatibility (remove typing.Annotated usage) - Marketing page: tab-based content generation with category support - Translate page: add auto-detect language default - Homepage: add TTS playback, announcement ticker, remove redundant quick-actions - Fix FAB button overlap with custom tabbar on customers/quotation pages - Make openai/anthropic imports lazy for Python 3.6 compat
73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from app.database import get_db
|
|
from app.services.analytics import AnalyticsService
|
|
from app.api.v1.deps import get_current_user_id
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/customers")
|
|
async def customer_analytics(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
return await service.get_customer_stats(user_id)
|
|
|
|
|
|
@router.get("/translations")
|
|
async def translation_analytics(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
return await service.get_translation_stats(user_id)
|
|
|
|
|
|
@router.get("/quotations")
|
|
async def quotation_analytics(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
return await service.get_quotation_stats(user_id)
|
|
|
|
|
|
@router.get("/messages")
|
|
async def message_analytics(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
return await service.get_message_stats(user_id)
|
|
|
|
|
|
@router.get("/overview")
|
|
async def overview(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
customers = await service.get_customer_stats(user_id)
|
|
translations = await service.get_translation_stats(user_id)
|
|
quotations = await service.get_quotation_stats(user_id)
|
|
messages = await service.get_message_stats(user_id)
|
|
marketing = await service.get_marketing_stats(user_id)
|
|
return {
|
|
"customers": customers,
|
|
"translations": translations,
|
|
"quotations": quotations,
|
|
"messages": messages,
|
|
"marketing": marketing,
|
|
}
|
|
|
|
|
|
@router.get("/marketing")
|
|
async def marketing_analytics(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
service = AnalyticsService(db)
|
|
return await service.get_marketing_stats(user_id)
|