getuserprofilelogic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package logic
  2. import (
  3. "context"
  4. "slowwild/internal/svc"
  5. "slowwild/internal/errorx"
  6. "slowwild/internal/model"
  7. "git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type GetUserProfileLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic {
  16. return &GetUserProfileLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. // 查询用户的详细信息
  23. func (l *GetUserProfileLogic) GetUserProfile(in *slowwildserver.GetUserProfileReq) (*slowwildserver.GetUserProfileRes, error) {
  24. if in.UserId <= 0 {
  25. return nil, errorx.ErrInvalidParam
  26. }
  27. // 查询用户详细信息
  28. user, err := l.svcCtx.UserModel.FindOneById(l.ctx, in.UserId)
  29. if err == model.ErrNotFound {
  30. return nil, errorx.ErrUserNotFound
  31. }
  32. if err != nil {
  33. return nil, errorx.ErrUserQueryFailed
  34. }
  35. return &slowwildserver.GetUserProfileRes{
  36. Id: user.ID,
  37. Username: user.Username,
  38. Phone: user.Phone,
  39. Nickname: user.Nickname,
  40. Avatar: user.Avatar,
  41. Sex: int32(user.Sex),
  42. Status: user.Status,
  43. GetLikesCount: int32(user.LikeCount),
  44. TweetCount: int32(user.TweetCount),
  45. GetCollectionCount: int32(user.CollectionCount),
  46. Follows: int64(user.FollowCount),
  47. Fans: int64(user.FansCount),
  48. CreatedOn: user.CreatedOn,
  49. }, nil
  50. }