Make names case insensitive for API
This commit is contained in:
@@ -2,7 +2,6 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"local/dndex/config"
|
||||
"local/dndex/storage/driver"
|
||||
@@ -36,12 +35,7 @@ func (g Graph) Search(ctx context.Context, namespace string, nameContains string
|
||||
}
|
||||
|
||||
func (g Graph) ListCaseInsensitive(ctx context.Context, namespace string, from ...string) ([]entity.One, error) {
|
||||
if len(from) == 0 {
|
||||
return g.List(ctx, namespace)
|
||||
}
|
||||
pattern := strings.Join(from, "|")
|
||||
pattern = "^(?i)(" + pattern + ")"
|
||||
filter := operator.Regex{Key: entity.Name, Value: pattern}
|
||||
filter := operator.CaseInsensitives{Key: entity.Name, Values: from}
|
||||
return g.find(ctx, namespace, filter)
|
||||
}
|
||||
|
||||
@@ -74,7 +68,7 @@ func (g Graph) Insert(ctx context.Context, namespace string, one entity.One) err
|
||||
if ones, err := g.ListCaseInsensitive(ctx, namespace, one.Name); err != nil {
|
||||
return err
|
||||
} else if len(ones) > 0 {
|
||||
return errors.New("collision on primary key when case insensitive")
|
||||
return fmt.Errorf("collision on primary key when case insensitive: cannot create %q because %+v exists", one.Name, ones)
|
||||
}
|
||||
return g.driver.Insert(ctx, namespace, one)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user