1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "net/http"
- "property-company-gateway/errors"
- param_v1 "property-company-gateway/param/v1"
- "property-company-gateway/pb"
- "property-company-gateway/pb/v1"
- )
- //
- // @Summary 套餐列表
- // @Description 套餐列表
- // @Tags 套餐
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
- // @Param page_size query int false "每页条数,-1 不分页返回所有"
- // @Param enable query int false "0不过滤,1已发布的 2 未发布的"
- // @Success 200 {object} v1.PackageListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/package [get]
- func (c *Controller) PackageList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PackageListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.PackageListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.PackageListResponse{}
- rpcReq := &v1.PackageListRequest{
- //PackageId: req.PackageId,
- PageSize: req.PageSize,
- Page: req.Page,
- Enable: 1,
- }
- rpcRsp, err := pb.Common.PackageList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.PackageList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.PackageItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|