self.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package myself
  2. import (
  3. "Cold_Logistic/internal/pkg/common/codex"
  4. "Cold_Logistic/internal/pkg/common/global"
  5. "Cold_Logistic/internal/server/application/myselfsrv"
  6. "Cold_Logistic/internal/server/infra/dao"
  7. "github.com/gin-gonic/gin"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  10. )
  11. // myselfInfo
  12. // @Tags 用户-我的
  13. // @BasePath /clodLogistic/app/api/v1
  14. // @Summary 个人信息
  15. // @Success 200 {object} swagger.AccountInfoVo "成功响应的结构体"
  16. // @Accept application/json
  17. // @Authorization
  18. // @Router /app/myself/info [get]
  19. func (api Api) myselfInfo(c *gin.Context) {
  20. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  21. res, err := srv.MyselfInfo(c)
  22. if err != nil {
  23. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  24. return
  25. }
  26. core.WriteResponse(c, nil, res)
  27. }
  28. // updateMyselfInfo
  29. // @Tags 用户-我的
  30. // @BasePath /clodLogistic/app/api/v1
  31. // @Summary 修改个人信息
  32. // @Success 200 {object} swagger.AccountInfoVo "成功响应的结构体"
  33. // @Param req body myselfsrv.UpdateMyselfInfoReqVO true "请求参数"
  34. // @Accept application/json
  35. // @Authorization
  36. // @Router /app/myself/update [post]
  37. func (api Api) updateMyselfInfo(c *gin.Context) {
  38. req := myselfsrv.UpdateMyselfInfoReqVO{}
  39. if err := c.BindJSON(&req); err != nil {
  40. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  41. return
  42. }
  43. if err := req.Validate(); err != nil {
  44. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  45. return
  46. }
  47. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  48. res, err := srv.UpdateMyselfInfo(c, req)
  49. if err != nil {
  50. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  51. return
  52. }
  53. core.WriteResponse(c, nil, res)
  54. }
  55. // refreshToken
  56. // @Tags 用户-我的
  57. // @BasePath /clodLogistic/app/api/v1
  58. // @Summary 刷新token
  59. // @Success 200 {object} myselfsrv.RefreshTokenRespVo "成功响应的结构体"
  60. // @Accept application/json
  61. // @Authorization
  62. // @Router /app/myself/refreshToken [post]
  63. func (api Api) refreshToken(c *gin.Context) {
  64. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  65. res, err := srv.RefreshToken(c)
  66. if err != nil {
  67. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  68. return
  69. }
  70. core.WriteResponse(c, nil, res)
  71. }