application.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "git.getensh.com/common/gopkgs/logger"
  6. "git.getensh.com/common/gopkgs/tasker/httptasker"
  7. "git.getensh.com/common/gopkgs/util"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "property-company-gateway/errors"
  12. param_v1 "property-company-gateway/param/v1"
  13. "property-company-gateway/pb"
  14. "property-company-gateway/pb/v1"
  15. )
  16. //
  17. // @Summary 所有应用列表
  18. // @Description 所有应用列表
  19. // @Tags 应用
  20. // @Accept json
  21. // @Produce json
  22. // @Param token header string true " "
  23. // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
  24. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  25. // @Success 200 {object} v1.ApplicationListResponse
  26. // @Failure 500 {object} base.HTTPError
  27. // @Router /api/v1/application [get]
  28. func (c *Controller) ApplicationList(ctx *gin.Context) {
  29. // 解析参数
  30. req := &param_v1.ApplicationListRequest{}
  31. parseParamTask := func() error {
  32. err := util.ShouldBind(ctx, &req.Header, nil, &req.ApplicationListQuery, nil)
  33. if err != nil {
  34. logger.Error("func",
  35. zap.String("call", "util.ShouldBind"),
  36. zap.String("error", err.Error()))
  37. return errors.ParamsError
  38. }
  39. return nil
  40. }
  41. // 业务处理
  42. handleServiceTask := func() error {
  43. //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  44. //if err != nil {
  45. // return err
  46. //}
  47. // 响应数据
  48. resp := param_v1.ApplicationListResponse{}
  49. rpcReq := &v1.ApplicationListRequest{
  50. //PackageId: req.PackageId,
  51. PageSize: req.PageSize,
  52. Page: req.Page,
  53. Enable: 1,
  54. }
  55. rpcRsp, err := pb.Common.ApplicationList(ctx, rpcReq)
  56. if err != nil {
  57. s, _ := json.MarshalToString(req)
  58. logger.Error("func",
  59. zap.String("call", "pb.Common.ApplicationList"),
  60. zap.String("params", s),
  61. zap.String("error", err.Error()))
  62. return errors.ErrorTransForm(err)
  63. }
  64. if rpcRsp.List == nil {
  65. rpcRsp.List = make([]*v1.ApplicationItem, 0)
  66. }
  67. resp.Data = *rpcRsp
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. }