mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
fix: todos (#1346)
* fix: pub sub in new eventstore * fix: todos * fix: todos * fix: todos * fix: todos * fix: todos
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import "github.com/caos/zitadel/internal/model"
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type GeneralSearchRequest struct {
|
||||
Offset uint64
|
||||
@@ -18,6 +20,6 @@ const (
|
||||
|
||||
type GeneralSearchQuery struct {
|
||||
Key GeneralSearchKey
|
||||
Method model.SearchMethod
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
@@ -3,13 +3,12 @@ package repository
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -73,7 +72,7 @@ func (req TestSearchRequest) GetQueries() []SearchQuery {
|
||||
|
||||
type TestSearchQuery struct {
|
||||
key TestSearchKey
|
||||
method model.SearchMethod
|
||||
method domain.SearchMethod
|
||||
value string
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ func (req TestSearchQuery) GetKey() ColumnKey {
|
||||
return req.key
|
||||
}
|
||||
|
||||
func (req TestSearchQuery) GetMethod() model.SearchMethod {
|
||||
func (req TestSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.method
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"strings"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
view_model "github.com/caos/zitadel/internal/view/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ type FailedEvent struct {
|
||||
|
||||
type FailedEventSearchQuery struct {
|
||||
Key FailedEventSearchKey
|
||||
Method model.SearchMethod
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (req FailedEventSearchQuery) GetKey() ColumnKey {
|
||||
return failedEventSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req FailedEventSearchQuery) GetMethod() model.SearchMethod {
|
||||
func (req FailedEventSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ func RemoveFailedEvent(db *gorm.DB, table string, failedEvent *FailedEvent) erro
|
||||
func LatestFailedEvent(db *gorm.DB, table, viewName string, sequence uint64) (*FailedEvent, error) {
|
||||
failedEvent := new(FailedEvent)
|
||||
queries := []SearchQuery{
|
||||
FailedEventSearchQuery{Key: FailedEventKeyViewName, Method: model.SearchMethodEqualsIgnoreCase, Value: viewName},
|
||||
FailedEventSearchQuery{Key: FailedEventKeyFailedSequence, Method: model.SearchMethodEquals, Value: sequence},
|
||||
FailedEventSearchQuery{Key: FailedEventKeyViewName, Method: domain.SearchMethodEqualsIgnoreCase, Value: viewName},
|
||||
FailedEventSearchQuery{Key: FailedEventKeyFailedSequence, Method: domain.SearchMethodEquals, Value: sequence},
|
||||
}
|
||||
query := PrepareGetByQuery(table, queries...)
|
||||
err := query(db, failedEvent)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/view/model"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func (req GeneralSearchQuery) GetKey() ColumnKey {
|
||||
return GeneralSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req GeneralSearchQuery) GetMethod() global_model.SearchMethod {
|
||||
func (req GeneralSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,9 @@ package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
@@ -19,7 +19,7 @@ type SearchRequest interface {
|
||||
|
||||
type SearchQuery interface {
|
||||
GetKey() ColumnKey
|
||||
GetMethod() model.SearchMethod
|
||||
GetMethod() domain.SearchMethod
|
||||
GetValue() interface{}
|
||||
}
|
||||
|
||||
@@ -60,66 +60,66 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r
|
||||
}
|
||||
}
|
||||
|
||||
func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method model.SearchMethod) (*gorm.DB, error) {
|
||||
func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method domain.SearchMethod) (*gorm.DB, error) {
|
||||
column := key.ToColumnName()
|
||||
if column == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-7dz3w", "Column name missing")
|
||||
}
|
||||
|
||||
switch method {
|
||||
case model.SearchMethodEquals:
|
||||
case domain.SearchMethodEquals:
|
||||
query = query.Where(""+column+" = ?", value)
|
||||
case model.SearchMethodEqualsIgnoreCase:
|
||||
case domain.SearchMethodEqualsIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-idu8e", "Equal ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") = LOWER(?)", valueText)
|
||||
case model.SearchMethodStartsWith:
|
||||
case domain.SearchMethodStartsWith:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-SLj7s", "Starts with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", valueText+"%")
|
||||
case model.SearchMethodStartsWithIgnoreCase:
|
||||
case domain.SearchMethodStartsWithIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eidus", "Starts with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", valueText+"%")
|
||||
case model.SearchMethodEndsWith:
|
||||
case domain.SearchMethodEndsWith:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Hswd3", "Ends with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", "%"+valueText)
|
||||
case model.SearchMethodEndsWithIgnoreCase:
|
||||
case domain.SearchMethodEndsWithIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-dAG31", "Ends with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText)
|
||||
case model.SearchMethodContains:
|
||||
case domain.SearchMethodContains:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-3ids", "Contains with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", "%"+valueText+"%")
|
||||
case model.SearchMethodContainsIgnoreCase:
|
||||
case domain.SearchMethodContainsIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eid73", "Contains with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText+"%")
|
||||
case model.SearchMethodNotEquals:
|
||||
case domain.SearchMethodNotEquals:
|
||||
query = query.Where(""+column+" <> ?", value)
|
||||
case model.SearchMethodGreaterThan:
|
||||
case domain.SearchMethodGreaterThan:
|
||||
query = query.Where(column+" > ?", value)
|
||||
case model.SearchMethodLessThan:
|
||||
case domain.SearchMethodLessThan:
|
||||
query = query.Where(column+" < ?", value)
|
||||
case model.SearchMethodIsOneOf:
|
||||
case domain.SearchMethodIsOneOf:
|
||||
query = query.Where(column+" IN (?)", value)
|
||||
case model.SearchMethodListContains:
|
||||
case domain.SearchMethodListContains:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Psois", "list contains only possible for strings")
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
"testing"
|
||||
)
|
||||
@@ -94,7 +94,7 @@ func TestPrepareSearchQuery(t *testing.T) {
|
||||
expectGetSearchRequestWithSearchQuery("TESTTABLE", TestSearchKey_ID.ToColumnName(), "=", "AggregateID", 2, 2),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchRequest: TestSearchRequest{queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}},
|
||||
searchRequest: TestSearchRequest{queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: domain.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}},
|
||||
},
|
||||
res{
|
||||
count: 2,
|
||||
@@ -107,7 +107,7 @@ func TestPrepareSearchQuery(t *testing.T) {
|
||||
expectGetSearchRequestWithAllParams("TESTTABLE", TestSearchKey_ID.ToColumnName(), "=", "AggregateID", "ASC", TestSearchKey_ID, 2, 2, 2, 5),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchRequest: TestSearchRequest{limit: 2, offset: 2, sortingColumn: TestSearchKey_ID, asc: true, queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}},
|
||||
searchRequest: TestSearchRequest{limit: 2, offset: 2, sortingColumn: TestSearchKey_ID, asc: true, queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: domain.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}},
|
||||
},
|
||||
res{
|
||||
count: 5,
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
"testing"
|
||||
)
|
||||
@@ -113,7 +113,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQuery("TESTTABLE", "test", "=", "VALUE"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodEqualsIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodEqualsIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -126,7 +126,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQueryCaseSensitive("TESTTABLE", "test", "=", "VALUE"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodEquals, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodEquals, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -139,7 +139,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQuery("TESTTABLE", "test", "LIKE", "VALUE%"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodStartsWithIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodStartsWithIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -152,7 +152,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQueryCaseSensitive("TESTTABLE", "test", "LIKE", "VALUE%"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodStartsWith, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodStartsWith, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -165,7 +165,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQuery("TESTTABLE", "test", "LIKE", "%VALUE%"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -178,7 +178,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQueryCaseSensitive("TESTTABLE", "test", "LIKE", "%VALUE%"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContains, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContains, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -191,7 +191,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQueryErr("TESTTABLE", "test", "LIKE", "%VALUE%", gorm.ErrRecordNotFound),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -205,7 +205,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQueryErr("TESTTABLE", "test", "LIKE", "%VALUE%", gorm.ErrUnaddressable),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
@@ -219,7 +219,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
expectGetByQuery("TESTTABLE", "", "=", "VALUE"),
|
||||
args{
|
||||
table: "TESTTABLE",
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_UNDEFINED, method: model.SearchMethodEqualsIgnoreCase, value: "VALUE"},
|
||||
searchQuery: TestSearchQuery{key: TestSearchKey_UNDEFINED, method: domain.SearchMethodEqualsIgnoreCase, value: "VALUE"},
|
||||
},
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
int_model "github.com/caos/zitadel/internal/model"
|
||||
"github.com/caos/zitadel/internal/view/model"
|
||||
)
|
||||
|
||||
@@ -60,8 +60,8 @@ func (q *sequenceSearchQuery) GetKey() ColumnKey {
|
||||
return q.key
|
||||
}
|
||||
|
||||
func (q *sequenceSearchQuery) GetMethod() int_model.SearchMethod {
|
||||
return int_model.SearchMethodEquals
|
||||
func (q *sequenceSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return domain.SearchMethodEquals
|
||||
}
|
||||
|
||||
func (q *sequenceSearchQuery) GetValue() interface{} {
|
||||
|
Reference in New Issue
Block a user