12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // 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 不分页返回所有"
- // @Success 200 {object} v1.ApplicationListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/application [get]
- func (c *Controller) ApplicationList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ApplicationListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ApplicationListQuery, 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.ApplicationListResponse{}
- rpcReq := &v1.ApplicationListRequest{
- //PackageId: req.PackageId,
- PageSize: req.PageSize,
- Page: req.Page,
- Enable: 1,
- }
- rpcRsp, err := pb.Common.ApplicationList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.ApplicationList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ApplicationItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|