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"`
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
// goctl 1.10.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"juwan-backend/common/middlewares"
|
||||
|
||||
"juwan-backend/app/users/api/internal/config"
|
||||
"juwan-backend/app/users/api/internal/handler"
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/common/middlewares"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/user-api.yaml", "the config file")
|
||||
var configFile = flag.String("f", "etc/users-api.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
+10
-10
@@ -70,7 +70,7 @@ type (
|
||||
EmptyResp {}
|
||||
// 用户信息核心模型 (User)
|
||||
User {
|
||||
Id int64 `json:"id"`
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
@@ -142,13 +142,13 @@ type (
|
||||
// =================================================================================
|
||||
type (
|
||||
GetUserReq {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
FollowUserReq {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
UnfollowUserReq {
|
||||
Id int64 `path:"id"`
|
||||
Id string `path:"id"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -159,7 +159,7 @@ type (
|
||||
group: auth
|
||||
prefix: /api/v1/auth
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "用户注册"
|
||||
@handler Register
|
||||
post /register (RegisterReq) returns (RegisterResp)
|
||||
@@ -177,7 +177,7 @@ service user-api {
|
||||
group: auth
|
||||
prefix: /api/v1/auth
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "退出登录"
|
||||
@handler Logout
|
||||
post /logout (LogoutReq) returns (EmptyResp)
|
||||
@@ -188,7 +188,7 @@ service user-api {
|
||||
prefix: /api/v1/users
|
||||
middleware: Logger
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "获取当前登录用户信息"
|
||||
@handler GetMe
|
||||
get /me returns (User)
|
||||
@@ -223,7 +223,7 @@ service user-api {
|
||||
group: user
|
||||
prefix: /api/v1/users
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "获取指定用户信息"
|
||||
@handler GetUserInfo
|
||||
get /:id (GetUserReq) returns (User)
|
||||
@@ -233,7 +233,7 @@ service user-api {
|
||||
group: verification_user
|
||||
prefix: /api/v1/users
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "提交或修改角色认证申请 (支持幂等更新)"
|
||||
@handler ApplyVerification
|
||||
post /me/verification (ApplyVerificationReq) returns (VerificationEmptyResp)
|
||||
@@ -247,7 +247,7 @@ service user-api {
|
||||
group: verification_admin
|
||||
prefix: /api/v1/admin
|
||||
)
|
||||
service user-api {
|
||||
service users-api {
|
||||
@doc "管理员获取认证申请列表 (分页)"
|
||||
@handler GetVerifications
|
||||
get /verifications (GetPendingListReq) returns (GetPendingListResp)
|
||||
|
||||
Reference in New Issue
Block a user