33 lines
662 B
Go
33 lines
662 B
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
v1 "server/api/user/v1"
|
|
"server/internal/model"
|
|
"server/internal/service"
|
|
"server/utility/ecode"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) {
|
|
// 从ctx获取userId
|
|
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
|
if userId == 0 {
|
|
return nil, ecode.Logout
|
|
}
|
|
|
|
out, err := service.User().Info(ctx, &model.UserInfoIn{UserId: userId})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &v1.InfoRes{
|
|
UserId: out.UserId,
|
|
Username: out.Username,
|
|
Avatar: out.Avatar,
|
|
Email: out.Email,
|
|
Points: out.Points,
|
|
}, nil
|
|
}
|