|
|
@@ -51,10 +51,10 @@ type SimpleBindItem[O any] struct {
|
|
|
DTO DTO
|
|
|
|
|
|
// 可选的dto绑定函数
|
|
|
- // 非必传,POST和PUT请求默认为JsonBody,DELETE默认为PathParams,Get默认为QueryParams
|
|
|
+ // 非必传,POST和PUT请求默认为JsonBody,DELETE默认为PathParams,GET默认为QueryParams
|
|
|
// 额外还提供了一些转化函数:
|
|
|
// MultipartForm: 绑定multipart form
|
|
|
- // Form: 绑定form body
|
|
|
+ // FormBody: 绑定form body
|
|
|
// XMLBody: 绑定XML body
|
|
|
DTOBindFunc DTOBindFunc
|
|
|
|
|
|
@@ -69,7 +69,6 @@ type SimpleBindItem[O any] struct {
|
|
|
Objects []domain.Object
|
|
|
|
|
|
// 应用服务泛型函数
|
|
|
- // 非必传,为nil时相当于使用了SmartUI
|
|
|
ServiceFunc ServiceFunc[O]
|
|
|
|
|
|
// 响应泛型函数,如果不响应,需要使用NoResponse零值占位
|
|
|
@@ -104,6 +103,10 @@ func (item *BindItem[O]) bind(router api.Router, middlewares ...api.Handler) {
|
|
|
panic("需要指定响应函数")
|
|
|
}
|
|
|
|
|
|
+ if item.ServiceFunc == nil {
|
|
|
+ panic("需要指定应用服务函数")
|
|
|
+ }
|
|
|
+
|
|
|
// 给单个路由增加中间件
|
|
|
handlers := []api.Handler{
|
|
|
func(c *api.Context) {
|
|
|
@@ -164,17 +167,15 @@ func (item *BindItem[O]) bind(router api.Router, middlewares ...api.Handler) {
|
|
|
}
|
|
|
|
|
|
// 执行业务函数
|
|
|
- if item.ServiceFunc != nil {
|
|
|
- statusCode := http.StatusOK
|
|
|
-
|
|
|
- outputModel, err := item.ServiceFunc(c, dto, domainObjects)
|
|
|
- if err != nil {
|
|
|
- statusCode = fserr.ParseCode(err).HttpCode
|
|
|
- }
|
|
|
+ statusCode := http.StatusOK
|
|
|
|
|
|
- item.ResponseFunc(c, statusCode, outputModel, err)
|
|
|
- return
|
|
|
+ outputModel, err := item.ServiceFunc(c, dto, domainObjects)
|
|
|
+ if err != nil {
|
|
|
+ statusCode = fserr.ParseCode(err).HttpCode
|
|
|
}
|
|
|
+
|
|
|
+ item.ResponseFunc(c, statusCode, outputModel, err)
|
|
|
+ return
|
|
|
},
|
|
|
}
|
|
|
|