initial commit

This commit is contained in:
2025-05-22 19:39:08 +08:00
commit 531bb42d01
103 changed files with 10291 additions and 0 deletions

View 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
}

View 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
}

View 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
}

View 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
}