api.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package common
  2. import (
  3. "Cold_Logistic/internal/pkg/common/codex"
  4. "Cold_Logistic/internal/pkg/common/global"
  5. "Cold_Logistic/internal/server/adapter/http/middleware"
  6. "Cold_Logistic/internal/server/application/commonsrv"
  7. "Cold_Logistic/internal/server/application/devicesrv"
  8. "Cold_Logistic/internal/server/infra/dao"
  9. "github.com/gin-gonic/gin"
  10. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  11. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  12. )
  13. func Register(r *gin.RouterGroup) {
  14. api := NewApi()
  15. common := r.Group("/common")
  16. common.Use(middleware.Auth())
  17. common.GET("/provinceList", api.provinceList) // 省市区列表
  18. common.GET("/sensorDataList", api.sensorDataList) // 设备数据列表
  19. common.GET("/logisticList", api.logisticList) // 物流公司列表
  20. return
  21. }
  22. type Api struct{}
  23. func NewApi() Api {
  24. return Api{}
  25. }
  26. // provinceList
  27. // @Tags 公共接口
  28. // @BasePath /clodLogistic/app/api/v1
  29. // @Summary 省市区列表
  30. // @Success 200 {object} commonsrv.ProvinceListRespVO "成功响应的结构体"
  31. // @Accept application/json
  32. // @Authorization
  33. // @Router /common/provinceList [get]
  34. func (api Api) provinceList(c *gin.Context) {
  35. srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  36. data, err := srv.ProvinceList(c)
  37. if err != nil {
  38. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  39. return
  40. }
  41. core.WriteResponse(c, nil, data)
  42. }
  43. // sensorDataList
  44. // @Tags 公共接口
  45. // @BasePath /clodLogistic/app/api/v1
  46. // @Summary 设备数据列表
  47. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  48. // @Param req body swagger.SnDataListReqVO true "请求参数"
  49. // @Accept application/json
  50. // @Authorization Bearer
  51. // @Router /address/add [post]
  52. func (api Api) sensorDataList(c *gin.Context) {
  53. req := devicesrv.SnDataListReqVO{}
  54. if err := c.BindJSON(&req); err != nil {
  55. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  56. return
  57. }
  58. if err := req.Validate(); err != nil {
  59. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  60. return
  61. }
  62. srv := devicesrv.NewDeviceService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  63. res, err := srv.SnDataList(c, req)
  64. if err != nil {
  65. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  66. return
  67. }
  68. core.WriteResponse(c, nil, res)
  69. }
  70. // logisticList
  71. // @Tags 公共接口
  72. // @BasePath /clodLogistic/app/api/v1
  73. // @Summary 物流公司列表
  74. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  75. // @Param req body swagger.LogisticListReqVO true "请求参数"
  76. // @Accept application/json
  77. // @Authorization Bearer
  78. // @Router /common/logisticList [get]
  79. func (api Api) logisticList(c *gin.Context) {
  80. req := commonsrv.LogisticListReqVO{}
  81. if err := c.BindJSON(&req); err != nil {
  82. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  83. return
  84. }
  85. srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  86. res, err := srv.LogisticList(c, req)
  87. if err != nil {
  88. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  89. return
  90. }
  91. core.WriteResponse(c, nil, res)
  92. }