first
This commit is contained in:
46
app/api/v1/analytics.py
Normal file
46
app/api/v1/analytics.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# app/api/v1/analytics.py
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional
|
||||
|
||||
from app.api import deps
|
||||
from app.services.analytics_service import AnalyticsService
|
||||
from app.schemas.response import FormAnalyticsResponse
|
||||
|
||||
router = APIRouter(prefix="/analytics", tags=["analytics"])
|
||||
|
||||
@router.get("/forms/{form_id}/report", response_model=FormAnalyticsResponse)
|
||||
async def get_form_analytics(
|
||||
form_id: int,
|
||||
db: Session = Depends(deps.get_db),
|
||||
days: int = Query(30, ge=1, le=365)
|
||||
):
|
||||
"""Получить аналитику по форме"""
|
||||
service = AnalyticsService(db)
|
||||
try:
|
||||
report = service.get_form_report(form_id, days)
|
||||
return report
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
@router.get("/forms/{form_id}/fields/{field_name}/stats")
|
||||
async def get_field_statistics(
|
||||
form_id: int,
|
||||
field_name: str,
|
||||
db: Session = Depends(deps.get_db)
|
||||
):
|
||||
"""Получить статистику по полю формы"""
|
||||
service = AnalyticsService(db)
|
||||
stats = service.get_field_statistics(form_id, field_name)
|
||||
if stats is None:
|
||||
raise HTTPException(status_code=404, detail="Form or field not found")
|
||||
return stats
|
||||
|
||||
@router.get("/dashboard/overview")
|
||||
async def get_dashboard_overview(
|
||||
db: Session = Depends(deps.get_db),
|
||||
days: int = Query(30, ge=1, le=365)
|
||||
):
|
||||
"""Получить общую статистику по всем формам"""
|
||||
service = AnalyticsService(db)
|
||||
return service.get_global_overview(days)
|
||||
Reference in New Issue
Block a user