2020-06-16 09:40:18 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-12-18 15:47:45 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
2020-06-16 09:40:18 +00: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 06:01:13 +00:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-06-16 09:40:18 +00: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 12:37:55 +00:00
|
|
|
func (v *View) SearchOrgDomains(request *org_model.OrgDomainSearchRequest) ([]*model.OrgDomainView, uint64, error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
return view.SearchOrgDomains(v.Db, orgDomainTable, request)
|
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutOrgDomain(org *model.OrgDomainView, event *models.Event) error {
|
2020-06-16 09:40:18 +00:00
|
|
|
err := view.PutOrgDomain(v.Db, orgDomainTable, org)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
if event.Sequence != 0 {
|
|
|
|
return v.ProcessedOrgDomainSequence(event)
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutOrgDomains(domains []*model.OrgDomainView, event *models.Event) error {
|
2020-08-26 11:01:37 +00:00
|
|
|
err := view.PutOrgDomains(v.Db, orgDomainTable, domains...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedUserSequence(event)
|
2020-08-26 11:01:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) DeleteOrgDomain(orgID, domain string, event *models.Event) error {
|
2020-06-17 15:23:39 +00:00
|
|
|
err := view.DeleteOrgDomain(v.Db, orgDomainTable, orgID, domain)
|
2020-06-16 09:40:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedOrgDomainSequence(event)
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) GetLatestOrgDomainSequence(aggregateType string) (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(orgDomainTable, aggregateType)
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) ProcessedOrgDomainSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(orgDomainTable, event)
|
2020-12-02 07:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateOrgDomainSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(orgDomainTable)
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 06:01:13 +00:00
|
|
|
func (v *View) GetLatestOrgDomainFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
return v.latestFailedEvent(orgDomainTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-06-25 06:01:13 +00:00
|
|
|
func (v *View) ProcessedOrgDomainFailedEvent(failedEvent *repository.FailedEvent) error {
|
2020-06-16 09:40:18 +00:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|