2020-05-26 16:46:16 +02:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
|
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
2020-06-16 11:40:18 +02:00
|
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
2020-05-26 16:46:16 +02:00
|
|
|
"github.com/caos/zitadel/internal/view"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
2020-06-16 11:40:18 +02:00
|
|
|
func OrgByID(db *gorm.DB, table, orgID string) (*model.OrgView, error) {
|
|
|
|
org := new(model.OrgView)
|
|
|
|
query := view.PrepareGetByKey(table, model.OrgSearchKey(org_model.ORGSEARCHKEY_ORG_ID), orgID)
|
2020-05-26 16:46:16 +02:00
|
|
|
err := query(db, org)
|
|
|
|
return org, err
|
|
|
|
}
|
|
|
|
|
2020-06-16 11:40:18 +02:00
|
|
|
func SearchOrgs(db *gorm.DB, table string, req *org_model.OrgSearchRequest) ([]*model.OrgView, int, error) {
|
|
|
|
orgs := make([]*model.OrgView, 0)
|
|
|
|
query := view.PrepareSearchQuery(table, model.OrgSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
2020-05-26 16:46:16 +02:00
|
|
|
count, err := query(db, &orgs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
return orgs, count, nil
|
|
|
|
}
|
|
|
|
|
2020-06-16 11:40:18 +02:00
|
|
|
func PutOrg(db *gorm.DB, table string, org *model.OrgView) error {
|
2020-05-26 16:46:16 +02:00
|
|
|
save := view.PrepareSave(table)
|
|
|
|
return save(db, org)
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteOrg(db *gorm.DB, table, orgID string) error {
|
2020-06-16 11:40:18 +02:00
|
|
|
delete := view.PrepareDeleteByKey(table, model.OrgSearchKey(org_model.ORGSEARCHKEY_ORG_ID), orgID)
|
2020-05-26 16:46:16 +02:00
|
|
|
return delete(db)
|
|
|
|
}
|