统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"git.sundynix.cn/Blizzard/Veyra/internal/apperror"
|
||||
"git.sundynix.cn/Blizzard/Veyra/internal/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func bindNotifications(r *gin.Engine, options IdentityOptions) {
|
||||
for _, admin := range []bool{true, false} {
|
||||
path, audience := "/api/v1", "app"
|
||||
if admin {
|
||||
path, audience = "/api/admin/v1", "admin"
|
||||
}
|
||||
group := r.Group(path, func(c *gin.Context) { authenticate(c, options, audience) })
|
||||
group.Use(func(c *gin.Context) {
|
||||
if options.Notifications == nil {
|
||||
fail(c, apperror.ErrUnavailable)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
})
|
||||
if admin {
|
||||
group.GET("/notification-tasks", func(c *gin.Context) {
|
||||
result, err := options.Notifications.Tasks(c.Request.Context(), currentUser(c))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
success(c, http.StatusOK, result)
|
||||
})
|
||||
group.GET("/simulation-quotes", func(c *gin.Context) {
|
||||
result, err := options.Notifications.Quotes(c.Request.Context(), currentUser(c))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
success(c, http.StatusOK, result)
|
||||
})
|
||||
group.POST("/simulation-quotes", func(c *gin.Context) {
|
||||
if !sameOrigin(c.Request) {
|
||||
fail(c, apperror.ErrForbidden)
|
||||
return
|
||||
}
|
||||
var input service.SimulationQuoteInput
|
||||
if !decode(c, &input) {
|
||||
return
|
||||
}
|
||||
result, err := options.Notifications.SaveQuote(c.Request.Context(), currentUser(c), input, c.Writer.Header().Get("X-Request-ID"))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
success(c, http.StatusCreated, result)
|
||||
})
|
||||
} else {
|
||||
group.GET("/notifications", func(c *gin.Context) {
|
||||
result, err := options.Notifications.List(c.Request.Context(), currentUser(c))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
success(c, http.StatusOK, result)
|
||||
})
|
||||
group.POST("/notifications/:id/read", func(c *gin.Context) {
|
||||
var input struct{}
|
||||
if !decode(c, &input) {
|
||||
return
|
||||
}
|
||||
if err := options.Notifications.MarkRead(c.Request.Context(), currentUser(c), c.Param("id")); err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
success(c, http.StatusOK, gin.H{"read": true})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user