getuserprofilelogic.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package logic
  2. import (
  3. "context"
  4. "encoding/json"
  5. "slow_wild_api/apps/internal/constants"
  6. "slow_wild_api/apps/internal/svc"
  7. "slow_wild_api/apps/internal/types"
  8. "git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
  9. "github.com/spf13/cast"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetUserProfileLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. // 获取用户信息
  18. func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic {
  19. return &GetUserProfileLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *GetUserProfileLogic) GetUserProfile(req *types.GetUserProfileReq) (resp *types.BaseReturnData, err error) {
  26. resp = &types.BaseReturnData{}
  27. userId := l.ctx.Value(constants.UserIdKey).(json.Number)
  28. rpcResp, err := l.svcCtx.SlowWildPb.GetUserProfile(l.ctx, &slowwildserver.GetUserProfileReq{
  29. UserId: cast.ToInt64(userId),
  30. })
  31. if err != nil {
  32. return nil, err
  33. }
  34. resp.Data = rpcResp
  35. return
  36. }