123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- package value_object_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/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, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error)
- Before func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
- After func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
- OnSuccessReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error
- OnErrorReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error
- }
- func callbackPrepareCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, 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, params, valueObject, i)
- }
- func callbackBeforeCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i, tx)
- }
- func callbackAfterCreate(callbacks *CreateCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i, tx)
- }
- func callbackOnCreateSuccessReturn(callbacks *CreateCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i)
- }
- func callbackOnCreateErrorReturn(callbacks *CreateCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, err, i)
- }
- type DeleteCallbacks struct {
- Prepare func(c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) (map[string]any, error)
- Before func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
- After func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
- OnSuccessReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, i *infrastructure.Infrastructure) error
- OnErrorReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, prepared map[string]any, err error, i *infrastructure.Infrastructure) error
- }
- func callbackPrepareDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, 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, params, valueObject, i)
- }
- func callbackBeforeDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i, tx)
- }
- func callbackAfterDelete(callbacks *DeleteCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i, tx)
- }
- func callbackOnDeleteSuccessReturn(callbacks *DeleteCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, i)
- }
- func callbackOnDeleteErrorReturn(callbacks *DeleteCallbacks, c *api.Context, params request.Params, 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, params, valueObject, prepared, err, i)
- }
- type QueryCallbacks[O any] struct {
- Before func(c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error
- After func(c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error
- OnSuccessReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error)
- OnErrorReturn func(c *api.Context, params request.Params, valueObject value_object.ValueObject, err error, i *infrastructure.Infrastructure) (response.InfosData[O], error)
- }
- func callbackBeforeQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error {
- if callbacks == nil {
- return nil
- }
- if callbacks.Before == nil {
- return nil
- }
- return callbacks.Before(c, params, valueObject, i)
- }
- func callbackAfterQuery[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, valueObject value_object.ValueObject, i *infrastructure.Infrastructure) error {
- if callbacks == nil {
- return nil
- }
- if callbacks.After == nil {
- return nil
- }
- return callbacks.After(c, params, valueObject, i)
- }
- func callbackOnQuerySuccessReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, 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, params, valueObject, i, output)
- }
- func callbackOnQueryErrorReturn[O any](callbacks *QueryCallbacks[O], c *api.Context, params request.Params, 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, params, valueObject, err, i)
- }
|