package service import ( "net/http" repository "sig-pub/internal/admin/repoitory" "sig-pub/pkg/resp" "sort" "github.com/gin-gonic/gin" ) type MarketService struct { repo *repository.MarketRepository } func NewMarketService(repo *repository.MarketRepository) *MarketService { return &MarketService{ repo: repo, } } func (svc *MarketService) Route(group *gin.RouterGroup) { group.GET("listInstanceId", svc.ListInstanceId) // 所有交易产品ID group.GET("listInstance", svc.ListInstance) // 所有交易产品信息 } func (svc *MarketService) ListInstanceId(ctx *gin.Context) { instIds, err := svc.repo.ListAllInstanceId() if err != nil { ctx.JSON(http.StatusInternalServerError, resp.Error(err.Error())) return } sort.Strings(instIds) ctx.JSON(http.StatusOK, resp.Success(instIds)) } func (svc *MarketService) ListInstance(ctx *gin.Context) { insts, err := svc.repo.ListAllInstance() if err != nil { ctx.JSON(http.StatusInternalServerError, resp.Error(err.Error())) return } sort.Slice(insts, func(i, j int) bool { return insts[i].InstId < insts[j].InstId }) ctx.JSON(http.StatusOK, resp.Success(resp.H{ "total": len(insts), "insts": insts, })) }