fix: unify user ID type to string and rename service to users-api
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -12,7 +12,7 @@ type EmptyResp struct {
|
||||
}
|
||||
|
||||
type FollowUserReq struct {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type GetMyVerificationsResp struct {
|
||||
@@ -32,7 +32,7 @@ type GetPendingListResp struct {
|
||||
}
|
||||
|
||||
type GetUserReq struct {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type LoginReq struct {
|
||||
@@ -85,7 +85,7 @@ type SwitchRoleReq struct {
|
||||
}
|
||||
|
||||
type UnfollowUserReq struct {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type UpdateNotifySettingsReq struct {
|
||||
@@ -105,7 +105,7 @@ type UpdateUserProfileReq struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int64 `json:"id"`
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
|
||||
Reference in New Issue
Block a user