mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-01 08:28:51 +00:00
refactor: eventstore v2
This commit is contained in:
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import "github.com/caos/zitadel/internal/errors"
|
||||
|
||||
//SearchQuery defines the which and how data are queried
|
||||
type SearchQuery struct {
|
||||
Columns Columns
|
||||
Limit uint64
|
||||
@@ -9,40 +10,68 @@ type SearchQuery struct {
|
||||
Filters []*Filter
|
||||
}
|
||||
|
||||
//Columns defines which fields of the event are needed for the query
|
||||
type Columns int32
|
||||
|
||||
const (
|
||||
Columns_Event = iota
|
||||
Columns_Max_Sequence
|
||||
//insert new columns-types above this ColumnsCount because count is needed for validation
|
||||
ColumnsCount
|
||||
//ColumnsEvent represents all fields of an event
|
||||
ColumnsEvent = iota + 1
|
||||
//ColumnsMaxSequence represents the latest sequence of the filtered events
|
||||
ColumnsMaxSequence
|
||||
|
||||
columnsCount
|
||||
)
|
||||
|
||||
func (c Columns) Validate() error {
|
||||
if c <= 0 || c >= columnsCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPOS-x8R35", "column out of range")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//Filter represents all fields needed to compare a field of an event with a value
|
||||
type Filter struct {
|
||||
Field Field
|
||||
Value interface{}
|
||||
Operation Operation
|
||||
}
|
||||
|
||||
//Operation defines how fields are compared
|
||||
type Operation int32
|
||||
|
||||
const (
|
||||
Operation_Equals Operation = 1 + iota
|
||||
Operation_Greater
|
||||
Operation_Less
|
||||
Operation_In
|
||||
// OperationEquals compares two values for equality
|
||||
OperationEquals Operation = iota + 1
|
||||
// OperationGreater compares if the given values is greater than the stored one
|
||||
OperationGreater
|
||||
// OperationLess compares if the given values is less than the stored one
|
||||
OperationLess
|
||||
//OperationIn checks if a stored value matches one of the passed value list
|
||||
OperationIn
|
||||
|
||||
operationCount
|
||||
)
|
||||
|
||||
//Field is the representation of a field from the event
|
||||
type Field int32
|
||||
|
||||
const (
|
||||
Field_AggregateType Field = 1 + iota
|
||||
Field_AggregateID
|
||||
Field_LatestSequence
|
||||
Field_ResourceOwner
|
||||
Field_EditorService
|
||||
Field_EditorUser
|
||||
Field_EventType
|
||||
//FieldAggregateType represents the aggregate type field
|
||||
FieldAggregateType Field = iota + 1
|
||||
//FieldAggregateID represents the aggregate id field
|
||||
FieldAggregateID
|
||||
//FieldSequence represents the sequence field
|
||||
FieldSequence
|
||||
//FieldResourceOwner represents the resource owner field
|
||||
FieldResourceOwner
|
||||
//FieldEditorService represents the editor service field
|
||||
FieldEditorService
|
||||
//FieldEditorUser represents the editor user field
|
||||
FieldEditorUser
|
||||
//FieldEventType represents the event type field
|
||||
FieldEventType
|
||||
|
||||
fieldCount
|
||||
)
|
||||
|
||||
//NewFilter is used in tests. Use searchQuery.*Filter() instead
|
||||
@@ -54,27 +83,18 @@ func NewFilter(field Field, value interface{}, operation Operation) *Filter {
|
||||
}
|
||||
}
|
||||
|
||||
// func (f *Filter) Field() Field {
|
||||
// return f.field
|
||||
// }
|
||||
// func (f *Filter) Operation() Operation {
|
||||
// return f.operation
|
||||
// }
|
||||
// func (f *Filter) Value() interface{} {
|
||||
// return f.value
|
||||
// }
|
||||
|
||||
//Validate checks if the fields of the filter have valid values
|
||||
func (f *Filter) Validate() error {
|
||||
if f == nil {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-z6KcG", "filter is nil")
|
||||
}
|
||||
if f.Field <= 0 {
|
||||
if f.Field <= 0 || f.Field >= fieldCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-zw62U", "field not definded")
|
||||
}
|
||||
if f.Value == nil {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-GJ9ct", "no value definded")
|
||||
}
|
||||
if f.Operation <= 0 {
|
||||
if f.Operation <= 0 || f.Operation >= operationCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-RrQTy", "operation not definded")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user