refactor(blazing): 重构登录模块并移除示例代码
- 重构了登录控制器和登录服务,使用了cool框架的控制器和服务结构 - 移除了注册相关代码和不必要的示例代码 - 更新了登录服务,关联了服务器列表模型 - 删除了与示例相关的模型和服务文件
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
baseservice "blazing/modules/base/service"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
@@ -21,6 +23,23 @@ type SessionRes struct {
|
||||
Session string `json:"session"`
|
||||
}
|
||||
|
||||
type BlazingController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
var biazing_service = service.NewLoginServiceService()
|
||||
|
||||
func init() {
|
||||
var blazing_controller = &BlazingController{
|
||||
&cool.Controller{
|
||||
Prefix: "/seer/game",
|
||||
Api: []string{},
|
||||
Service: biazing_service,
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(blazing_controller)
|
||||
}
|
||||
func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
||||
// res = &DemoSampleWelcomeRes{
|
||||
// BaseRes: cool.Ok("Welcome to Cool Admin Go"),
|
||||
@@ -44,7 +63,7 @@ func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (re
|
||||
}
|
||||
|
||||
accountID := res1.ID
|
||||
retsid, sid, err := service.NewLoginServiceService().GetSessionId(accountID)
|
||||
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
||||
if err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
@@ -53,7 +72,7 @@ func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (re
|
||||
|
||||
res.Session = retsid
|
||||
|
||||
if err := service.NewLoginServiceService().SaveSessionId(sid, gconv.String(accountID)); err != nil {
|
||||
if err := biazing_service.SaveSessionId(sid, gconv.String(accountID)); err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type BlazingController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
var demo_sample_controller = &BlazingController{
|
||||
&cool.Controller{
|
||||
Prefix: "/seer/game",
|
||||
Api: []string{},
|
||||
Service: service.NewDemoSampleService(),
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(demo_sample_controller)
|
||||
}
|
||||
|
||||
// 增加 Welcome 演示 方法
|
||||
type RegReq struct {
|
||||
g.Meta `path:"/reg" method:"POST"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
type RegRes struct {
|
||||
*cool.BaseRes
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func (c *BlazingController) Reg(ctx context.Context, req *RegReq) (res *cool.BaseRes, err error) {
|
||||
// res = &DemoSampleWelcomeRes{
|
||||
// BaseRes: cool.Ok("Welcome to Cool Admin Go"),
|
||||
// Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
|
||||
// }
|
||||
if err := g.Validator().Data(req).Run(ctx); err != nil {
|
||||
fmt.Println(err)
|
||||
res = cool.Ok(err)
|
||||
|
||||
} else {
|
||||
res = cool.Ok("注册成功")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user