package entity_crud import ( "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/api/request" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-framework/baize/framework/core/domain/entity" "git.sxidc.com/go-framework/baize/framework/core/infrastructure" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database" "git.sxidc.com/go-tools/utils/reflectutils" ) type CreateCallbacks struct { Prepare func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) Before func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error After func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, id string) (string, error) OnErrorReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) (string, error) } func callbackPrepareCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, i) } func callbackBeforeCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, prepared, i, tx) } func callbackAfterCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, dbExecutor database.Executor) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, params, e, prepared, i, dbExecutor) } func callbackOnCreateSuccessReturn(callbacks *CreateCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, id string) (string, error) { if callbacks == nil { return id, nil } if callbacks.OnSuccessReturn == nil { return id, nil } return callbacks.OnSuccessReturn(c, params, e, prepared, i, id) } func callbackOnCreateErrorReturn(callbacks *CreateCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) (string, error) { if callbacks == nil { return "", err } if callbacks.OnErrorReturn == nil { return "", err } return callbacks.OnErrorReturn(c, params, e, prepared, err, i) } type DeleteCallbacks struct { Prepare func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) Before func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error After func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error OnErrorReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) error } func callbackPrepareDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, i) } func callbackBeforeDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, prepared, i, tx) } func callbackAfterDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, dbExecutor database.Executor) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, params, e, prepared, i, dbExecutor) } func callbackOnDeleteSuccessReturn(callbacks *DeleteCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.OnSuccessReturn == nil { return nil } return callbacks.OnSuccessReturn(c, params, e, prepared, i) } func callbackOnDeleteErrorReturn(callbacks *DeleteCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, prepared, err, i) } type UpdateCallbacks struct { Prepare func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) Before func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error After func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error OnErrorReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) error } func callbackPrepareUpdate(callbacks *UpdateCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, i) } func callbackBeforeUpdate(callbacks *UpdateCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, prepared, i, tx) } func callbackAfterUpdate(callbacks *UpdateCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, dbExecutor database.Executor) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, params, e, prepared, i, dbExecutor) } func callbackOnUpdateSuccessReturn(callbacks *UpdateCallbacks, c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.OnSuccessReturn == nil { return nil } return callbacks.OnSuccessReturn(c, params, e, prepared, i) } func callbackOnUpdateErrorReturn(callbacks *UpdateCallbacks, c *api.Context, params request.Params, e entity.Entity, 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, params, e, prepared, err, i) } type QueryCallbacks[O any] struct { Before func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error After func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error) OnErrorReturn func(c *api.Context, params request.Params, e entity.Entity, err error, i *infrastructure.Infrastructure) (response.InfosData[O], error) } func callbackBeforeQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.Before == nil { return nil } return callbacks.Before(c, params, e, i) } func callbackAfterQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, params, e, i) } func callbackOnQuerySuccessReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, e entity.Entity, 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, params, e, i, output) } func callbackOnQueryErrorReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, e entity.Entity, 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, params, e, err, i) } type GetByIDCallbacks[O any] struct { Before func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error After func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output O) (O, error) OnErrorReturn func(c *api.Context, params request.Params, e entity.Entity, err error, i *infrastructure.Infrastructure) (O, error) } func callbackBeforeGetByID[O any](callbacks *GetByIDCallbacks[O], c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.Before == nil { return nil } return callbacks.Before(c, params, e, i) } func callbackAfterGetByID[O any](callbacks *GetByIDCallbacks[O], c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error { if callbacks == nil { return nil } if callbacks.After == nil { return nil } return callbacks.After(c, params, e, i) } func callbackOnGetByIDSuccessReturn[O any](callbacks *GetByIDCallbacks[O], c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output O) (O, error) { if callbacks == nil { return output, nil } if callbacks.OnSuccessReturn == nil { return output, nil } return callbacks.OnSuccessReturn(c, params, e, i, output) } func callbackOnGetByIDErrorReturn[O any](callbacks *GetByIDCallbacks[O], c *api.Context, params request.Params, e entity.Entity, err error, i *infrastructure.Infrastructure) (O, error) { if callbacks == nil { return reflectutils.Zero[O](), err } if callbacks.OnErrorReturn == nil { return reflectutils.Zero[O](), err } return callbacks.OnErrorReturn(c, params, e, err, i) }