所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数
This commit is contained in:
@@ -2,6 +2,9 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/webset/internal/logic"
|
||||
"fusenapi/server/webset/internal/svc"
|
||||
@@ -12,10 +15,21 @@ func WebSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.RequestWebSet
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewWetSetSettingLogic(r.Context(), svcCtx)
|
||||
l := logic.NewWebSetSettingLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.WebSetSetting(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,24 +15,31 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type WetSetSettingLogic struct {
|
||||
type WebSetSettingLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WetSetSettingLogic {
|
||||
return &WetSetSettingLogic{
|
||||
func NewWebSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebSetSettingLogic {
|
||||
return &WebSetSettingLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WetSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *WebSetSettingLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向
|
||||
// func (l *WebSetSettingLogic) AfterLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *WebSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
typeConf := constants.TypeWebSet(req.Type)
|
||||
|
||||
//如果是这三个配置项 则读取缓存
|
||||
@@ -52,4 +59,6 @@ func (l *WetSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *a
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, result)
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestWetSetLogic(t *testing.T) {
|
||||
func TestWebSetLogic(t *testing.T) {
|
||||
var err error
|
||||
var resp *requests.Response
|
||||
var result gjson.Result
|
||||
Reference in New Issue
Block a user