fix: some api bug
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddUserFollowsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddUserFollowsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserFollowsLogic {
|
||||
return &AddUserFollowsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------userFollows-----------------------
|
||||
func (l *AddUserFollowsLogic) AddUserFollows(in *pb.AddUserFollowsReq) (*pb.AddUserFollowsResp, error) {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("AddUserFollows error: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UsersModelRW.UserFollows.Create().
|
||||
SetFollowerID(in.FollowerId).
|
||||
SetFolloweeID(in.FolloweeId).
|
||||
SetID(idResp.Id).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("AddUserFollows error: %s", err.Error())
|
||||
return nil, errors.New("failed to add user follow relationship")
|
||||
}
|
||||
return &pb.AddUserFollowsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddUserPreferencesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddUserPreferencesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserPreferencesLogic {
|
||||
return &AddUserPreferencesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------userPreferences-----------------------
|
||||
func (l *AddUserPreferencesLogic) AddUserPreferences(in *pb.AddUserPreferencesReq) (*pb.AddUserPreferencesResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.AddUserPreferencesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/rpc/internal/models/userfollows"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelUserFollowsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelUserFollowsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelUserFollowsLogic {
|
||||
return &DelUserFollowsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelUserFollowsLogic) DelUserFollows(in *pb.DelUserFollowsReq) (*pb.DelUserFollowsResp, error) {
|
||||
_, err := l.svcCtx.UsersModelRW.UserFollows.Delete().Where(
|
||||
userfollows.IDEQ(in.Id),
|
||||
userfollows.FollowerIDEQ(in.UserId),
|
||||
).Exec(l.ctx)
|
||||
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("Failed to delete user follow: %s", err.Error())
|
||||
return nil, errors.New("failed to unfollow")
|
||||
}
|
||||
return &pb.DelUserFollowsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelUserPreferencesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelUserPreferencesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelUserPreferencesLogic {
|
||||
return &DelUserPreferencesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelUserPreferencesLogic) DelUserPreferences(in *pb.DelUserPreferencesReq) (*pb.DelUserPreferencesResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.DelUserPreferencesResp{}, nil
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func (l *GetUserByUsernameLogic) GetUserByUsername(in *pb.GetUserByUsernameReq)
|
||||
pbUsers := &pb.Users{}
|
||||
|
||||
//user, err := l.svcCtx.UsersModelRO.FindOneByUsername(l.ctx, in.Username)
|
||||
user, err := l.svcCtx.UsersModelRO.Query().Where(users.UsernameEQ(in.Username)).First(l.ctx)
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().Where(users.UsernameEQ(in.Username)).First(l.ctx)
|
||||
if err == nil || user != nil {
|
||||
return &pb.GetUserByUsernameResp{
|
||||
Users: pbUsers,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserFollowsByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserFollowsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserFollowsByIdLogic {
|
||||
return &GetUserFollowsByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserFollowsByIdLogic) GetUserFollowsById(in *pb.GetUserFollowsByIdReq) (*pb.GetUserFollowsByIdResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.GetUserFollowsByIdResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserPreferencesByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserPreferencesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserPreferencesByIdLogic {
|
||||
return &GetUserPreferencesByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserPreferencesByIdLogic) GetUserPreferencesById(in *pb.GetUserPreferencesByIdReq) (*pb.GetUserPreferencesByIdResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.GetUserPreferencesByIdResp{}, nil
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"juwan-backend/app/users/rpc/internal/models/users"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
"juwan-backend/common/converter"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,15 +29,37 @@ func NewGetUsersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetU
|
||||
func (l *GetUsersByIdLogic) GetUsersById(in *pb.GetUsersByIdReq) (*pb.GetUsersByIdResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
//user, err := l.svcCtx.UsersModelRO.FindOne(l.ctx, in.Id)
|
||||
user, err := l.svcCtx.UsersModelRO.Query().Where(users.IDEQ(in.Id)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbUser := &pb.Users{}
|
||||
err = converter.StructToStruct(&user, &pbUser)
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().Where(users.IDEQ(in.Id)).First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
verificationStatus, err := json.Marshal(user.VerificationStatus)
|
||||
if err != nil {
|
||||
logx.Errorf("json marshal verification status failed: %v", err)
|
||||
return nil, errors.New("marshal verification status failed")
|
||||
}
|
||||
|
||||
logx.Debugf("Users data: %+v", user)
|
||||
logx.Debugf("verified_role: %+v", user.VerifiedRoles)
|
||||
pbUser := &pb.Users{
|
||||
Id: user.ID,
|
||||
Username: user.Username,
|
||||
PasswordHash: "",
|
||||
Phone: "",
|
||||
Email: "",
|
||||
Nickname: user.Nickname,
|
||||
Avatar: user.Avatar,
|
||||
Bio: user.Bio,
|
||||
CurrentRole: user.CurrentRole,
|
||||
VerifiedRoles: user.VerifiedRoles.Elements,
|
||||
VerificationStatus: string(verificationStatus),
|
||||
IsAdmin: user.IsAdmin,
|
||||
CreatedAt: user.CreatedAt.Unix(),
|
||||
UpdatedAt: user.UpdatedAt.Unix(),
|
||||
DeletedAt: user.DeletedAt.Unix(),
|
||||
}
|
||||
logx.Debugf("pb users data: %+v", pbUser)
|
||||
|
||||
return &pb.GetUsersByIdResp{Users: pbUser}, nil
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(in *pb.LoginReq) (*pb.LoginResp, error) {
|
||||
//user, err := l.svcCtx.UsersModelRO.FindOneByUsername(l.ctx, in.Username)
|
||||
user, err := l.svcCtx.UsersModelRO.Query().Where(users.NicknameEQ(in.Username)).First(l.ctx)
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().
|
||||
Where(users.UsernameEQ(in.Username)).
|
||||
Select(users.FieldID, users.FieldUsername, users.FieldPasswordHash, users.FieldEmail).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("LoginLogic.Login error:%v", err)
|
||||
return nil, err
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
logx.Infof("user:%v", user)
|
||||
if !pwdUtils.VerifyPassword(user.PasswordHash, in.Passwd) {
|
||||
|
||||
@@ -49,6 +49,7 @@ func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
|
||||
}
|
||||
|
||||
redisKey := fmt.Sprintf(redisx.VCODE_KEY_PREFIX, in.RequestId, redisx.SCENE_REG, in.Email)
|
||||
logx.Infof("redisKey: %s", redisKey)
|
||||
vcode, err := l.svcCtx.RedisCluster.Get(l.ctx, redisKey).Result()
|
||||
logx.Infof("vcode:%s, err:%v", vcode, err)
|
||||
if err != nil {
|
||||
@@ -66,12 +67,15 @@ func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
|
||||
return nil, errors.New("generate user ID failed")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UsersModelRW.Create().
|
||||
_, err = l.svcCtx.UsersModelRW.Users.Create().
|
||||
SetID(resp.Id).
|
||||
SetUsername(in.Username).
|
||||
SetPasswordHash(in.Passwd).
|
||||
SetPhone(in.Phone).
|
||||
SetEmail(in.Email).
|
||||
SetBio(in.Email).
|
||||
SetAvatar("").
|
||||
SetCurrentRole("consumer").
|
||||
SetNickname(mustNewRandomNickname()).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -38,7 +38,7 @@ func (l *ResetPasswordLogic) ResetPassword(in *pb.ResetPasswordReq) (*pb.ResetPa
|
||||
if vcode != in.Vcode {
|
||||
return nil, errors.New(fmt.Sprintf("user %v reset password failed, invalid vcode.", in.Email))
|
||||
}
|
||||
err = l.svcCtx.UsersModelRW.Update().Where(users.EmailEQ(in.Email)).
|
||||
err = l.svcCtx.UsersModelRW.Users.Update().Where(users.EmailEQ(in.Email)).
|
||||
SetPasswordHash(in.NewPassword).
|
||||
Exec(l.ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchUserFollowsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchUserFollowsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchUserFollowsLogic {
|
||||
return &SearchUserFollowsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchUserFollowsLogic) SearchUserFollows(in *pb.SearchUserFollowsReq) (*pb.SearchUserFollowsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.SearchUserFollowsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchUserPreferencesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchUserPreferencesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchUserPreferencesLogic {
|
||||
return &SearchUserPreferencesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchUserPreferencesLogic) SearchUserPreferences(in *pb.SearchUserPreferencesReq) (*pb.SearchUserPreferencesResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.SearchUserPreferencesResp{}, nil
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func (l *SearchUsersLogic) SearchUsers(in *pb.SearchUsersReq) (out *pb.SearchUse
|
||||
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
||||
return nil, errors.New("limit exceeds max limit")
|
||||
}
|
||||
user, err := l.svcCtx.UsersModelRO.Query().
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().
|
||||
Where(users.Or(
|
||||
users.UsernameContainsFold(*in.Username),
|
||||
users.NicknameContainsFold(*in.Username),
|
||||
@@ -80,7 +80,8 @@ func ConvertEntUserToProto(entUser *models.Users) *pb.Users {
|
||||
}
|
||||
|
||||
out.VerificationStatus = string(verificationStatus)
|
||||
out.VerifiedRoles = entUser.VerifiedRoles
|
||||
//out.VerifiedRoles = entUser.VerifiedRoles
|
||||
out.VerifiedRoles = entUser.VerifiedRoles.Elements
|
||||
|
||||
out.PasswordHash = "" // 手动清空敏感字段
|
||||
return out
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/models/users"
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SwitchRoleLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSwitchRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SwitchRoleLogic {
|
||||
return &SwitchRoleLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
var userRoles = []string{"consumer", "owner", "player", "admin"}
|
||||
|
||||
func (l *SwitchRoleLogic) SwitchRole(in *pb.SwitchRoleReq) (*pb.SwitchRoleResp, error) {
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().
|
||||
Select(users.FieldVerifiedRoles).
|
||||
Where(users.IDEQ(in.UserId)).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("find user error by switch role, err: %v", err.Error())
|
||||
return &pb.SwitchRoleResp{
|
||||
Success: false,
|
||||
}, errors.New("failed to find user")
|
||||
}
|
||||
|
||||
if !slices.Contains(userRoles, in.NewRole) {
|
||||
logx.Infof("user role not found by userId: %v", in.UserId)
|
||||
return nil, errors.New("user role not found by userId")
|
||||
}
|
||||
|
||||
if !slices.Contains(user.VerifiedRoles.Elements, in.NewRole) {
|
||||
logx.Infof("user verified role not exists, user: %v", in.UserId)
|
||||
return nil, errors.New("no permission to operate")
|
||||
}
|
||||
|
||||
user, err = l.svcCtx.UsersModelRW.Users.UpdateOneID(in.UserId).
|
||||
SetCurrentRole(in.NewRole).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("failed to update user role, userId: %v, err: %v", in.UserId, err.Error())
|
||||
return nil, errors.New("failed to update user")
|
||||
}
|
||||
|
||||
return &pb.SwitchRoleResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserFollowsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateUserFollowsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserFollowsLogic {
|
||||
return &UpdateUserFollowsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateUserFollowsLogic) UpdateUserFollows(in *pb.UpdateUserFollowsReq) (*pb.UpdateUserFollowsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.UpdateUserFollowsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserPreferencesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateUserPreferencesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserPreferencesLogic {
|
||||
return &UpdateUserPreferencesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateUserPreferencesLogic) UpdateUserPreferences(in *pb.UpdateUserPreferencesReq) (*pb.UpdateUserPreferencesResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.UpdateUserPreferencesResp{}, nil
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
"juwan-backend/pkg/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -23,14 +24,20 @@ func NewUpdateUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Updat
|
||||
}
|
||||
|
||||
func (l *UpdateUsersLogic) UpdateUsers(in *pb.UpdateUsersReq) (*pb.UpdateUsersResp, error) {
|
||||
updater := l.svcCtx.UsersModelRW.UpdateOneID(in.Id).
|
||||
updater := l.svcCtx.UsersModelRW.Users.UpdateOneID(in.Id).
|
||||
SetNillableNickname(in.Nickname).
|
||||
SetNillableAvatar(in.Avatar).
|
||||
SetNillableBio(in.Bio).
|
||||
SetNillableCurrentRole(in.CurrentRole).
|
||||
SetNillablePasswordHash(in.PasswordHash)
|
||||
if len(in.VerifiedRoles) > 0 {
|
||||
updater.SetVerifiedRoles(in.VerifiedRoles)
|
||||
var verifiedRoles types.TextArray
|
||||
err := verifiedRoles.Scan(in.VerifiedRoles)
|
||||
if err != nil {
|
||||
logx.Errorf("failed to scan verified roles: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
updater.SetVerifiedRoles(verifiedRoles)
|
||||
}
|
||||
err := updater.Exec(l.ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,8 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"juwan-backend/app/users/rpc/internal/models/users"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
@@ -33,15 +35,24 @@ func (l *ValidateTokenLogic) ValidateToken(in *pb.ValidateTokenReq) (*pb.Validat
|
||||
return nil, err
|
||||
}
|
||||
//users, err := l.svcCtx.UsersModelRO.FindOne(l.ctx, in.UserId)
|
||||
user, err := l.svcCtx.UsersModelRO.Query().Where(users.IDEQ(in.UserId)).First(l.ctx)
|
||||
user, err := l.svcCtx.UsersModelRO.Users.Query().
|
||||
Where(users.IDEQ(in.UserId)).
|
||||
Select(users.FieldCurrentRole).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userJson, err := json.Marshal(user.CurrentRole)
|
||||
if err != nil {
|
||||
logx.Errorf("json marshal err: %v", err)
|
||||
return nil, errors.New("internal error")
|
||||
}
|
||||
|
||||
return &pb.ValidateTokenResp{
|
||||
Valid: true,
|
||||
Message: "OK",
|
||||
UserId: in.UserId,
|
||||
RoleType: user.CurrentRole,
|
||||
RoleType: string(userJson),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user