api.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package configuration
  2. import (
  3. "git.sxidc.com/go-framework/baize/binding"
  4. "git.sxidc.com/go-framework/baize/binding/response"
  5. "git.sxidc.com/go-framework/baize/convenient/value_object"
  6. "git.sxidc.com/go-framework/baize/domain"
  7. "git.sxidc.com/go-tools/utils/strutils"
  8. )
  9. func BindConfiguration(binder *binding.Binder, opts ...Option) {
  10. options := new(Options)
  11. for _, opt := range opts {
  12. opt(options)
  13. }
  14. configurationTableName := tableName
  15. if strutils.IsStringNotEmpty(options.schema) {
  16. configurationTableName = tableName + "." + options.schema
  17. }
  18. dbExecutorType := binding.DBExecutorOperations
  19. if strutils.IsStringNotEmpty(options.dbExecutorType) {
  20. dbExecutorType = options.dbExecutorType
  21. }
  22. value_object.BindSimple(binder, &value_object.Simple[any]{
  23. ValueObject: &Entity{},
  24. TableName: configurationTableName,
  25. DBExecutorType: dbExecutorType,
  26. DomainPath: "/configuration",
  27. CreateJsonBody: &AddConfigurationJsonBody{},
  28. DeleteQueryParams: &RemoveConfigurationQueryParams{},
  29. }, value_object.WithDisableQuery[any]())
  30. binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
  31. Path: "/configuration/values",
  32. RequestParams: &GetConfigurationValuesQueryParams{},
  33. Objects: []domain.Object{&Entity{}},
  34. Infrastructure: binder.ChooseDBExecutor(dbExecutorType),
  35. ServiceFunc: nil,
  36. ResponseFunc: response.SendMapResponse,
  37. })
  38. }
  39. type Option func(options *Options)
  40. type Options struct {
  41. schema string
  42. dbExecutorType string
  43. }
  44. func WithSchema(schema string) Option {
  45. return func(options *Options) {
  46. options.schema = schema
  47. }
  48. }
  49. func WithDBExecutorType(dbExecutorType string) Option {
  50. return func(options *Options) {
  51. options.dbExecutorType = dbExecutorType
  52. }
  53. }