| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package logic
- import (
- "context"
- "slowwild/internal/svc"
- "slowwild/internal/errorx"
- "slowwild/internal/model"
- "git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GetUserProfileLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic {
- return &GetUserProfileLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 查询用户的详细信息
- func (l *GetUserProfileLogic) GetUserProfile(in *slowwildserver.GetUserProfileReq) (*slowwildserver.GetUserProfileRes, error) {
- if in.UserId <= 0 {
- return nil, errorx.ErrInvalidParam
- }
- // 查询用户详细信息
- user, err := l.svcCtx.UserModel.FindOneById(l.ctx, in.UserId)
- if err == model.ErrNotFound {
- return nil, errorx.ErrUserNotFound
- }
- if err != nil {
- return nil, errorx.ErrUserQueryFailed
- }
- return &slowwildserver.GetUserProfileRes{
- Id: user.ID,
- Username: user.Username,
- Phone: user.Phone,
- Nickname: user.Nickname,
- Avatar: user.Avatar,
- Sex: int32(user.Sex),
- Status: user.Status,
- GetLikesCount: int32(user.LikeCount),
- TweetCount: int32(user.TweetCount),
- GetCollectionCount: int32(user.CollectionCount),
- Follows: int64(user.FollowCount),
- Fans: int64(user.FansCount),
- CreatedOn: user.CreatedOn,
- }, nil
- }
|