feat: integrate AI candidate review and automatic publication

This commit is contained in:
2026-10-09 22:33:38 +08:00
parent 04dbeb2ac6
commit 86f1e7a897
46 changed files with 2460 additions and 2362 deletions
+65
View File
@@ -0,0 +1,65 @@
package handler
import (
"git.sundynix.cn/Blizzard/Veyra/internal/apperror"
"git.sundynix.cn/Blizzard/Veyra/internal/model"
"github.com/gin-gonic/gin"
"net/http"
)
func bindCandidateAnalysis(r *gin.Engine, o IdentityOptions) {
g := r.Group("/api/admin/v1", func(c *gin.Context) { authenticate(c, o, "admin") })
g.Use(func(c *gin.Context) {
if o.Analyses == nil {
fail(c, apperror.ErrUnavailable)
return
}
c.Next()
})
g.GET("/ai-review-policy", func(c *gin.Context) {
p, err := o.Analyses.Policy(c.Request.Context(), currentUser(c))
if err != nil {
fail(c, err)
return
}
success(c, http.StatusOK, p)
})
g.GET("/candidate-analyses", func(c *gin.Context) {
v, err := o.Analyses.List(c.Request.Context(), currentUser(c))
if err != nil {
fail(c, err)
return
}
success(c, http.StatusOK, v)
})
g.Use(func(c *gin.Context) {
if !sameOrigin(c.Request) {
fail(c, apperror.ErrForbidden)
return
}
c.Next()
})
g.PUT("/ai-review-policy", func(c *gin.Context) {
var input struct {
Enabled bool `json:"enabled"`
AutoPublish bool `json:"auto_publish"`
ExpectedVersion int64 `json:"expected_version"`
}
if !decode(c, &input) {
return
}
p, err := o.Analyses.SavePolicy(c.Request.Context(), currentUser(c), model.AIReviewPolicy{Enabled: input.Enabled, AutoPublish: input.AutoPublish, Version: input.ExpectedVersion}, c.Writer.Header().Get("X-Request-ID"))
if err != nil {
fail(c, err)
return
}
success(c, http.StatusOK, p)
})
g.POST("/candidate-analyses/run", func(c *gin.Context) {
if err := o.Analyses.Wake(currentUser(c)); err != nil {
fail(c, err)
return
}
success(c, http.StatusAccepted, gin.H{"queued": true})
})
}
+1
View File
@@ -21,6 +21,7 @@ type LoginLimiter interface {
Login(context.Context, string, string) (bool, error)
}
type IdentityOptions struct {
Analyses *service.CandidateAnalysisService
Screenings *service.ScreeningService
Market *service.MarketService
Backtests *service.BacktestService
+22
View File
@@ -40,6 +40,28 @@ func bindProviders(r *gin.Engine, options IdentityOptions) {
}
success(c, http.StatusOK, config)
})
admin.POST("/providers/model_review/copy-primary", func(c *gin.Context) {
if !sameOrigin(c.Request) {
fail(c, apperror.ErrForbidden)
return
}
if options.Providers == nil {
fail(c, apperror.ErrUnavailable)
return
}
var input struct {
ExpectedVersion int64 `json:"expected_version"`
}
if !decode(c, &input) {
return
}
result, err := options.Providers.CopyPrimaryToReview(c.Request.Context(), currentUser(c), c.Writer.Header().Get("X-Request-ID"), input.ExpectedVersion)
if err != nil {
fail(c, err)
return
}
success(c, http.StatusOK, result)
})
admin.GET("/audit-events", func(c *gin.Context) {
list, err := options.Providers.Audit(c.Request.Context(), currentUser(c))
if err != nil {
+1
View File
@@ -70,6 +70,7 @@ func NewRouter(health *service.HealthService, logger *zap.Logger, identity Ident
bindIdentity(r, identity)
bindProviders(r, identity)
bindCandidates(r, identity)
bindCandidateAnalysis(r, identity)
bindTradePlans(r, identity)
bindTradeFills(r, identity)
bindNotifications(r, identity)