2020-05-11 12:16:29 +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-05-11 12:16:29 +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-05-11 12:16:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
projectGrantMemberTable = "management.project_grant_members"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *View) ProjectGrantMemberByIDs(projectID, userID string) (*model.ProjectGrantMemberView, error) {
|
|
|
|
return view.ProjectGrantMemberByIDs(v.Db, projectGrantMemberTable, projectID, userID)
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:32:25 +02:00
|
|
|
func (v *View) ProjectGrantMembersByProjectID(projectID string) ([]*model.ProjectGrantMemberView, error) {
|
|
|
|
return view.ProjectGrantMembersByProjectID(v.Db, projectGrantMemberTable, projectID)
|
|
|
|
}
|
|
|
|
|
2020-07-30 14:37:55 +02:00
|
|
|
func (v *View) SearchProjectGrantMembers(request *proj_model.ProjectGrantMemberSearchRequest) ([]*model.ProjectGrantMemberView, uint64, error) {
|
2020-05-11 12:16:29 +02:00
|
|
|
return view.SearchProjectGrantMembers(v.Db, projectGrantMemberTable, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProjectGrantMembersByUserID(userID string) ([]*model.ProjectGrantMemberView, error) {
|
|
|
|
return view.ProjectGrantMembersByUserID(v.Db, projectGrantMemberTable, userID)
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutProjectGrantMember(member *model.ProjectGrantMemberView, event *models.Event) error {
|
2020-08-26 13:01:37 +02:00
|
|
|
err := view.PutProjectGrantMember(v.Db, projectGrantMemberTable, member)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedProjectGrantMemberSequence(event)
|
2020-08-26 13:01:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutProjectGrantMembers(members []*model.ProjectGrantMemberView, event *models.Event) error {
|
2020-08-26 13:01:37 +02:00
|
|
|
err := view.PutProjectGrantMembers(v.Db, projectGrantMemberTable, members...)
|
2020-05-11 12:16:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedProjectGrantMemberSequence(event)
|
2020-05-11 12:16:29 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteProjectGrantMember(grantID, userID string, event *models.Event) error {
|
2020-07-09 17:56:37 +02:00
|
|
|
err := view.DeleteProjectGrantMember(v.Db, projectGrantMemberTable, grantID, userID)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-05-11 12:16:29 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedProjectGrantMemberSequence(event)
|
2020-05-11 12:16:29 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 18:32:25 +02:00
|
|
|
func (v *View) DeleteProjectGrantMembersByProjectID(projectID string) error {
|
|
|
|
return view.DeleteProjectGrantMembersByProjectID(v.Db, projectGrantMemberTable, projectID)
|
|
|
|
}
|
|
|
|
|
2021-01-27 10:35:01 +01:00
|
|
|
func (v *View) GetLatestProjectGrantMemberSequence() (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(projectGrantMemberTable)
|
2020-05-11 12:16:29 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) ProcessedProjectGrantMemberSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(projectGrantMemberTable, event)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateProjectGrantMemberSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(projectGrantMemberTable)
|
2020-05-11 12:16:29 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) GetLatestProjectGrantMemberFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
2020-05-11 12:16:29 +02:00
|
|
|
return v.latestFailedEvent(projectGrantMemberTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-06-25 08:01:13 +02:00
|
|
|
func (v *View) ProcessedProjectGrantMemberFailedEvent(failedEvent *repository.FailedEvent) error {
|
2020-05-11 12:16:29 +02:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|