zitadel/internal/eventstore/v2/repository/search_query.go

82 lines
1.6 KiB
Go
Raw Normal View History

2020-09-30 08:00:05 +00:00
package repository
2020-09-24 06:52:10 +00:00
2020-09-30 08:00:05 +00:00
import "github.com/caos/zitadel/internal/errors"
type SearchQuery struct {
Columns Columns
Limit uint64
Desc bool
Filters []*Filter
}
type Columns int32
const (
Columns_Event = iota
Columns_Max_Sequence
//insert new columns-types above this ColumnsCount because count is needed for validation
ColumnsCount
2020-09-24 06:52:10 +00:00
)
type Filter struct {
2020-10-05 18:39:36 +00:00
Field Field
Value interface{}
Operation Operation
2020-09-24 06:52:10 +00:00
}
type Operation int32
const (
Operation_Equals Operation = 1 + iota
Operation_Greater
Operation_Less
Operation_In
)
type Field int32
const (
Field_AggregateType Field = 1 + iota
Field_AggregateID
Field_LatestSequence
Field_ResourceOwner
Field_EditorService
Field_EditorUser
Field_EventType
)
//NewFilter is used in tests. Use searchQuery.*Filter() instead
func NewFilter(field Field, value interface{}, operation Operation) *Filter {
return &Filter{
2020-10-05 18:39:36 +00:00
Field: field,
Value: value,
Operation: operation,
2020-09-24 06:52:10 +00:00
}
}
2020-10-05 18:39:36 +00:00
// func (f *Filter) Field() Field {
// return f.field
// }
// func (f *Filter) Operation() Operation {
// return f.operation
// }
// func (f *Filter) Value() interface{} {
// return f.value
// }
2020-09-24 06:52:10 +00:00
func (f *Filter) Validate() error {
if f == nil {
2020-09-30 08:00:05 +00:00
return errors.ThrowPreconditionFailed(nil, "REPO-z6KcG", "filter is nil")
2020-09-24 06:52:10 +00:00
}
2020-10-05 18:39:36 +00:00
if f.Field <= 0 {
2020-09-30 08:00:05 +00:00
return errors.ThrowPreconditionFailed(nil, "REPO-zw62U", "field not definded")
2020-09-24 06:52:10 +00:00
}
2020-10-05 18:39:36 +00:00
if f.Value == nil {
2020-09-30 08:00:05 +00:00
return errors.ThrowPreconditionFailed(nil, "REPO-GJ9ct", "no value definded")
2020-09-24 06:52:10 +00:00
}
2020-10-05 18:39:36 +00:00
if f.Operation <= 0 {
2020-09-30 08:00:05 +00:00
return errors.ThrowPreconditionFailed(nil, "REPO-RrQTy", "operation not definded")
2020-09-24 06:52:10 +00:00
}
return nil
}