|
|
@@ -19,125 +19,70 @@ import (
|
|
|
type Simple struct {
|
|
|
// schema
|
|
|
Schema string
|
|
|
-
|
|
|
- // 可选配置项,通过WithXXX配置
|
|
|
- options *Options
|
|
|
}
|
|
|
|
|
|
func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
- options := simple.options
|
|
|
-
|
|
|
configurationTableName := domain.TableName(simple.Schema, &ValueObject{})
|
|
|
- valueObjectOptions := []any{value_object_crud.WithDisableQuery[any]()}
|
|
|
-
|
|
|
- if options.disableCreate {
|
|
|
- valueObjectOptions = append(valueObjectOptions, value_object_crud.WithDisableCreate())
|
|
|
- }
|
|
|
-
|
|
|
- if options.disableDelete {
|
|
|
- valueObjectOptions = append(valueObjectOptions, value_object_crud.WithDisableDelete())
|
|
|
- }
|
|
|
|
|
|
value_object_crud.BindSimple(binder, &value_object_crud.Simple[any]{
|
|
|
ValueObject: &ValueObject{},
|
|
|
Schema: simple.Schema,
|
|
|
CreateJsonBody: &AddConfigurationJsonBody{},
|
|
|
DeleteJsonBody: &RemoveConfigurationJsonBody{},
|
|
|
- }, valueObjectOptions...)
|
|
|
-
|
|
|
- if !options.disableQuery {
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
- Path: "/configuration/values",
|
|
|
- SendResponseFunc: response.SendMapResponse,
|
|
|
- RequestParams: &GetConfigurationValuesQueryParams{},
|
|
|
- Objects: []domain.Object{&ValueObject{}},
|
|
|
- ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (map[string]any, error) {
|
|
|
- dbExecutor := i.DBExecutor()
|
|
|
-
|
|
|
- e, ok := objects[0].(*ValueObject)
|
|
|
- if !ok {
|
|
|
- return map[string]any{
|
|
|
- "values": make([]string, 0),
|
|
|
- }, errors.New("传递的实体不是该领域的实体")
|
|
|
- }
|
|
|
-
|
|
|
- conditions := sql.NewConditions()
|
|
|
-
|
|
|
- if strutils.IsStringNotEmpty(e.Scope) {
|
|
|
- conditions.Equal(ColumnScope, e.Scope)
|
|
|
- }
|
|
|
-
|
|
|
- if strutils.IsStringNotEmpty(e.Group) {
|
|
|
- conditions.Equal(ColumnGroup, e.Group)
|
|
|
- }
|
|
|
-
|
|
|
- results, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
|
|
|
- TableName: configurationTableName,
|
|
|
- SelectClauses: []string{ColumnValue},
|
|
|
- Conditions: conditions,
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- return map[string]any{
|
|
|
- "values": make([]string, 0),
|
|
|
- }, err
|
|
|
- }
|
|
|
-
|
|
|
- values := make([]string, 0)
|
|
|
- err = sql.ParseSqlResult(results, &values)
|
|
|
- if err != nil {
|
|
|
- return map[string]any{
|
|
|
- "values": make([]string, 0),
|
|
|
- }, err
|
|
|
- }
|
|
|
+ })
|
|
|
+
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
+ Path: "/configuration/values",
|
|
|
+ SendResponseFunc: response.SendMapResponse,
|
|
|
+ RequestParams: &GetConfigurationValuesQueryParams{},
|
|
|
+ Objects: []domain.Object{&ValueObject{}},
|
|
|
+ ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (map[string]any, error) {
|
|
|
+ dbExecutor := i.DBExecutor()
|
|
|
+
|
|
|
+ e, ok := objects[0].(*ValueObject)
|
|
|
+ if !ok {
|
|
|
+ return map[string]any{
|
|
|
+ "values": make([]string, 0),
|
|
|
+ }, errors.New("传递的实体不是该领域的实体")
|
|
|
+ }
|
|
|
+
|
|
|
+ conditions := sql.NewConditions()
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(e.Scope) {
|
|
|
+ conditions.Equal(ColumnScope, e.Scope)
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(e.Group) {
|
|
|
+ conditions.Equal(ColumnGroup, e.Group)
|
|
|
+ }
|
|
|
+
|
|
|
+ results, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
|
|
|
+ TableName: configurationTableName,
|
|
|
+ SelectClauses: []string{ColumnValue},
|
|
|
+ Conditions: conditions,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return map[string]any{
|
|
|
+ "values": make([]string, 0),
|
|
|
+ }, err
|
|
|
+ }
|
|
|
|
|
|
+ values := make([]string, 0)
|
|
|
+ err = sql.ParseSqlResult(results, &values)
|
|
|
+ if err != nil {
|
|
|
return map[string]any{
|
|
|
- "values": values,
|
|
|
- }, nil
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
+ "values": make([]string, 0),
|
|
|
+ }, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return map[string]any{
|
|
|
+ "values": values,
|
|
|
+ }, nil
|
|
|
+ },
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-func BindConfiguration(app *application.App, simple *Simple, opts ...Option) {
|
|
|
- options := new(Options)
|
|
|
-
|
|
|
- for _, opt := range opts {
|
|
|
- opt(options)
|
|
|
- }
|
|
|
-
|
|
|
- simple.options = options
|
|
|
-
|
|
|
+func BindConfiguration(app *application.App, simple *Simple) {
|
|
|
binder := binding.NewBinder(app.Api().ChooseRouter(api.RouterPrefix, ""), app.Infrastructure())
|
|
|
simple.bind(binder)
|
|
|
}
|
|
|
-
|
|
|
-type Option func(options *Options)
|
|
|
-
|
|
|
-type Options struct {
|
|
|
- // 创建删除
|
|
|
- disableCreate bool
|
|
|
-
|
|
|
- // 关闭删除
|
|
|
- disableDelete bool
|
|
|
-
|
|
|
- // 关闭查询
|
|
|
- disableQuery bool
|
|
|
-}
|
|
|
-
|
|
|
-func WithDisableCreate() Option {
|
|
|
- return func(options *Options) {
|
|
|
- options.disableCreate = true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func WithDisableDelete() Option {
|
|
|
- return func(options *Options) {
|
|
|
- options.disableDelete = true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func WithDisableQuery() Option {
|
|
|
- return func(options *Options) {
|
|
|
- options.disableQuery = true
|
|
|
- }
|
|
|
-}
|