2021-02-22 14:08:47 +01:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2021-03-25 17:26:21 +01:00
|
|
|
"time"
|
|
|
|
|
2021-02-22 14:08:47 +01:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2021-02-23 15:13:04 +01:00
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
2021-02-22 14:08:47 +01:00
|
|
|
"github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ProjectByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, error) {
|
|
|
|
if id == "" {
|
|
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dke74", "Errors.Project.ProjectIDMissing")
|
|
|
|
}
|
|
|
|
return ProjectQuery(latestSequence).
|
|
|
|
AggregateIDFilter(id), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ProjectQuery(latestSequence uint64) *es_models.SearchQuery {
|
|
|
|
return es_models.NewSearchQuery().
|
|
|
|
AggregateTypeFilter(model.ProjectAggregate).
|
|
|
|
LatestSequenceFilter(latestSequence)
|
|
|
|
}
|
|
|
|
|
2021-03-25 17:26:21 +01:00
|
|
|
func ChangesQuery(projectID string, latestSequence, limit uint64, sortAscending bool, retention time.Duration) *es_models.SearchQuery {
|
2021-02-22 14:08:47 +01:00
|
|
|
query := es_models.NewSearchQuery().
|
|
|
|
AggregateTypeFilter(model.ProjectAggregate)
|
|
|
|
if !sortAscending {
|
|
|
|
query.OrderDesc()
|
|
|
|
}
|
2021-03-25 17:26:21 +01:00
|
|
|
if retention > 0 {
|
|
|
|
query.CreationDateNewerFilter(time.Now().Add(-retention))
|
|
|
|
}
|
2021-02-22 14:08:47 +01:00
|
|
|
|
|
|
|
query.LatestSequenceFilter(latestSequence).
|
|
|
|
AggregateIDFilter(projectID).
|
|
|
|
SetLimit(limit)
|
|
|
|
return query
|
|
|
|
}
|