fix: deliver validated AI insight responses

This commit is contained in:
2026-08-22 15:47:38 +08:00
parent ca55c2fb3d
commit 3fba4261ee
68 changed files with 6870 additions and 493 deletions

View File

@@ -18,6 +18,7 @@ import (
"unicode"
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/analytics"
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/coach"
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/identity"
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/insight"
)
@@ -39,6 +40,7 @@ type Server struct {
analytics *analytics.Service
growth growthReportService
insights insightService
coach *coach.Service
logger *slog.Logger
frontendOrigin string
cookieSecure bool
@@ -52,6 +54,8 @@ func (s *Server) WithInsights(service *insight.Service) *Server {
return s
}
func (s *Server) WithCoach(service *coach.Service) *Server { s.coach = service; return s }
type sessionKey struct{}
type tokenKey struct{}
@@ -83,8 +87,23 @@ func (s *Server) Handler() http.Handler {
mux.Handle("GET /api/v1/analytics/growth-reports/{reportId}/events", s.authenticate(http.HandlerFunc(s.growthReportEvents)))
mux.Handle("GET /api/v1/analytics/ai-insights/{module}", s.authenticate(http.HandlerFunc(s.latestAIInsight)))
mux.Handle("POST /api/v1/analytics/ai-insights/{module}/refreshes", s.authenticate(s.csrf(http.HandlerFunc(s.refreshAIInsight))))
mux.Handle("POST /api/v1/analytics/ai-insights/{module}/sections/{sectionId}/refreshes", s.authenticate(s.csrf(http.HandlerFunc(s.refreshAIInsightSection))))
mux.Handle("GET /api/v1/analytics/ai-insight-refreshes/{jobId}", s.authenticate(http.HandlerFunc(s.getAIInsightJob)))
mux.Handle("GET /api/v1/analytics/ai-insight-refreshes/{jobId}/events", s.authenticate(http.HandlerFunc(s.aiInsightEvents)))
mux.Handle("GET /api/v1/growth-coach", s.authenticate(http.HandlerFunc(s.growthCoachDashboard)))
mux.Handle("GET /api/v1/growth-coach/terminals/{terminalId}/profile", s.authenticate(http.HandlerFunc(s.growthCoachProfile)))
mux.Handle("PUT /api/v1/growth-coach/terminals/{terminalId}/profile", s.authenticate(s.csrf(http.HandlerFunc(s.saveGrowthCoachProfile))))
mux.Handle("POST /api/v1/growth-coach/terminals/{terminalId}/refreshes", s.authenticate(s.csrf(http.HandlerFunc(s.refreshGrowthCoach))))
mux.Handle("GET /api/v1/growth-coach/plans", s.authenticate(http.HandlerFunc(s.growthCoachPlans)))
mux.Handle("GET /api/v1/growth-coach/actions", s.authenticate(http.HandlerFunc(s.growthCoachActions)))
mux.Handle("GET /api/v1/growth-coach/goals", s.authenticate(http.HandlerFunc(s.growthCoachGoals)))
mux.Handle("POST /api/v1/growth-coach/goals/{goalId}/subtasks/{subtaskId}/transitions", s.authenticate(s.csrf(http.HandlerFunc(s.transitionGrowthCoachSubtask))))
mux.Handle("POST /api/v1/growth-coach/deadline-proposals/{proposalId}/decisions", s.authenticate(s.csrf(http.HandlerFunc(s.decideGrowthCoachDeadlineProposal))))
mux.Handle("POST /api/v1/growth-coach/recommendations/{id}/decisions", s.authenticate(s.csrf(http.HandlerFunc(s.decideGrowthCoachRecommendation))))
mux.Handle("POST /api/v1/growth-coach/actions/{id}/transitions", s.authenticate(s.csrf(http.HandlerFunc(s.transitionGrowthCoachAction))))
mux.Handle("POST /api/v1/growth-coach/difficulty-proposals/{id}/decisions", s.authenticate(s.csrf(http.HandlerFunc(s.decideGrowthCoachDifficulty))))
mux.Handle("GET /api/v1/growth-coach/refreshes/{jobId}", s.authenticate(http.HandlerFunc(s.growthCoachJob)))
mux.Handle("GET /api/v1/growth-coach/refreshes/{jobId}/events", s.authenticate(http.HandlerFunc(s.growthCoachEvents)))
return s.boundary(mux)
}