mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
70e98460ab
* 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>
110 lines
3.1 KiB
Go
110 lines
3.1 KiB
Go
package org
|
|
|
|
import (
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
instance_pb "github.com/zitadel/zitadel/pkg/grpc/instance"
|
|
)
|
|
|
|
func InstancesToPb(instances []*query.Instance) []*instance_pb.Instance {
|
|
list := make([]*instance_pb.Instance, len(instances))
|
|
for i, instance := range instances {
|
|
list[i] = InstanceToPb(instance)
|
|
}
|
|
return list
|
|
}
|
|
|
|
func InstanceToPb(instance *query.Instance) *instance_pb.Instance {
|
|
return &instance_pb.Instance{
|
|
Details: object.ToViewDetailsPb(
|
|
instance.Sequence,
|
|
instance.CreationDate,
|
|
instance.ChangeDate,
|
|
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),
|
|
}
|
|
}
|
|
|
|
func InstanceQueriesToModel(queries []*instance_pb.Query) (_ []query.SearchQuery, err error) {
|
|
q := make([]query.SearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i], err = InstanceQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return q, nil
|
|
}
|
|
|
|
func InstanceQueryToModel(searchQuery *instance_pb.Query) (query.SearchQuery, error) {
|
|
switch q := searchQuery.Query.(type) {
|
|
case *instance_pb.Query_IdQuery:
|
|
return query.NewInstanceIDsListSearchQuery(q.IdQuery.Ids...)
|
|
default:
|
|
return nil, errors.ThrowInvalidArgument(nil, "INST-3m0se", "List.Query.Invalid")
|
|
}
|
|
}
|
|
|
|
func DomainQueriesToModel(queries []*instance_pb.DomainSearchQuery) (_ []query.SearchQuery, err error) {
|
|
q := make([]query.SearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i], err = DomainQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return q, nil
|
|
}
|
|
|
|
func DomainQueryToModel(searchQuery *instance_pb.DomainSearchQuery) (query.SearchQuery, error) {
|
|
switch q := searchQuery.Query.(type) {
|
|
case *instance_pb.DomainSearchQuery_DomainQuery:
|
|
return query.NewInstanceDomainDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain)
|
|
case *instance_pb.DomainSearchQuery_GeneratedQuery:
|
|
return query.NewInstanceDomainGeneratedSearchQuery(q.GeneratedQuery.Generated)
|
|
case *instance_pb.DomainSearchQuery_PrimaryQuery:
|
|
return query.NewInstanceDomainPrimarySearchQuery(q.PrimaryQuery.Primary)
|
|
default:
|
|
return nil, errors.ThrowInvalidArgument(nil, "INST-Ags42", "List.Query.Invalid")
|
|
}
|
|
}
|
|
|
|
func DomainsToPb(domains []*query.InstanceDomain) []*instance_pb.Domain {
|
|
d := make([]*instance_pb.Domain, len(domains))
|
|
for i, domain := range domains {
|
|
d[i] = DomainToPb(domain)
|
|
}
|
|
return d
|
|
}
|
|
|
|
func DomainToPb(d *query.InstanceDomain) *instance_pb.Domain {
|
|
return &instance_pb.Domain{
|
|
Domain: d.Domain,
|
|
Primary: d.IsPrimary,
|
|
Generated: d.IsGenerated,
|
|
Details: object.ToViewDetailsPb(
|
|
d.Sequence,
|
|
d.CreationDate,
|
|
d.ChangeDate,
|
|
d.InstanceID,
|
|
),
|
|
}
|
|
}
|