add: some user api and all api desc
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type FollowUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 关注用户
|
||||
func NewFollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FollowUserLogic {
|
||||
return &FollowUserLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *FollowUserLogic) FollowUser(req *types.FollowUserReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -6,9 +6,10 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/converter"
|
||||
"juwan-backend/common/utils/contextx"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
@@ -31,7 +32,7 @@ func NewGetMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMeLogic
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetMeLogic) GetMe() (resp *types.UserInfo, err error) {
|
||||
func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
|
||||
userId, err := contextx.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("illegal id")
|
||||
@@ -43,6 +44,8 @@ func (l *GetMeLogic) GetMe() (resp *types.UserInfo, err error) {
|
||||
return nil, errors.New("get user by id error")
|
||||
}
|
||||
err = converter.StructToStruct(user, &resp)
|
||||
createAt := time.Unix(user.Users.CreatedAt, 0)
|
||||
resp.CreatedAt = createAt.Format(time.DateTime)
|
||||
if err != nil {
|
||||
return nil, errors.New("to struct error")
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/converter"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -30,21 +29,21 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserInfoReq) (resp types.UserInfo, err error) {
|
||||
|
||||
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserReq) (resp types.User, err error) {
|
||||
|
||||
pbUser, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||
Id: req.UserId,
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return types.UserInfo{}, errors.New("failed to get user info by userid")
|
||||
}
|
||||
user := types.UserInfo{}
|
||||
err = converter.StructToStruct(&pbUser.Users, &user)
|
||||
if err != nil {
|
||||
logx.Errorf("struct to user info failed, err:%v.", err)
|
||||
return types.UserInfo{}, errors.New("failed to get user info by userid")
|
||||
return types.User{}, errors.New("failed to get user info by userid")
|
||||
}
|
||||
|
||||
user := types.User{}
|
||||
err = copier.Copy(&user, &pbUser.Users)
|
||||
if err != nil {
|
||||
logx.Errorf("struct to user info failed, err:%v.", err)
|
||||
return types.User{}, errors.New("failed to get user info by userid")
|
||||
}
|
||||
|
||||
//req.UserId
|
||||
return user, nil
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 用户登录接口
|
||||
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
||||
return &LoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
||||
if len(req.Username) < 3 || len(req.Password) < 8 || len(req.Password) > 20 {
|
||||
return nil, errors.New("the information is illegal")
|
||||
}
|
||||
|
||||
res, err := l.svcCtx.UserRpc.Login(l.ctx, &usercenter.LoginReq{
|
||||
Username: req.Username,
|
||||
Passwd: req.Password,
|
||||
})
|
||||
logx.Infof("res:%v", res)
|
||||
if err != nil {
|
||||
logx.Errorf("rpc login err: %v", err)
|
||||
return nil, errors.New("login fail")
|
||||
}
|
||||
|
||||
if res == nil || res.Id <= 0 || res.Username == "" || res.Token == "" {
|
||||
logx.Errorf("rpc login returned empty payload, username=%s, resp=%+v", req.Username, res)
|
||||
return nil, errors.New("login fail")
|
||||
}
|
||||
|
||||
return &types.LoginResp{
|
||||
UserId: res.Id,
|
||||
Username: res.Username,
|
||||
Email: res.Email,
|
||||
Token: res.Token,
|
||||
Expires: int64((7 * 24 * time.Hour).Seconds()),
|
||||
}, nil
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LogoutLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 用户登出
|
||||
func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
|
||||
return &LogoutLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LogoutLogic) Logout(req *types.LogoutReq) (resp *types.LogoutResp, err error) {
|
||||
if req.UserId <= 0 {
|
||||
return nil, errors.New("invalid userId")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UserRpc.Logout(l.ctx, &usercenter.LogoutReq{UserId: req.UserId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.LogoutResp{Message: "logout success"}, nil
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"regexp"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/utils"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RegisterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 用户注册接口
|
||||
func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
|
||||
return &RegisterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
var usernameRegex = regexp.MustCompile("^[a-zA-Z0-9_]+$")
|
||||
|
||||
func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterResp, err error) {
|
||||
existingUser, err := l.svcCtx.UserRpc.GetUserByUsername(l.ctx, &pb.GetUserByUsernameReq{
|
||||
Username: req.Username,
|
||||
})
|
||||
if len(req.Username) < 3 {
|
||||
return nil, errors.New("username must be at least 3 characters long")
|
||||
}
|
||||
if len(req.Username) > 20 {
|
||||
return nil, errors.New("username must be at most 20 characters long")
|
||||
}
|
||||
if !usernameRegex.MatchString(req.Username) {
|
||||
return nil, errors.New("username can only contain letters, numbers, and underscores")
|
||||
}
|
||||
if err == nil && existingUser != nil {
|
||||
return nil, errors.New("user already exists")
|
||||
}
|
||||
|
||||
hashedPassword, err := utils.HashPassword(req.Password)
|
||||
if err != nil {
|
||||
return nil, errors.New("hash password failed")
|
||||
}
|
||||
|
||||
requestId, err := contextx.RequestIdFrom(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("contextx.RequestIdFrom failed: %v", err)
|
||||
return nil, errors.New("contextx.RequestIdFrom failed")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UserRpc.Register(l.ctx, &usercenter.RegisterReq{
|
||||
Username: req.Username,
|
||||
Passwd: hashedPassword,
|
||||
Phone: req.Username,
|
||||
Vcode: req.Vcode,
|
||||
Email: req.Email,
|
||||
RequestId: requestId,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("failed to register user: ", err)
|
||||
return nil, errors.New("failed to register user")
|
||||
}
|
||||
|
||||
// 返回响应
|
||||
return &types.RegisterResp{
|
||||
UserId: 0,
|
||||
Username: req.Username,
|
||||
Email: req.Email,
|
||||
Message: "register success",
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/utils/contextx"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type SwitchRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 切换当前激活角色
|
||||
func NewSwitchRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SwitchRoleLogic {
|
||||
return &SwitchRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SwitchRoleLogic) SwitchRole(req *types.SwitchRoleReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
id, err := contextx.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("get user id from context: %v", err)
|
||||
return nil, errors.New("illegal id")
|
||||
}
|
||||
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||
Id: id,
|
||||
CurrentRole: proto.String(req.Role),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logx.Errorf("update user info by id: %v", err)
|
||||
return nil, errors.New("update user info by userid")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UnfollowUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 取消关注用户
|
||||
func NewUnfollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnfollowUserLogic {
|
||||
return &UnfollowUserLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UnfollowUserLogic) UnfollowUser(req *types.UnfollowUserReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -6,9 +6,10 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/converter"
|
||||
"juwan-backend/common/utils/contextx"
|
||||
"strings"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
@@ -31,16 +32,16 @@ func NewUpdateMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMe
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserInfoReq) (resp *types.UserInfo, err error) {
|
||||
func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserProfileReq) (resp *types.UpdateUserProfileReq, err error) {
|
||||
userId, err := contextx.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||
Id: userId,
|
||||
Nickname: req.Nickname,
|
||||
Avatar: req.Avatar,
|
||||
Bio: req.Bio,
|
||||
Nickname: proto_string(req.Nickname),
|
||||
Avatar: proto_string(req.Avatar),
|
||||
Bio: proto_string(req.Bio),
|
||||
VerifiedRoles: nil,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -53,3 +54,10 @@ func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserInfoReq) (resp *types.User
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func proto_string(s string) *string {
|
||||
if len(s) == 0 || strings.Contains(s, " ") {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateNotificationSettingsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 更新通知偏好
|
||||
func NewUpdateNotificationSettingsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNotificationSettingsLogic {
|
||||
return &UpdateNotificationSettingsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateNotificationSettingsLogic) UpdateNotificationSettings(req *types.UpdateNotifySettingsReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/utils"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdatePasswordByVcodeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 修改密码-使用验证码
|
||||
func NewUpdatePasswordByVcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordByVcodeLogic {
|
||||
return &UpdatePasswordByVcodeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdatePasswordByVcodeLogic) UpdatePasswordByVcode(req *types.ResetPasswordByVcode) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
requestId, err := contextx.RequestIdFrom(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("get request id from context failed, err:%v.", err)
|
||||
return nil, errors.New("bad request")
|
||||
}
|
||||
hashedPassword, err := utils.HashPassword(req.Password)
|
||||
if err != nil {
|
||||
logx.Errorf("hash password failed, err:%v.", err)
|
||||
return nil, errors.New("bad password")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UserRpc.ResetPassword(l.ctx, &usercenter.ResetPasswordReq{
|
||||
NewPassword: hashedPassword,
|
||||
Email: req.Email,
|
||||
RequestId: requestId,
|
||||
Vcode: req.Vcode,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("reset password failed, err:%v.", err)
|
||||
return nil, errors.New("reset password failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/utils"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
var ChangeUserPassFailed = errors.New("change user pass failed")
|
||||
|
||||
type UpdatePasswordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 修改用户密码
|
||||
func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
|
||||
return &UpdatePasswordLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordReq) (resp *types.UpdatePasswordResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
userId, err := contextx.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("get user id from context failed, err:%v.", err)
|
||||
return nil, ChangeUserPassFailed
|
||||
}
|
||||
|
||||
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||
Id: userId,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("get user info failed, err:%v.", err)
|
||||
return nil, ChangeUserPassFailed
|
||||
}
|
||||
|
||||
oldPasswd, err := utils.HashPassword(req.OldPassword)
|
||||
if err != nil {
|
||||
logx.Errorf("hash old password failed, err:%v.", err)
|
||||
return nil, ChangeUserPassFailed
|
||||
}
|
||||
|
||||
if oldPasswd != user.Users.PasswordHash {
|
||||
return nil, ChangeUserPassFailed
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||
Id: userId,
|
||||
Username: &user.Users.Username,
|
||||
PasswordHash: &req.NewPassword,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("update user password failed, err:%v.", err)
|
||||
return nil, ChangeUserPassFailed
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateThemeSettingsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 更新主题偏好
|
||||
func NewUpdateThemeSettingsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateThemeSettingsLogic {
|
||||
return &UpdateThemeSettingsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateThemeSettingsLogic) UpdateThemeSettings(req *types.UpdateThemeSettingsReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/contextx"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 修改用户信息
|
||||
func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic {
|
||||
return &UpdateUserInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateUserInfoLogic) UpdateUserInfo(req *types.UpdateUserInfoReq) (resp *types.UpdateUserInfoResp, err error) {
|
||||
userId, err := contextx.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||
Id: userId,
|
||||
Nickname: req.Nickname,
|
||||
Avatar: req.Avatar,
|
||||
Bio: req.Bio,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New("update user info failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user