mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 19:23:29 +00:00
fix: refactor system api (#3500)
* fix: refactor system api * fix: search domains on get instance * fix: search domains on get instance * fix: return instance detail * fix: implement user sorting column (#3469) * fix: implement user sorting column * fix: implement user sorting column * fix: string column * isOrderByLower Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: user converter import * Update instance.go Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -23,7 +23,22 @@ func InstanceToPb(instance *query.Instance) *instance_pb.Instance {
|
||||
instance.ChangeDate,
|
||||
instance.InstanceID(),
|
||||
),
|
||||
Id: instance.InstanceID(),
|
||||
Id: instance.InstanceID(),
|
||||
Name: instance.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func InstanceDetailToPb(instance *query.Instance) *instance_pb.InstanceDetail {
|
||||
return &instance_pb.InstanceDetail{
|
||||
Details: object.ToViewDetailsPb(
|
||||
instance.Sequence,
|
||||
instance.CreationDate,
|
||||
instance.ChangeDate,
|
||||
instance.InstanceID(),
|
||||
),
|
||||
Id: instance.InstanceID(),
|
||||
Name: instance.Name,
|
||||
Domains: DomainsToPb(instance.Domains),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/user"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
@@ -27,14 +28,38 @@ func ListUsersRequestToModel(req *mgmt_pb.ListUsersRequest) (*query.UserSearchQu
|
||||
}
|
||||
return &query.UserSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
SortingColumn: UserFieldNameToSortingColumn(req.SortingColumn),
|
||||
},
|
||||
Queries: queries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func UserFieldNameToSortingColumn(field user.UserFieldName) query.Column {
|
||||
switch field {
|
||||
case user.UserFieldName_USER_FIELD_NAME_EMAIL:
|
||||
return query.HumanEmailCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_FIRST_NAME:
|
||||
return query.HumanFirstNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_LAST_NAME:
|
||||
return query.HumanLastNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_DISPLAY_NAME:
|
||||
return query.HumanDisplayNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_USER_NAME:
|
||||
return query.UserUsernameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_STATE:
|
||||
return query.UserStateCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_TYPE:
|
||||
return query.UserTypeCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_NICK_NAME:
|
||||
return query.HumanNickNameCol
|
||||
default:
|
||||
return query.UserIDCol
|
||||
}
|
||||
}
|
||||
|
||||
func BulkSetMetadataToDomain(req *mgmt_pb.BulkSetUserMetadataRequest) []*domain.Metadata {
|
||||
metadata := make([]*domain.Metadata, len(req.Metadata))
|
||||
for i, data := range req.Metadata {
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
instance_grpc "github.com/zitadel/zitadel/internal/api/grpc/instance"
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
object_pb "github.com/zitadel/zitadel/pkg/grpc/object"
|
||||
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
||||
)
|
||||
@@ -29,13 +30,13 @@ func (s *Server) ListInstances(ctx context.Context, req *system_pb.ListInstances
|
||||
}
|
||||
|
||||
func (s *Server) GetInstance(ctx context.Context, req *system_pb.GetInstanceRequest) (*system_pb.GetInstanceResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
instance, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.GetInstanceResponse{
|
||||
Instance: instance_grpc.InstanceToPb(instance),
|
||||
Instance: instance_grpc.InstanceDetailToPb(instance),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ func (s *Server) AddInstance(ctx context.Context, req *system_pb.AddInstanceRequ
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.AddInstanceResponse{
|
||||
Id: id,
|
||||
InstanceId: id,
|
||||
Details: object.AddToDetailsPb(
|
||||
details.Sequence,
|
||||
details.EventDate,
|
||||
@@ -55,8 +56,30 @@ func (s *Server) AddInstance(ctx context.Context, req *system_pb.AddInstanceRequ
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) ExistsDomain(ctx context.Context, req *system_pb.ExistsDomainRequest) (*system_pb.ExistsDomainResponse, error) {
|
||||
domainQuery, err := query.NewInstanceDomainDomainSearchQuery(query.TextEqualsIgnoreCase, req.Domain)
|
||||
|
||||
query := &query.InstanceDomainSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: 0,
|
||||
Limit: 1,
|
||||
Asc: true,
|
||||
},
|
||||
Queries: []query.SearchQuery{
|
||||
domainQuery,
|
||||
},
|
||||
}
|
||||
domains, err := s.query.SearchInstanceDomains(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.ExistsDomainResponse{
|
||||
Exists: domains.Count > 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) ListDomains(ctx context.Context, req *system_pb.ListDomainsRequest) (*system_pb.ListDomainsResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
queries, err := ListInstanceDomainsRequestToModel(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,7 +100,7 @@ func (s *Server) ListDomains(ctx context.Context, req *system_pb.ListDomainsRequ
|
||||
}
|
||||
|
||||
func (s *Server) AddDomain(ctx context.Context, req *system_pb.AddDomainRequest) (*system_pb.AddDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
instance, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,7 +120,7 @@ func (s *Server) AddDomain(ctx context.Context, req *system_pb.AddDomainRequest)
|
||||
}
|
||||
|
||||
func (s *Server) RemoveDomain(ctx context.Context, req *system_pb.RemoveDomainRequest) (*system_pb.RemoveDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
details, err := s.command.RemoveInstanceDomain(ctx, req.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -112,7 +135,7 @@ func (s *Server) RemoveDomain(ctx context.Context, req *system_pb.RemoveDomainRe
|
||||
}
|
||||
|
||||
func (s *Server) SetPrimaryDomain(ctx context.Context, req *system_pb.SetPrimaryDomainRequest) (*system_pb.SetPrimaryDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
details, err := s.command.SetPrimaryInstanceDomain(ctx, req.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
instance_pb "github.com/zitadel/zitadel/pkg/grpc/instance"
|
||||
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func AddInstancePbToSetupInstance(req *system_pb.AddInstanceRequest, defaultInstance command.InstanceSetup) *command.InstanceSetup {
|
||||
@@ -20,18 +21,32 @@ func AddInstancePbToSetupInstance(req *system_pb.AddInstanceRequest, defaultInst
|
||||
if req.FirstOrgName != "" {
|
||||
defaultInstance.Org.Name = req.FirstOrgName
|
||||
}
|
||||
if req.OwnerEmail != "" {
|
||||
defaultInstance.Org.Human.Email.Address = req.OwnerEmail
|
||||
if req.OwnerEmail.Email != "" {
|
||||
defaultInstance.Org.Human.Email.Address = req.OwnerEmail.Email
|
||||
defaultInstance.Org.Human.Email.Verified = req.OwnerEmail.IsEmailVerified
|
||||
}
|
||||
if req.OwnerUsername != "" {
|
||||
defaultInstance.Org.Human.Username = req.OwnerUsername
|
||||
if req.OwnerProfile != nil {
|
||||
if req.OwnerProfile.FirstName != "" {
|
||||
defaultInstance.Org.Human.FirstName = req.OwnerProfile.FirstName
|
||||
}
|
||||
if req.OwnerProfile.LastName != "" {
|
||||
defaultInstance.Org.Human.LastName = req.OwnerProfile.LastName
|
||||
}
|
||||
if req.OwnerProfile.PreferredLanguage != "" {
|
||||
lang, err := language.Parse(req.OwnerProfile.PreferredLanguage)
|
||||
if err == nil {
|
||||
defaultInstance.Org.Human.PreferredLang = lang
|
||||
}
|
||||
}
|
||||
}
|
||||
if req.OwnerFirstName != "" {
|
||||
defaultInstance.Org.Human.FirstName = req.OwnerFirstName
|
||||
if req.OwnerUserName != "" {
|
||||
defaultInstance.Org.Human.Username = req.OwnerUserName
|
||||
}
|
||||
if req.OwnerLastName != "" {
|
||||
defaultInstance.Org.Human.LastName = req.OwnerLastName
|
||||
if req.OwnerPassword != nil {
|
||||
defaultInstance.Org.Human.Password = req.OwnerPassword.Password
|
||||
defaultInstance.Org.Human.PasswordChangeRequired = req.OwnerPassword.PasswordChangeRequired
|
||||
}
|
||||
|
||||
return &defaultInstance
|
||||
}
|
||||
func ListInstancesRequestToModel(req *system_pb.ListInstancesRequest) (*query.InstanceSearchQueries, error) {
|
||||
|
@@ -75,6 +75,7 @@ type Instance struct {
|
||||
ChangeDate time.Time
|
||||
CreationDate time.Time
|
||||
Sequence uint64
|
||||
Name string
|
||||
|
||||
GlobalOrgID string
|
||||
IAMProjectID string
|
||||
@@ -83,6 +84,7 @@ type Instance struct {
|
||||
DefaultLang language.Tag
|
||||
SetupStarted domain.Step
|
||||
SetupDone domain.Step
|
||||
Domains []*InstanceDomain
|
||||
host string
|
||||
}
|
||||
|
||||
@@ -159,7 +161,7 @@ func (q *Queries) SearchInstances(ctx context.Context, queries *InstanceSearchQu
|
||||
}
|
||||
|
||||
func (q *Queries) Instance(ctx context.Context) (*Instance, error) {
|
||||
stmt, scan := prepareInstanceQuery(authz.GetInstance(ctx).RequestedDomain())
|
||||
stmt, scan := prepareInstanceDomainQuery(authz.GetInstance(ctx).RequestedDomain())
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
InstanceColumnID.identifier(): authz.GetInstance(ctx).InstanceID(),
|
||||
}).ToSql()
|
||||
@@ -167,7 +169,10 @@ func (q *Queries) Instance(ctx context.Context) (*Instance, error) {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-d9ngs", "Errors.Query.SQLStatement")
|
||||
}
|
||||
|
||||
row := q.client.QueryRowContext(ctx, query, args...)
|
||||
row, err := q.client.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
@@ -181,7 +186,10 @@ func (q *Queries) InstanceByHost(ctx context.Context, host string) (authz.Instan
|
||||
return nil, errors.ThrowInternal(err, "QUERY-SAfg2", "Errors.Query.SQLStatement")
|
||||
}
|
||||
|
||||
row := q.client.QueryRowContext(ctx, query, args...)
|
||||
row, err := q.client.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
@@ -226,9 +234,9 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-n0wng", "Errors.IAM.NotFound")
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-5m09s", "Errors.IAM.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-d9nw", "Errors.Internal")
|
||||
return nil, errors.ThrowInternal(err, "QUERY-3j9sf", "Errors.Internal")
|
||||
}
|
||||
instance.DefaultLang = language.Make(lang)
|
||||
return instance, nil
|
||||
@@ -241,6 +249,7 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
|
||||
InstanceColumnCreationDate.identifier(),
|
||||
InstanceColumnChangeDate.identifier(),
|
||||
InstanceColumnSequence.identifier(),
|
||||
InstanceColumnName.identifier(),
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
@@ -262,6 +271,7 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
|
||||
&instance.CreationDate,
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.Name,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
@@ -290,12 +300,13 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
|
||||
}
|
||||
}
|
||||
|
||||
func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Instance, error)) {
|
||||
func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows) (*Instance, error)) {
|
||||
return sq.Select(
|
||||
InstanceColumnID.identifier(),
|
||||
InstanceColumnCreationDate.identifier(),
|
||||
InstanceColumnChangeDate.identifier(),
|
||||
InstanceColumnSequence.identifier(),
|
||||
InstanceColumnName.identifier(),
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
@@ -303,33 +314,73 @@ func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Row) (
|
||||
InstanceColumnSetupStarted.identifier(),
|
||||
InstanceColumnSetupDone.identifier(),
|
||||
InstanceColumnDefaultLanguage.identifier(),
|
||||
InstanceDomainDomainCol.identifier(),
|
||||
InstanceDomainIsPrimaryCol.identifier(),
|
||||
InstanceDomainIsGeneratedCol.identifier(),
|
||||
InstanceDomainCreationDateCol.identifier(),
|
||||
InstanceDomainChangeDateCol.identifier(),
|
||||
InstanceDomainSequenceCol.identifier(),
|
||||
).
|
||||
From(instanceTable.identifier()).
|
||||
LeftJoin(join(InstanceDomainInstanceIDCol, InstanceColumnID)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*Instance, error) {
|
||||
instance := &Instance{host: host}
|
||||
lang := ""
|
||||
err := row.Scan(
|
||||
&instance.ID,
|
||||
&instance.CreationDate,
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
&instance.SetupStarted,
|
||||
&instance.SetupDone,
|
||||
&lang,
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-n0wng", "Errors.IAM.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-d9nw", "Errors.Internal")
|
||||
func(rows *sql.Rows) (*Instance, error) {
|
||||
instance := &Instance{
|
||||
host: host,
|
||||
Domains: make([]*InstanceDomain, 0),
|
||||
}
|
||||
lang := ""
|
||||
for rows.Next() {
|
||||
var (
|
||||
domain sql.NullString
|
||||
isPrimary sql.NullBool
|
||||
isGenerated sql.NullBool
|
||||
changeDate sql.NullTime
|
||||
creationDate sql.NullTime
|
||||
sequecne sql.NullInt64
|
||||
)
|
||||
err := rows.Scan(
|
||||
&instance.ID,
|
||||
&instance.CreationDate,
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.Name,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
&instance.SetupStarted,
|
||||
&instance.SetupDone,
|
||||
&lang,
|
||||
&domain,
|
||||
&isPrimary,
|
||||
&isGenerated,
|
||||
&changeDate,
|
||||
&creationDate,
|
||||
&sequecne,
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-n0wng", "Errors.IAM.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-d9nw", "Errors.Internal")
|
||||
}
|
||||
if !domain.Valid {
|
||||
continue
|
||||
}
|
||||
instance.Domains = append(instance.Domains, &InstanceDomain{
|
||||
CreationDate: creationDate.Time,
|
||||
ChangeDate: changeDate.Time,
|
||||
Sequence: uint64(sequecne.Int64),
|
||||
Domain: domain.String,
|
||||
IsPrimary: isPrimary.Bool,
|
||||
IsGenerated: isGenerated.Bool,
|
||||
InstanceID: instance.ID,
|
||||
})
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-Dfbe2", "Errors.Query.CloseRows")
|
||||
}
|
||||
instance.DefaultLang = language.Make(lang)
|
||||
return instance, nil
|
||||
}
|
||||
}
|
||||
|
@@ -31,18 +31,16 @@ func (req *SearchRequest) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
}
|
||||
|
||||
if !req.SortingColumn.isZero() {
|
||||
clause := "LOWER(" + sqlPlaceholder + ")"
|
||||
clause := req.SortingColumn.orderBy()
|
||||
if !req.Asc {
|
||||
clause += " DESC"
|
||||
}
|
||||
query = query.OrderByClause(clause, req.SortingColumn.identifier())
|
||||
query = query.OrderByClause(clause)
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
const sqlPlaceholder = "?"
|
||||
|
||||
type SearchQuery interface {
|
||||
toQuery(sq.SelectBuilder) sq.SelectBuilder
|
||||
comp() sq.Sqlizer
|
||||
@@ -367,8 +365,9 @@ func (t table) isZero() bool {
|
||||
}
|
||||
|
||||
type Column struct {
|
||||
name string
|
||||
table table
|
||||
name string
|
||||
table table
|
||||
isOrderByLower bool
|
||||
}
|
||||
|
||||
func (c Column) identifier() string {
|
||||
@@ -381,6 +380,13 @@ func (c Column) identifier() string {
|
||||
return c.name
|
||||
}
|
||||
|
||||
func (c Column) orderBy() string {
|
||||
if !c.isOrderByLower {
|
||||
return c.identifier()
|
||||
}
|
||||
return "LOWER(" + c.identifier() + ")"
|
||||
}
|
||||
|
||||
func (c Column) setTable(t table) Column {
|
||||
c.table = t
|
||||
return c
|
||||
|
@@ -19,6 +19,11 @@ var (
|
||||
name: "test_col",
|
||||
table: testTable,
|
||||
}
|
||||
testLowerCol = Column{
|
||||
name: "test_lower_col",
|
||||
table: testTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
testNoCol = Column{
|
||||
name: "",
|
||||
table: testTable,
|
||||
@@ -34,7 +39,6 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
}
|
||||
type want struct {
|
||||
stmtAddition string
|
||||
args []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -46,7 +50,6 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
fields: fields{},
|
||||
want: want{
|
||||
stmtAddition: "",
|
||||
args: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -56,7 +59,6 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "OFFSET 5",
|
||||
args: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -66,7 +68,6 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "LIMIT 5",
|
||||
args: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -76,8 +77,7 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
Asc: true,
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "ORDER BY LOWER(?)",
|
||||
args: []interface{}{"test_table.test_col"},
|
||||
stmtAddition: "ORDER BY test_table.test_col",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -86,8 +86,17 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
SortingColumn: testCol,
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "ORDER BY LOWER(?) DESC",
|
||||
args: []interface{}{"test_table.test_col"},
|
||||
stmtAddition: "ORDER BY test_table.test_col DESC",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sort lower asc",
|
||||
fields: fields{
|
||||
SortingColumn: testLowerCol,
|
||||
Asc: true,
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "ORDER BY LOWER(test_table.test_lower_col)",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -99,8 +108,7 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
Asc: true,
|
||||
},
|
||||
want: want{
|
||||
stmtAddition: "ORDER BY LOWER(?) LIMIT 10 OFFSET 5",
|
||||
args: []interface{}{"test_table.test_col"},
|
||||
stmtAddition: "ORDER BY test_table.test_col LIMIT 10 OFFSET 5",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -116,7 +124,7 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
query := sq.Select((testCol).identifier()).From(testTable.identifier())
|
||||
expectedQuery, _, _ := query.ToSql()
|
||||
|
||||
stmt, args, err := req.toQuery(query).ToSql()
|
||||
stmt, _, err := req.toQuery(query).ToSql()
|
||||
if len(tt.want.stmtAddition) > 0 {
|
||||
expectedQuery += " " + tt.want.stmtAddition
|
||||
}
|
||||
@@ -124,10 +132,6 @@ func TestSearchRequest_ToQuery(t *testing.T) {
|
||||
t.Errorf("stmt = %q, want %q", stmt, expectedQuery)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(args, tt.want.args) {
|
||||
t.Errorf("args = %v, want %v", args, tt.want.stmtAddition)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("no error expected but got %v", err)
|
||||
}
|
||||
|
@@ -130,8 +130,9 @@ var (
|
||||
table: userTable,
|
||||
}
|
||||
UserUsernameCol = Column{
|
||||
name: projection.UserUsernameCol,
|
||||
table: userTable,
|
||||
name: projection.UserUsernameCol,
|
||||
table: userTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
UserTypeCol = Column{
|
||||
name: projection.UserTypeCol,
|
||||
@@ -163,20 +164,24 @@ var (
|
||||
table: humanTable,
|
||||
}
|
||||
HumanFirstNameCol = Column{
|
||||
name: projection.HumanFirstNameCol,
|
||||
table: humanTable,
|
||||
name: projection.HumanFirstNameCol,
|
||||
table: humanTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
HumanLastNameCol = Column{
|
||||
name: projection.HumanLastNameCol,
|
||||
table: humanTable,
|
||||
name: projection.HumanLastNameCol,
|
||||
table: humanTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
HumanNickNameCol = Column{
|
||||
name: projection.HumanNickNameCol,
|
||||
table: humanTable,
|
||||
name: projection.HumanNickNameCol,
|
||||
table: humanTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
HumanDisplayNameCol = Column{
|
||||
name: projection.HumanDisplayNameCol,
|
||||
table: humanTable,
|
||||
name: projection.HumanDisplayNameCol,
|
||||
table: humanTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
HumanPreferredLanguageCol = Column{
|
||||
name: projection.HumanPreferredLanguageCol,
|
||||
@@ -193,8 +198,9 @@ var (
|
||||
|
||||
// email
|
||||
HumanEmailCol = Column{
|
||||
name: projection.HumanEmailCol,
|
||||
table: humanTable,
|
||||
name: projection.HumanEmailCol,
|
||||
table: humanTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
HumanIsEmailVerifiedCol = Column{
|
||||
name: projection.HumanIsEmailVerifiedCol,
|
||||
@@ -221,8 +227,9 @@ var (
|
||||
table: machineTable,
|
||||
}
|
||||
MachineNameCol = Column{
|
||||
name: projection.MachineNameCol,
|
||||
table: machineTable,
|
||||
name: projection.MachineNameCol,
|
||||
table: machineTable,
|
||||
isOrderByLower: true,
|
||||
}
|
||||
MachineDescriptionCol = Column{
|
||||
name: projection.MachineDescriptionCol,
|
||||
@@ -397,27 +404,27 @@ func NewUserResourceOwnerSearchQuery(value string, comparison TextComparison) (S
|
||||
}
|
||||
|
||||
func NewUserUsernameSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(UserUsernameCol, value, comparison)
|
||||
return NewTextQuery(Column(UserUsernameCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserFirstNameSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(HumanFirstNameCol, value, comparison)
|
||||
return NewTextQuery(Column(HumanFirstNameCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserLastNameSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(HumanLastNameCol, value, comparison)
|
||||
return NewTextQuery(Column(HumanLastNameCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserNickNameSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(HumanNickNameCol, value, comparison)
|
||||
return NewTextQuery(Column(HumanNickNameCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserDisplayNameSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(HumanDisplayNameCol, value, comparison)
|
||||
return NewTextQuery(Column(HumanDisplayNameCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserEmailSearchQuery(value string, comparison TextComparison) (SearchQuery, error) {
|
||||
return NewTextQuery(HumanEmailCol, value, comparison)
|
||||
return NewTextQuery(Column(HumanEmailCol), value, comparison)
|
||||
}
|
||||
|
||||
func NewUserStateSearchQuery(value int32) (SearchQuery, error) {
|
||||
|
Reference in New Issue
Block a user