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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"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)
|
logx.Errorf("copier.Copy err: %v", err)
|
||||||
return nil, "", errors.New("copy user failed")
|
return nil, "", errors.New("copy user failed")
|
||||||
}
|
}
|
||||||
|
user.Id = strconv.FormatInt(userResp.Users.Id, 10)
|
||||||
var verificationStatus map[string]string
|
var verificationStatus map[string]string
|
||||||
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
|
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/users/rpc/pb"
|
"juwan-backend/app/users/rpc/pb"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"juwan-backend/common/utils/contextj"
|
||||||
"juwan-backend/common/utils/pwdUtils"
|
"juwan-backend/common/utils/pwdUtils"
|
||||||
"regexp"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"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)
|
logx.Errorf("copier.Copy err: %v", err)
|
||||||
return nil, "", errors.New("copy user failed")
|
return nil, "", errors.New("copy user failed")
|
||||||
}
|
}
|
||||||
|
user.Id = strconv.FormatInt(userResp.Users.Id, 10)
|
||||||
var verificationStatus map[string]string
|
var verificationStatus map[string]string
|
||||||
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
|
err = json.Unmarshal([]byte(userResp.Users.VerificationStatus), &verificationStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"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) {
|
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)
|
userId, err := contextj.UserIDFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("unauthorized")
|
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{
|
_, err = l.svcCtx.UserRpc.AddUserFollows(l.ctx, &usercenter.AddUserFollowsReq{
|
||||||
FollowerId: userId,
|
FollowerId: userId,
|
||||||
FolloweeId: req.Id,
|
FolloweeId: followeeId,
|
||||||
CreatedAt: 0,
|
CreatedAt: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"juwan-backend/common/utils/contextj"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"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")
|
return nil, errors.New("copy user failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Id = strconv.FormatInt(user.Users.Id, 10)
|
||||||
var verificationStatus map[string]string
|
var verificationStatus map[string]string
|
||||||
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"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) {
|
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{
|
pbUser, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||||
Id: req.Id,
|
Id: targetId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.User{}, errors.New("failed to get user info by userid")
|
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)
|
logx.Errorf("struct to user info failed, err:%v.", err)
|
||||||
return types.User{}, errors.New("failed to get user info by userid")
|
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
|
user.Role = pbUser.Users.CurrentRole
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"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) {
|
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)
|
userId, err := contextj.UserIDFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("unauthorized")
|
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{
|
_, err = l.svcCtx.UserRpc.DelUserFollows(l.ctx, &usercenter.DelUserFollowsReq{
|
||||||
Id: req.Id,
|
Id: targetId,
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/converter"
|
"juwan-backend/common/converter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"juwan-backend/common/utils/contextj"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"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")
|
return nil, errors.New("get user failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Id = strconv.FormatInt(user.Users.Id, 10)
|
||||||
var verificationStatus map[string]string
|
var verificationStatus map[string]string
|
||||||
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type EmptyResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FollowUserReq struct {
|
type FollowUserReq struct {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetMyVerificationsResp struct {
|
type GetMyVerificationsResp struct {
|
||||||
@@ -32,7 +32,7 @@ type GetPendingListResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetUserReq struct {
|
type GetUserReq struct {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginReq struct {
|
type LoginReq struct {
|
||||||
@@ -85,7 +85,7 @@ type SwitchRoleReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UnfollowUserReq struct {
|
type UnfollowUserReq struct {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateNotifySettingsReq struct {
|
type UpdateNotifySettingsReq struct {
|
||||||
@@ -105,7 +105,7 @@ type UpdateUserProfileReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64 `json:"id"`
|
Id string `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.10.1
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"juwan-backend/common/middlewares"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/config"
|
"juwan-backend/app/users/api/internal/config"
|
||||||
"juwan-backend/app/users/api/internal/handler"
|
"juwan-backend/app/users/api/internal/handler"
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|||||||
+10
-10
@@ -70,7 +70,7 @@ type (
|
|||||||
EmptyResp {}
|
EmptyResp {}
|
||||||
// 用户信息核心模型 (User)
|
// 用户信息核心模型 (User)
|
||||||
User {
|
User {
|
||||||
Id int64 `json:"id"`
|
Id string `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
@@ -142,13 +142,13 @@ type (
|
|||||||
// =================================================================================
|
// =================================================================================
|
||||||
type (
|
type (
|
||||||
GetUserReq {
|
GetUserReq {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
FollowUserReq {
|
FollowUserReq {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
UnfollowUserReq {
|
UnfollowUserReq {
|
||||||
Id int64 `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ type (
|
|||||||
group: auth
|
group: auth
|
||||||
prefix: /api/v1/auth
|
prefix: /api/v1/auth
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "用户注册"
|
@doc "用户注册"
|
||||||
@handler Register
|
@handler Register
|
||||||
post /register (RegisterReq) returns (RegisterResp)
|
post /register (RegisterReq) returns (RegisterResp)
|
||||||
@@ -177,7 +177,7 @@ service user-api {
|
|||||||
group: auth
|
group: auth
|
||||||
prefix: /api/v1/auth
|
prefix: /api/v1/auth
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "退出登录"
|
@doc "退出登录"
|
||||||
@handler Logout
|
@handler Logout
|
||||||
post /logout (LogoutReq) returns (EmptyResp)
|
post /logout (LogoutReq) returns (EmptyResp)
|
||||||
@@ -188,7 +188,7 @@ service user-api {
|
|||||||
prefix: /api/v1/users
|
prefix: /api/v1/users
|
||||||
middleware: Logger
|
middleware: Logger
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "获取当前登录用户信息"
|
@doc "获取当前登录用户信息"
|
||||||
@handler GetMe
|
@handler GetMe
|
||||||
get /me returns (User)
|
get /me returns (User)
|
||||||
@@ -223,7 +223,7 @@ service user-api {
|
|||||||
group: user
|
group: user
|
||||||
prefix: /api/v1/users
|
prefix: /api/v1/users
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "获取指定用户信息"
|
@doc "获取指定用户信息"
|
||||||
@handler GetUserInfo
|
@handler GetUserInfo
|
||||||
get /:id (GetUserReq) returns (User)
|
get /:id (GetUserReq) returns (User)
|
||||||
@@ -233,7 +233,7 @@ service user-api {
|
|||||||
group: verification_user
|
group: verification_user
|
||||||
prefix: /api/v1/users
|
prefix: /api/v1/users
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "提交或修改角色认证申请 (支持幂等更新)"
|
@doc "提交或修改角色认证申请 (支持幂等更新)"
|
||||||
@handler ApplyVerification
|
@handler ApplyVerification
|
||||||
post /me/verification (ApplyVerificationReq) returns (VerificationEmptyResp)
|
post /me/verification (ApplyVerificationReq) returns (VerificationEmptyResp)
|
||||||
@@ -247,7 +247,7 @@ service user-api {
|
|||||||
group: verification_admin
|
group: verification_admin
|
||||||
prefix: /api/v1/admin
|
prefix: /api/v1/admin
|
||||||
)
|
)
|
||||||
service user-api {
|
service users-api {
|
||||||
@doc "管理员获取认证申请列表 (分页)"
|
@doc "管理员获取认证申请列表 (分页)"
|
||||||
@handler GetVerifications
|
@handler GetVerifications
|
||||||
get /verifications (GetPendingListReq) returns (GetPendingListResp)
|
get /verifications (GetPendingListReq) returns (GetPendingListResp)
|
||||||
|
|||||||
Reference in New Issue
Block a user