2020-06-16 11:40:18 +02:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-12-21 18:42:34 +01:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2020-12-18 16:47:45 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
2020-06-16 11:40:18 +02:00
|
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
|
|
|
"github.com/caos/zitadel/internal/org/repository/view"
|
|
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
2020-06-25 08:01:13 +02:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-06-16 11:40:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
orgDomainTable = "management.org_domains"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *View) OrgDomainByOrgIDAndDomain(orgID, domain string) (*model.OrgDomainView, error) {
|
|
|
|
return view.OrgDomainByOrgIDAndDomain(v.Db, orgDomainTable, orgID, domain)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) OrgDomainsByOrgID(domain string) ([]*model.OrgDomainView, error) {
|
|
|
|
return view.OrgDomainsByOrgID(v.Db, orgDomainTable, domain)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) VerifiedOrgDomain(domain string) (*model.OrgDomainView, error) {
|
|
|
|
return view.VerifiedOrgDomain(v.Db, orgDomainTable, domain)
|
|
|
|
}
|
|
|
|
|
2020-07-30 14:37:55 +02:00
|
|
|
func (v *View) SearchOrgDomains(request *org_model.OrgDomainSearchRequest) ([]*model.OrgDomainView, uint64, error) {
|
2020-06-16 11:40:18 +02:00
|
|
|
return view.SearchOrgDomains(v.Db, orgDomainTable, request)
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutOrgDomain(org *model.OrgDomainView, event *models.Event) error {
|
2020-06-16 11:40:18 +02:00
|
|
|
err := view.PutOrgDomain(v.Db, orgDomainTable, org)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-21 18:42:34 +01:00
|
|
|
return v.ProcessedOrgDomainSequence(event)
|
2020-06-16 11:40:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutOrgDomains(domains []*model.OrgDomainView, event *models.Event) error {
|
2020-08-26 13:01:37 +02:00
|
|
|
err := view.PutOrgDomains(v.Db, orgDomainTable, domains...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserSequence(event)
|
2020-08-26 13:01:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteOrgDomain(orgID, domain string, event *models.Event) error {
|
2020-06-17 17:23:39 +02:00
|
|
|
err := view.DeleteOrgDomain(v.Db, orgDomainTable, orgID, domain)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-06-16 11:40:18 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedOrgDomainSequence(event)
|
2020-06-16 11:40:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) GetLatestOrgDomainSequence(aggregateType string) (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(orgDomainTable, aggregateType)
|
2020-06-16 11:40:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) ProcessedOrgDomainSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(orgDomainTable, event)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateOrgDomainSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(orgDomainTable)
|
2020-06-16 11:40:18 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) GetLatestOrgDomainFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
2020-06-16 11:40:18 +02:00
|
|
|
return v.latestFailedEvent(orgDomainTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) ProcessedOrgDomainFailedEvent(failedEvent *repository.FailedEvent) error {
|
2020-06-16 11:40:18 +02:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|