// Code generated by entc, DO NOT EDIT. package hook import ( "context" "fmt" "code.osinet.fr/fgm/entdemo/ent" ) // The CarFunc type is an adapter to allow the use of ordinary // function as Car mutator. type CarFunc func(context.Context, *ent.CarMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f CarFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { mv, ok := m.(*ent.CarMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CarMutation", m) } return f(ctx, mv) } // The GroupFunc type is an adapter to allow the use of ordinary // function as Group mutator. type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { mv, ok := m.(*ent.GroupMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m) } return f(ctx, mv) } // The UserFunc type is an adapter to allow the use of ordinary // function as User mutator. type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { mv, ok := m.(*ent.UserMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) } return f(ctx, mv) } // On executes the given hook only of the given operation. // // hook.On(Log, ent.Delete|ent.Create) // func On(hk ent.Hook, op ent.Op) ent.Hook { return func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { if m.Op().Is(op) { return hk(next).Mutate(ctx, m) } return next.Mutate(ctx, m) }) } } // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { // return []ent.Hook{ // Reject(ent.Delete|ent.Update), // } // } // func Reject(op ent.Op) ent.Hook { return func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { if m.Op().Is(op) { return nil, fmt.Errorf("%s operation is not allowed", m.Op()) } return next.Mutate(ctx, m) }) } }