2020-06-15 12:50:39 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2021-03-01 07:48:50 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-04-06 14:03:07 +00:00
|
|
|
caos_errors "github.com/caos/zitadel/internal/errors"
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectView struct {
|
2020-10-16 05:49:38 +00:00
|
|
|
ProjectID string
|
|
|
|
Name string
|
|
|
|
CreationDate time.Time
|
|
|
|
ChangeDate time.Time
|
|
|
|
State ProjectState
|
|
|
|
ResourceOwner string
|
|
|
|
ProjectRoleAssertion bool
|
|
|
|
ProjectRoleCheck bool
|
|
|
|
Sequence uint64
|
2020-06-15 12:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectViewSearchRequest struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
SortingColumn ProjectViewSearchKey
|
|
|
|
Asc bool
|
|
|
|
Queries []*ProjectViewSearchQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectViewSearchKey int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 12:47:47 +00:00
|
|
|
ProjectViewSearchKeyUnspecified ProjectViewSearchKey = iota
|
|
|
|
ProjectViewSearchKeyName
|
|
|
|
ProjectViewSearchKeyProjectID
|
|
|
|
ProjectViewSearchKeyResourceOwner
|
2020-06-15 12:50:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectViewSearchQuery struct {
|
|
|
|
Key ProjectViewSearchKey
|
2021-03-01 07:48:50 +00:00
|
|
|
Method domain.SearchMethod
|
2020-06-15 12:50:39 +00:00
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectViewSearchResponse struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
TotalResult uint64
|
|
|
|
Result []*ProjectView
|
2020-07-15 11:24:36 +00:00
|
|
|
Sequence uint64
|
|
|
|
Timestamp time.Time
|
2020-06-15 12:50:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 12:00:29 +00:00
|
|
|
func (r *ProjectViewSearchRequest) GetSearchQuery(key ProjectViewSearchKey) (int, *ProjectViewSearchQuery) {
|
|
|
|
for i, q := range r.Queries {
|
|
|
|
if q.Key == key {
|
|
|
|
return i, q
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func (r *ProjectViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) {
|
2021-03-01 07:48:50 +00:00
|
|
|
r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: ProjectViewSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID})
|
2020-06-15 12:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 14:03:07 +00:00
|
|
|
func (r *ProjectViewSearchRequest) EnsureLimit(limit uint64) error {
|
|
|
|
if r.Limit > limit {
|
|
|
|
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-2M0ds", "Errors.Limit.ExceedsDefault")
|
|
|
|
}
|
|
|
|
if r.Limit == 0 {
|
2020-06-15 12:50:39 +00:00
|
|
|
r.Limit = limit
|
|
|
|
}
|
2021-04-06 14:03:07 +00:00
|
|
|
return nil
|
2020-06-15 12:50:39 +00:00
|
|
|
}
|