-
Notifications
You must be signed in to change notification settings - Fork 509
/
features_view.go
48 lines (42 loc) · 1.63 KB
/
features_view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package view
import (
"github.com/jinzhu/gorm"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/features/model"
view_model "github.com/caos/zitadel/internal/features/repository/view/model"
"github.com/caos/zitadel/internal/view/repository"
)
func GetDefaultFeatures(db *gorm.DB, table string) ([]*view_model.FeaturesView, error) {
features := make([]*view_model.FeaturesView, 0)
queries := []*model.FeaturesSearchQuery{
{Key: model.FeaturesSearchKeyDefault, Value: true, Method: domain.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, view_model.FeaturesSearchRequest{Queries: queries})
_, err := query(db, &features)
if err != nil {
return nil, err
}
return features, nil
}
func GetFeaturesByAggregateID(db *gorm.DB, table, aggregateID string) (*view_model.FeaturesView, error) {
features := new(view_model.FeaturesView)
query := repository.PrepareGetByKey(table, view_model.FeaturesSearchKey(model.FeaturesSearchKeyAggregateID), aggregateID)
err := query(db, features)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Dbf3h", "Errors.Features.NotFound")
}
return features, err
}
func PutFeatures(db *gorm.DB, table string, features *view_model.FeaturesView) error {
save := repository.PrepareSave(table)
return save(db, features)
}
func PutFeaturesList(db *gorm.DB, table string, featuresList ...*view_model.FeaturesView) error {
save := repository.PrepareBulkSave(table)
f := make([]interface{}, len(featuresList))
for i, features := range featuresList {
f[i] = features
}
return save(db, f...)
}