simple.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package many2many
  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"
  6. )
  7. // Simple 关联的Bind参数
  8. // LI 为左边实体的Info类型
  9. // RI 为右边实体的Info类型
  10. type Simple[LI any, RI any] struct {
  11. // 左领域实体,注意是Entity类型
  12. Left domain.Entity
  13. // 右领域实体,注意是Entity类型
  14. Right domain.Entity
  15. // 中间表表名
  16. MiddleTableName string
  17. // URL领域相对路径,如/person,后面会自动补充,如/user/右领域path/update
  18. LeftDomainPath string
  19. // URL领域相对路径,如/identity,后面会自动补充,如/userInfo/左领域path/update
  20. RightDomainPath string
  21. // 更新左实体关联使用的请求参数
  22. LeftUpdateJsonBody request.Params
  23. // 查询左实体关联使用的请求参数,注意是Query类型
  24. LeftQueryQueryParams request.Query
  25. // 更新右实体关联使用的请求参数
  26. RightUpdateJsonBody request.Params
  27. // 查询右实体关联使用的请求参数,注意是Query类型
  28. RightQueryQueryParams request.Query
  29. // 可选配置项,通过WithXXX配置
  30. options *Options
  31. }
  32. func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
  33. //options := simple.options
  34. }
  35. func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
  36. options := new(Options)
  37. for _, opt := range opts {
  38. opt(options)
  39. }
  40. simple.options = options
  41. simple.bind(binder)
  42. }
  43. type Option func(options *Options)
  44. type Options struct {
  45. // 关闭左侧到右侧关联
  46. disableLeft bool
  47. // 关闭右侧到左侧关联
  48. disableRight bool
  49. // 关闭左侧更新
  50. disableLeftUpdate bool
  51. // 关闭左侧查询
  52. disableLeftQuery bool
  53. // 关闭右侧更新
  54. disableRightUpdate bool
  55. // 关闭右侧查询
  56. disableRightQuery 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. }