package handler import ( "git.sundynix.cn/Blizzard/Veyra/internal/apperror" "github.com/gin-gonic/gin" "net/http" ) func bindMarket(r *gin.Engine, o IdentityOptions) { for _, audience := range []string{"admin", "app"} { prefix := "/api/v1" if audience == "admin" { prefix = "/api/admin/v1" } g := r.Group(prefix, func(c *gin.Context) { authenticate(c, o, audience) }) g.Use(func(c *gin.Context) { if o.Market == nil { fail(c, apperror.ErrUnavailable) return } c.Next() }) g.GET("/instruments", func(c *gin.Context) { v, e := o.Market.List(c.Request.Context(), currentUser(c), c.Query("q")) if e != nil { fail(c, e) return } success(c, http.StatusOK, v) }) g.GET("/market/history", func(c *gin.Context) { v, e := o.Market.History(c.Request.Context(), currentUser(c), c.Query("symbol"), c.Query("exchange"), c.Query("start"), c.Query("end")) if e != nil { fail(c, e) return } success(c, http.StatusOK, v) }) if audience == "admin" { g.GET("/market/syncs", func(c *gin.Context) { v, e := o.Market.Tasks(c.Request.Context(), currentUser(c)) if e != nil { fail(c, e) return } success(c, http.StatusOK, v) }) } } }