落地 synastry/star/ask API 与 H5 页面,补齐 cece-frontend-re complete-design 证据文档,并加入 Android 模拟器截图抓取脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
// Package httpserver wires HTTP routes for the 愈心谷 API.
|
|
package httpserver
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/config"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/handler"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/llm/deepseek"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/middleware"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/ask"
|
|
companionsvc "github.com/yuxingu/digital-psychology/apps/api/internal/service/companion"
|
|
imagecardsvc "github.com/yuxingu/digital-psychology/apps/api/internal/service/imagecard"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/profile"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/relation"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/report"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/scale"
|
|
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
|
)
|
|
|
|
// NewRouter builds the Gin engine with all /api/v1 routes.
|
|
func NewRouter(pool *pgxpool.Pool, cfg config.Config) *gin.Engine {
|
|
profileRepo := &repository.ProfileRepo{Pool: pool}
|
|
reportRepo := &repository.ReportRepo{Pool: pool}
|
|
relationRepo := &repository.RelationRepo{Pool: pool}
|
|
askRepo := &repository.AskRepo{Pool: pool}
|
|
|
|
var llm *deepseek.Client
|
|
if cfg.DeepSeek.Enabled() {
|
|
llm = deepseek.New(cfg.DeepSeek)
|
|
}
|
|
|
|
profileSvc := &profile.Service{Repo: profileRepo}
|
|
reportSvc := &report.Service{
|
|
Profiles: profileRepo,
|
|
Reports: reportRepo,
|
|
Invites: &repository.SynastryInviteRepo{Pool: pool},
|
|
}
|
|
relationSvc := &relation.Service{Profiles: profileRepo, Reports: reportRepo, Relations: relationRepo}
|
|
scaleSvc := &scale.Service{Repo: &repository.ScaleRepo{Pool: pool}, Profiles: profileRepo}
|
|
askSvc := &ask.Service{Profiles: profileRepo, Reports: reportRepo, Ask: askRepo, LLM: llm}
|
|
companionSvc := &companionsvc.Service{Moods: &repository.MoodRepo{Pool: pool}}
|
|
imageCardSvc := &imagecardsvc.Service{
|
|
Profiles: profileRepo,
|
|
Reports: reportRepo,
|
|
Quotas: &repository.ImageCardRepo{Pool: pool},
|
|
}
|
|
|
|
r := gin.New()
|
|
r.Use(gin.Recovery(), gin.Logger(), middleware.RequestID())
|
|
r.Use(func(c *gin.Context) {
|
|
c.Header("Access-Control-Expose-Headers", "X-Device-Key, X-Request-Id")
|
|
c.Next()
|
|
})
|
|
|
|
api := r.Group("/api/v1")
|
|
handler.NewHealthHandler().Register(api)
|
|
api.GET("/ping", func(c *gin.Context) {
|
|
response.OK(c, gin.H{"pong": true})
|
|
})
|
|
|
|
authed := api.Group("")
|
|
authed.Use(middleware.DeviceAuth(pool))
|
|
(&handler.ProfileHandler{Svc: profileSvc}).Register(authed)
|
|
(&handler.ReportHandler{Svc: reportSvc}).Register(authed)
|
|
(&handler.SynastryHandler{Svc: reportSvc}).Register(authed)
|
|
(&handler.RelationHandler{Svc: relationSvc}).Register(authed)
|
|
(&handler.ScaleHandler{Svc: scaleSvc}).Register(authed)
|
|
(&handler.AskHandler{Svc: askSvc}).Register(authed)
|
|
(&handler.CompanionHandler{Svc: companionSvc}).Register(authed)
|
|
(&handler.ImageCardHandler{Svc: imageCardSvc}).Register(authed)
|
|
(&handler.ExploreHandler{}).Register(authed)
|
|
(&handler.GrowthHandler{
|
|
Plans: &repository.GrowthRepo{Pool: pool},
|
|
}).Register(authed)
|
|
|
|
return r
|
|
}
|