simple.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package one2many
  2. import (
  3. "git.sxidc.com/go-framework/baize/convenient/binding"
  4. "git.sxidc.com/go-framework/baize/convenient/binding/request"
  5. "git.sxidc.com/go-framework/baize/framwork/domain/entity"
  6. )
  7. // Simple 关联的Bind参数
  8. // LI 为左边实体的Info类型
  9. // RI 为右边实体的Info类型
  10. type Simple[LI any, RI any] struct {
  11. // 左领域实体,注意是Entity类型
  12. Left entity.Entity
  13. // 右领域实体,注意是Entity类型
  14. Right entity.Entity
  15. // 数据库Schema
  16. Schema string
  17. // 更新左实体关联使用的请求参数
  18. LeftUpdateJsonBody request.Params
  19. // 查询左实体关联使用的请求参数,注意是Query类型
  20. LeftQueryQueryParams request.Query
  21. // 更新左实体关联使用的请求参数
  22. RightUpdateJsonBody request.Params
  23. // 查询右实体关联使用的请求参数,注意是Query类型
  24. RightQueryQueryParams request.Query
  25. // 查询右实体带左实体信息使用的请求参数,注意是Query类型
  26. RightQueryWithLeftQueryParams request.Query
  27. // 可选配置项,通过WithXXX配置
  28. options *Options
  29. }
  30. func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
  31. //options := simple.options
  32. }
  33. func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
  34. options := new(Options)
  35. for _, opt := range opts {
  36. opt(options)
  37. }
  38. simple.options = options
  39. simple.bind(binder)
  40. }
  41. type Option func(options *Options)
  42. type Options struct {
  43. // 关闭左侧到右侧关联
  44. disableLeft bool
  45. // 关闭右侧到左侧关联
  46. disableRight bool
  47. // 关闭左侧更新
  48. disableLeftUpdate bool
  49. // 关闭左侧查询
  50. disableLeftQuery bool
  51. // 关闭右侧更新
  52. disableRightUpdate bool
  53. // 关闭右侧查询
  54. disableRightQuery bool
  55. // 关闭右实体带左实体信息查询
  56. disableRightWithLeftQuery bool
  57. }
  58. func WithDisableLeft() Option {
  59. return func(options *Options) {
  60. options.disableLeft = true
  61. }
  62. }
  63. func WithDisableRight() Option {
  64. return func(options *Options) {
  65. options.disableRight = true
  66. }
  67. }
  68. func WithDisableLeftUpdate() Option {
  69. return func(options *Options) {
  70. options.disableLeftUpdate = true
  71. }
  72. }
  73. func WithDisableLeftQuery() Option {
  74. return func(options *Options) {
  75. options.disableLeftQuery = true
  76. }
  77. }
  78. func WithDisableRightUpdate() Option {
  79. return func(options *Options) {
  80. options.disableRightUpdate = true
  81. }
  82. }
  83. func WithDisableRightQuery() Option {
  84. return func(options *Options) {
  85. options.disableRightQuery = true
  86. }
  87. }
  88. func WithDisableRightWithLeftQuery() Option {
  89. return func(options *Options) {
  90. options.disableRightWithLeftQuery = true
  91. }
  92. }