|
|
@@ -26,66 +26,88 @@ func BindConfiguration(binder *binding.Binder, opts ...Option) {
|
|
|
configurationTableName = options.schema + "." + tableName
|
|
|
}
|
|
|
|
|
|
+ valueObjectOptions := []value_object.Option[any]{value_object.WithDisableQuery[any]()}
|
|
|
+
|
|
|
+ if options.disableCreate {
|
|
|
+ valueObjectOptions = append(valueObjectOptions, value_object.WithDisableCreate[any]())
|
|
|
+ }
|
|
|
+
|
|
|
+ if options.disableDelete {
|
|
|
+ valueObjectOptions = append(valueObjectOptions, value_object.WithDisableDelete[any]())
|
|
|
+ }
|
|
|
+
|
|
|
value_object.BindSimple(binder, &value_object.Simple[any]{
|
|
|
ValueObject: &Entity{},
|
|
|
TableName: configurationTableName,
|
|
|
DomainPath: "/configuration",
|
|
|
CreateJsonBody: &AddConfigurationJsonBody{},
|
|
|
DeleteQueryParams: &RemoveConfigurationJsonBody{},
|
|
|
- }, value_object.WithDisableQuery[any]())
|
|
|
-
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
- Path: "/configuration/values",
|
|
|
- ResponseFunc: response.SendMapResponse,
|
|
|
- RequestParams: &GetConfigurationValuesQueryParams{},
|
|
|
- Objects: []domain.Object{&Entity{}},
|
|
|
- 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].(*Entity)
|
|
|
- if !ok {
|
|
|
- return map[string]any{
|
|
|
- "values": make([]string, 0),
|
|
|
- }, fserr.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,
|
|
|
- SelectColumns: []string{ColumnValue},
|
|
|
- Conditions: conditions,
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
+ }, valueObjectOptions...)
|
|
|
+
|
|
|
+ if !options.disableQuery {
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
+ Path: "/configuration/values",
|
|
|
+ ResponseFunc: response.SendMapResponse,
|
|
|
+ RequestParams: &GetConfigurationValuesQueryParams{},
|
|
|
+ Objects: []domain.Object{&Entity{}},
|
|
|
+ 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].(*Entity)
|
|
|
+ if !ok {
|
|
|
+ return map[string]any{
|
|
|
+ "values": make([]string, 0),
|
|
|
+ }, fserr.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,
|
|
|
+ SelectColumns: []string{ColumnValue},
|
|
|
+ Conditions: conditions,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return map[string]any{
|
|
|
+ "values": make([]string, 0),
|
|
|
+ }, err
|
|
|
+ }
|
|
|
+
|
|
|
+ values := make([]string, 0)
|
|
|
+ for _, result := range results {
|
|
|
+ values = append(values, result.ColumnValueString(ColumnValue))
|
|
|
+ }
|
|
|
+
|
|
|
return map[string]any{
|
|
|
- "values": make([]string, 0),
|
|
|
- }, err
|
|
|
- }
|
|
|
-
|
|
|
- values := make([]string, 0)
|
|
|
- for _, result := range results {
|
|
|
- values = append(values, result.ColumnValueString(ColumnValue))
|
|
|
- }
|
|
|
-
|
|
|
- return map[string]any{
|
|
|
- "values": values,
|
|
|
- }, nil
|
|
|
- },
|
|
|
- })
|
|
|
+ "values": values,
|
|
|
+ }, nil
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
type Option func(options *Options)
|
|
|
|
|
|
type Options struct {
|
|
|
+ // 表schema
|
|
|
schema string
|
|
|
+
|
|
|
+ // 创建删除
|
|
|
+ disableCreate bool
|
|
|
+
|
|
|
+ // 关闭删除
|
|
|
+ disableDelete bool
|
|
|
+
|
|
|
+ // 关闭查询
|
|
|
+ disableQuery bool
|
|
|
}
|
|
|
|
|
|
func WithSchema(schema string) Option {
|
|
|
@@ -93,3 +115,21 @@ func WithSchema(schema string) Option {
|
|
|
options.schema = schema
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+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
|
|
|
+ }
|
|
|
+}
|