simple.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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"
  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. LeftTableName string
  17. // 右表名
  18. RightTableName string
  19. // URL领域相对路径,如/class,后面会自动补充,如/class/右领域path/update
  20. LeftDomainPath string
  21. // URL领域相对路径,如/student,后面会自动补充,如/student/左领域path/update
  22. RightDomainPath string
  23. // 更新左实体关联使用的请求参数
  24. LeftUpdateJsonBody request.Params
  25. // 查询左实体关联使用的请求参数,注意是Query类型
  26. LeftQueryQueryParams request.Query
  27. // 更新左实体关联使用的请求参数
  28. RightUpdateJsonBody request.Params
  29. // 查询右实体关联使用的请求参数,注意是Query类型
  30. RightQueryQueryParams request.Query
  31. // 查询右实体带左实体信息使用的请求参数,注意是Query类型
  32. RightQueryWithLeftQueryParams request.Query
  33. // 可选配置项,通过WithXXX配置
  34. options *Options
  35. }
  36. func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
  37. //options := simple.options
  38. }
  39. func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
  40. options := new(Options)
  41. for _, opt := range opts {
  42. opt(options)
  43. }
  44. simple.options = options
  45. simple.bind(binder)
  46. }
  47. type Option func(options *Options)
  48. type Options struct {
  49. // 关闭左侧到右侧关联
  50. disableLeft bool
  51. // 关闭右侧到左侧关联
  52. disableRight bool
  53. // 关闭左侧更新
  54. disableLeftUpdate bool
  55. // 关闭左侧查询
  56. disableLeftQuery bool
  57. // 关闭右侧更新
  58. disableRightUpdate bool
  59. // 关闭右侧查询
  60. disableRightQuery bool
  61. // 关闭右实体带左实体信息查询
  62. disableRightWithLeftQuery bool
  63. }
  64. func WithDisableLeft() Option {
  65. return func(options *Options) {
  66. options.disableLeft = true
  67. }
  68. }
  69. func WithDisableRight() Option {
  70. return func(options *Options) {
  71. options.disableRight = true
  72. }
  73. }
  74. func WithDisableLeftUpdate() Option {
  75. return func(options *Options) {
  76. options.disableLeftUpdate = true
  77. }
  78. }
  79. func WithDisableLeftQuery() Option {
  80. return func(options *Options) {
  81. options.disableLeftQuery = true
  82. }
  83. }
  84. func WithDisableRightUpdate() Option {
  85. return func(options *Options) {
  86. options.disableRightUpdate = true
  87. }
  88. }
  89. func WithDisableRightQuery() Option {
  90. return func(options *Options) {
  91. options.disableRightQuery = true
  92. }
  93. }
  94. func WithDisableRightWithLeftQuery() Option {
  95. return func(options *Options) {
  96. options.disableRightWithLeftQuery = true
  97. }
  98. }