2020-05-26 16:46:16 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-04-07 09:56:45 +02:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
caos_errors "github.com/caos/zitadel/internal/errors"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
2020-05-26 16:46:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type OrgView struct {
|
|
|
|
ID string
|
|
|
|
CreationDate time.Time
|
|
|
|
ChangeDate time.Time
|
|
|
|
State OrgState
|
|
|
|
ResourceOwner string
|
|
|
|
Sequence uint64
|
|
|
|
|
2020-06-16 11:40:18 +02:00
|
|
|
Name string
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type OrgSearchRequest struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
SortingColumn OrgSearchKey
|
|
|
|
Asc bool
|
|
|
|
Queries []*OrgSearchQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
type OrgSearchKey int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 14:47:47 +02:00
|
|
|
OrgSearchKeyUnspecified OrgSearchKey = iota
|
|
|
|
OrgSearchKeyOrgID
|
|
|
|
OrgSearchKeyOrgName
|
|
|
|
OrgSearchKeyOrgDomain
|
|
|
|
OrgSearchKeyState
|
|
|
|
OrgSearchKeyResourceOwner
|
2021-04-07 09:56:45 +02:00
|
|
|
OrgSearchKeyOrgNameIgnoreCase //used for lowercase search
|
2020-05-26 16:46:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type OrgSearchQuery struct {
|
|
|
|
Key OrgSearchKey
|
2021-03-01 08:48:50 +01:00
|
|
|
Method domain.SearchMethod
|
2020-06-16 11:40:18 +02:00
|
|
|
Value interface{}
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type OrgSearchResult struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
TotalResult uint64
|
|
|
|
Result []*OrgView
|
2020-07-15 13:24:36 +02:00
|
|
|
Sequence uint64
|
|
|
|
Timestamp time.Time
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 16:03:07 +02:00
|
|
|
func (r *OrgSearchRequest) EnsureLimit(limit uint64) error {
|
|
|
|
if r.Limit > limit {
|
|
|
|
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-200ds", "Errors.Limit.ExceedsDefault")
|
|
|
|
}
|
|
|
|
if r.Limit == 0 {
|
2020-05-26 16:46:16 +02:00
|
|
|
r.Limit = limit
|
|
|
|
}
|
2021-04-06 16:03:07 +02:00
|
|
|
return nil
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func OrgViewToOrg(o *OrgView) *Org {
|
|
|
|
return &Org{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: o.ID,
|
|
|
|
ChangeDate: o.ChangeDate,
|
|
|
|
CreationDate: o.CreationDate,
|
|
|
|
ResourceOwner: o.ResourceOwner,
|
|
|
|
Sequence: o.Sequence,
|
|
|
|
},
|
2020-06-16 11:40:18 +02:00
|
|
|
Name: o.Name,
|
|
|
|
State: o.State,
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
}
|