package one2many import ( "git.sxidc.com/go-framework/baize/binding" "git.sxidc.com/go-framework/baize/binding/request" "git.sxidc.com/go-framework/baize/domain" ) // Simple 关联的Bind参数 // LI 为左边实体的Info类型 // RI 为右边实体的Info类型 type Simple[LI any, RI any] struct { // 左领域实体,注意是Entity类型 Left domain.Entity // 右领域实体,注意是Entity类型 Right domain.Entity // 左表名 LeftTableName string // 右表名 RightTableName string // URL领域相对路径,如/class/students,后面会自动补充,如/class/students/update LeftDomainPath string // URL领域相对路径,如/student/classes,后面会自动补充,如/student/classes/update RightDomainPath string // 更新左实体关联使用的请求参数 LeftUpdateJsonBody request.Params // 查询左实体关联使用的请求参数,注意是Query类型 LeftQueryQueryParams request.Query // 更新左实体关联使用的请求参数 RightUpdateJsonBody request.Params // 查询右实体关联使用的请求参数,注意是Query类型 RightQueryQueryParams request.Query // 查询右实体带左实体信息使用的请求参数,注意是Query类型 RightQueryWithLeftQueryParams request.Query // 可选配置项,通过WithXXX配置 options *Options[LI, RI] } func (simple *Simple[LI, RI]) bind(binder *binding.Binder) { //options := simple.options } func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option[LI, RI]) { options := new(Options[LI, RI]) for _, opt := range opts { opt(options) } simple.options = options simple.bind(binder) } type Option[LI any, RI any] func(options *Options[LI, RI]) type Options[LI any, RI any] struct { // 右实体中指向左实体的字段 rightRelationField string // 右实体中指向左实体的列名 rightRelationColumn string // 关闭左侧到右侧关联 disableLeft bool // 关闭右侧到左侧关联 disableRight bool // 关闭左侧更新 disableLeftUpdate bool // 关闭左侧查询 disableLeftQuery bool // 关闭右侧更新 disableRightUpdate bool // 关闭右侧查询 disableRightQuery bool // 关闭右实体带左实体信息查询 disableRightWithLeftQuery bool } func WithRightRelationField[LI any, RI any](rightRelationField string) Option[LI, RI] { return func(options *Options[LI, RI]) { options.rightRelationField = rightRelationField } } func WithRightRelationColumn[LI any, RI any](rightRelationColumn string) Option[LI, RI] { return func(options *Options[LI, RI]) { options.rightRelationColumn = rightRelationColumn } } func WithDisableLeft[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableLeft = true } } func WithDisableRight[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableRight = true } } func WithDisableLeftUpdate[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableLeftUpdate = true } } func WithDisableLeftQuery[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableLeftQuery = true } } func WithDisableRightUpdate[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableRightUpdate = true } } func WithDisableRightQuery[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableRightQuery = true } } func WithDisableRightWithLeftQuery[LI any, RI any]() Option[LI, RI] { return func(options *Options[LI, RI]) { options.disableRightWithLeftQuery = true } }