You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
1.4 KiB

package inst
import (
"net/http"
"sig-pub/internal/market"
"sig-pub/pkg/data/args"
"sig-pub/pkg/resp"
"github.com/gin-gonic/gin"
)
type TradeInstanceApi struct {
service *market.TradeInstanceService // todo grpc call
}
func NewTradeInstanceApi() *TradeInstanceApi {
return &TradeInstanceApi{}
}
func (a *TradeInstanceApi) InitRoute(r *gin.RouterGroup) {
instGroup := r.Group("/inst")
{
instGroup.GET("/one/:inst_id", a.getInst)
instGroup.GET("/listAll", a.listAllInst)
instGroup.POST("/list", a.listInst)
}
}
// getInst 获取指定交易产品
func (a *TradeInstanceApi) getInst(c *gin.Context) {
instId := c.Param("inst_id")
inst, err := a.service.GetInstance(instId)
if err != nil {
c.JSON(http.StatusOK, resp.Error(err.Error()))
return
}
c.JSON(http.StatusOK, resp.Success(inst))
}
// listAllInst 获取所有交易产品
func (a *TradeInstanceApi) listAllInst(c *gin.Context) {
// list, err := a.service.ListAllInstance()
// if err != nil {
// c.JSON(http.StatusOK, resp.Error(err.Error()))
// return
// }
// c.JSON(http.StatusOK, resp.Success(list))
}
// listInst 交易产品分页查询
func (a *TradeInstanceApi) listInst(c *gin.Context) {
pageArg := args.ParsePageArgs(c)
total, list, err := a.service.PageInstance(pageArg.Page, pageArg.Size, "")
if err != nil {
c.JSON(http.StatusOK, resp.Error(err.Error()))
return
}
c.JSON(http.StatusOK, resp.Success(resp.H{
"total": total,
"data": list,
}))
}