package value_object_crud import ( "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-framework/baize/framework/core/domain/value_object" "git.sxidc.com/go-framework/baize/framework/core/infrastructure" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database" ) type CreateCallbacks struct { Prepare func(c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error) Before func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error After func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error OnSuccessReturn func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error OnErrorReturn func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error } func callbackPrepareCreate(callbacks *CreateCallbacks, c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error) { if callbacks == nil { return make(map[string]any), nil } if callbacks.Prepare == nil { return make(map[string]any), nil } return callbacks.Prepare(c, valueObject, i) } func callbackBeforeCreate(callbacks *CreateCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error { if callbacks == nil { return nil } if callbacks.Before == nil { return nil } return callbacks.Before(c, valueObject, prepared, i, tx) } func callbackAfterCreate(callbacks *CreateCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, valueObject, prepared, i, tx) } func callbackOnCreateSuccessReturn(callbacks *CreateCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.OnSuccessReturn == nil { return nil } return callbacks.OnSuccessReturn(c, valueObject, prepared, i) } func callbackOnCreateErrorReturn(callbacks *CreateCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error { if callbacks == nil { return err } if callbacks.OnErrorReturn == nil { return err } return callbacks.OnErrorReturn(c, valueObject, prepared, err, i) } type DeleteCallbacks struct { Prepare func(c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error) Before func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error After func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error OnSuccessReturn func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error OnErrorReturn func(c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error } func callbackPrepareDelete(callbacks *DeleteCallbacks, c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error) { if callbacks == nil { return make(map[string]any), nil } if callbacks.Prepare == nil { return make(map[string]any), nil } return callbacks.Prepare(c, valueObject, i) } func callbackBeforeDelete(callbacks *DeleteCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error { if callbacks == nil { return nil } if callbacks.Before == nil { return nil } return callbacks.Before(c, valueObject, prepared, i, tx) } func callbackAfterDelete(callbacks *DeleteCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, valueObject, prepared, i, tx) } func callbackOnDeleteSuccessReturn(callbacks *DeleteCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.OnSuccessReturn == nil { return nil } return callbacks.OnSuccessReturn(c, valueObject, prepared, i) } func callbackOnDeleteErrorReturn(callbacks *DeleteCallbacks, c *api.Context, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error { if callbacks == nil { return err } if callbacks.OnErrorReturn == nil { return err } return callbacks.OnErrorReturn(c, valueObject, prepared, err, i) } type QueryCallbacks[O any] struct { Before func(c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error After func(c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error OnSuccessReturn func(c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error) OnErrorReturn func(c *api.Context, valueObject value_object.ValueObject, err error, i *infrastructure.Infrastructure) (response.InfosData[O], error) } func callbackBeforeQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.Before == nil { return nil } return callbacks.Before(c, valueObject, i) } func callbackAfterQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, valueObject, i) } func callbackOnQuerySuccessReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, valueObject value_object.ValueObject, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error) { if callbacks == nil { return output, nil } if callbacks.OnSuccessReturn == nil { return output, nil } return callbacks.OnSuccessReturn(c, valueObject, i, output) } func callbackOnQueryErrorReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, valueObject value_object.ValueObject, err error, i *infrastructure.Infrastructure) (response.InfosData[O], error) { if callbacks == nil { return response.InfosData[O]{ Infos: make([]O, 0), }, err } if callbacks.OnErrorReturn == nil { return response.InfosData[O]{ Infos: make([]O, 0), }, err } return callbacks.OnErrorReturn(c, valueObject, err, i) }