initial commit
This commit is contained in:
45
gateway/internal/logic/getuserinfologic.go
Normal file
45
gateway/internal/logic/getuserinfologic.go
Normal file
@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
"godemo/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
|
||||
return &GetUserInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserInfoReq) (resp *types.GetUserInfoResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
rpcResp, err := l.svcCtx.UserRpc.GetUserInfo(l.ctx, &user.GetUserInfoRequest{
|
||||
UserId: req.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构造 API 返回值
|
||||
resp = &types.GetUserInfoResp{
|
||||
UserId: rpcResp.UserId,
|
||||
Username: rpcResp.Username,
|
||||
Email: rpcResp.Email,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
Roles: rpcResp.Roles,
|
||||
}
|
||||
return
|
||||
}
|
||||
43
gateway/internal/logic/loginlogic.go
Normal file
43
gateway/internal/logic/loginlogic.go
Normal file
@ -0,0 +1,43 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
"godemo/user/user"
|
||||
|
||||
"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) {
|
||||
// 调用 user RPC 的 Login 方法
|
||||
rpcResp, err := l.svcCtx.UserRpc.Login(l.ctx, &user.LoginRequest{
|
||||
Username: req.Username,
|
||||
Password: req.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构造 API 返回值
|
||||
resp = &types.LoginResp{
|
||||
Token: rpcResp.Token,
|
||||
ExpiresAt: rpcResp.ExpiresAt,
|
||||
}
|
||||
return
|
||||
}
|
||||
30
gateway/internal/logic/logoutlogic.go
Normal file
30
gateway/internal/logic/logoutlogic.go
Normal file
@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
|
||||
"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) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
40
gateway/internal/logic/registerlogic.go
Normal file
40
gateway/internal/logic/registerlogic.go
Normal file
@ -0,0 +1,40 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
"godemo/user/user"
|
||||
|
||||
"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,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterResp, err error) {
|
||||
rpcResp, err := l.svcCtx.UserRpc.Register(l.ctx, &user.RegisterRequest{
|
||||
Email: req.Email,
|
||||
Password: req.Password,
|
||||
Username: req.Username,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = &types.RegisterResp{
|
||||
UserId: rpcResp.UserId,
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user