2020-06-15 14:50:39 +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-15 14:50:39 +02:00
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
|
|
"github.com/caos/zitadel/internal/project/repository/view"
|
|
|
|
"github.com/caos/zitadel/internal/project/repository/view/model"
|
2020-06-25 08:01:13 +02:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-06-15 14:50:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
projectTable = "management.projects"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *View) ProjectByID(projectID string) (*model.ProjectView, error) {
|
|
|
|
return view.ProjectByID(v.Db, projectTable, projectID)
|
|
|
|
}
|
|
|
|
|
2020-07-30 14:37:55 +02:00
|
|
|
func (v *View) SearchProjects(request *proj_model.ProjectViewSearchRequest) ([]*model.ProjectView, uint64, error) {
|
2020-06-15 14:50:39 +02:00
|
|
|
return view.SearchProjects(v.Db, projectTable, request)
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutProject(project *model.ProjectView, event *models.Event) error {
|
2020-06-15 14:50:39 +02:00
|
|
|
err := view.PutProject(v.Db, projectTable, project)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedProjectSequence(event)
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteProject(projectID string, event *models.Event) error {
|
2020-06-15 14:50:39 +02:00
|
|
|
err := view.DeleteProject(v.Db, projectTable, projectID)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedProjectSequence(event)
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2021-01-27 10:35:01 +01:00
|
|
|
func (v *View) GetLatestProjectSequence() (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(projectTable)
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) ProcessedProjectSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(projectTable, event)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateProjectSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(projectTable)
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) GetLatestProjectFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
2020-06-15 14:50:39 +02:00
|
|
|
return v.latestFailedEvent(projectTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) ProcessedProjectFailedEvent(failedEvent *repository.FailedEvent) error {
|
2020-06-15 14:50:39 +02:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|