fix: unify user ID type to string and rename service to users-api

This commit is contained in:
zetaloop
2026-04-22 22:03:49 +08:00
parent 59256897e9
commit b3db04c9cc
11 changed files with 59 additions and 28 deletions
@@ -6,9 +6,11 @@ package auth
import (
"context"
"errors"
"juwan-backend/app/users/rpc/usercenter"
"strconv"
"time"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
@@ -65,6 +67,7 @@ func (l *LoginLogic) Login(req *types.LoginReq) (*types.LoginResp, string, error
logx.Errorf("copier.Copy err: %v", err)
return nil, "", errors.New("copy user failed")
}
user.Id = strconv.FormatInt(userResp.Users.Id, 10)
var verificationStatus map[string]string
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
if err != nil {
@@ -7,12 +7,14 @@ import (
"context"
"errors"
"fmt"
"regexp"
"strconv"
"time"
"juwan-backend/app/users/rpc/pb"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
"juwan-backend/common/utils/pwdUtils"
"regexp"
"time"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
@@ -95,6 +97,7 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (*types.RegisterResp, s
logx.Errorf("copier.Copy err: %v", err)
return nil, "", errors.New("copy user failed")
}
user.Id = strconv.FormatInt(userResp.Users.Id, 10)
var verificationStatus map[string]string
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
if err != nil {
@@ -6,6 +6,8 @@ package user
import (
"context"
"errors"
"strconv"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
@@ -31,15 +33,19 @@ func NewFollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Follow
}
func (l *FollowUserLogic) FollowUser(req *types.FollowUserReq) (resp *types.EmptyResp, err error) {
// todo: add your logic here and delete this line
userId, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, errors.New("unauthorized")
}
followeeId, err := strconv.ParseInt(req.Id, 10, 64)
if err != nil {
return nil, errors.New("invalid user id")
}
_, err = l.svcCtx.UserRpc.AddUserFollows(l.ctx, &usercenter.AddUserFollowsReq{
FollowerId: userId,
FolloweeId: req.Id,
FolloweeId: followeeId,
CreatedAt: 0,
})
if err != nil {
@@ -6,11 +6,13 @@ package user
import (
"context"
"errors"
"strconv"
"time"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
"time"
"github.com/jinzhu/copier"
"github.com/zeromicro/go-zero/core/logx"
@@ -56,6 +58,7 @@ func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
return nil, errors.New("copy user failed")
}
resp.Id = strconv.FormatInt(user.Users.Id, 10)
var verificationStatus map[string]string
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
if err != nil {
@@ -6,6 +6,8 @@ package user
import (
"context"
"errors"
"strconv"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
"juwan-backend/app/users/rpc/usercenter"
@@ -30,9 +32,13 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
}
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserReq) (resp types.User, err error) {
targetId, err := strconv.ParseInt(req.Id, 10, 64)
if err != nil {
return types.User{}, errors.New("invalid user id")
}
pbUser, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
Id: req.Id,
Id: targetId,
})
if err != nil {
return types.User{}, errors.New("failed to get user info by userid")
@@ -44,6 +50,7 @@ func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserReq) (resp types.User,
logx.Errorf("struct to user info failed, err:%v.", err)
return types.User{}, errors.New("failed to get user info by userid")
}
user.Id = strconv.FormatInt(pbUser.Users.Id, 10)
user.Role = pbUser.Users.CurrentRole
return user, nil
@@ -6,6 +6,8 @@ package user
import (
"context"
"errors"
"strconv"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
@@ -31,14 +33,18 @@ func NewUnfollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Unfo
}
func (l *UnfollowUserLogic) UnfollowUser(req *types.UnfollowUserReq) (resp *types.EmptyResp, err error) {
// todo: add your logic here and delete this line
userId, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, errors.New("unauthorized")
}
targetId, err := strconv.ParseInt(req.Id, 10, 64)
if err != nil {
return nil, errors.New("invalid user id")
}
_, err = l.svcCtx.UserRpc.DelUserFollows(l.ctx, &usercenter.DelUserFollowsReq{
Id: req.Id,
Id: targetId,
UserId: userId,
})
if err != nil {
@@ -6,11 +6,13 @@ package user
import (
"context"
"errors"
"strconv"
"strings"
"time"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/converter"
"juwan-backend/common/utils/contextj"
"strings"
"time"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
@@ -64,6 +66,7 @@ func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserProfileReq) (resp *types.U
return nil, errors.New("get user failed")
}
resp.Id = strconv.FormatInt(user.Users.Id, 10)
var verificationStatus map[string]string
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
if err != nil {