feat: integrate AI candidate review and automatic publication
This commit is contained in:
@@ -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})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user