mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
3cd3a238c2
* fix: all enums same style * fix: rename process to reduce * add some missing enum renaming Co-authored-by: Livio Amstutz <livio.a@gmail.com>
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
package view
|
|
|
|
import (
|
|
global_model "github.com/caos/zitadel/internal/model"
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
"github.com/caos/zitadel/internal/project/repository/view/model"
|
|
"github.com/caos/zitadel/internal/view"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model.ProjectGrantMemberView, error) {
|
|
role := new(model.ProjectGrantMemberView)
|
|
|
|
grantIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals}
|
|
userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
|
query := view.PrepareGetByQuery(table, grantIDQuery, userIDQuery)
|
|
err := query(db, role)
|
|
return role, err
|
|
}
|
|
|
|
func SearchProjectGrantMembers(db *gorm.DB, table string, req *proj_model.ProjectGrantMemberSearchRequest) ([]*model.ProjectGrantMemberView, int, error) {
|
|
roles := make([]*model.ProjectGrantMemberView, 0)
|
|
query := view.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
|
count, err := query(db, &roles)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return roles, count, nil
|
|
}
|
|
|
|
func ProjectGrantMembersByUserID(db *gorm.DB, table, userID string) ([]*model.ProjectGrantMemberView, error) {
|
|
members := make([]*model.ProjectGrantMemberView, 0)
|
|
queries := []*proj_model.ProjectGrantMemberSearchQuery{
|
|
&proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals},
|
|
}
|
|
query := view.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Queries: queries})
|
|
_, err := query(db, &members)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return members, nil
|
|
}
|
|
|
|
func PutProjectGrantMember(db *gorm.DB, table string, role *model.ProjectGrantMemberView) error {
|
|
save := view.PrepareSave(table)
|
|
return save(db, role)
|
|
}
|
|
|
|
func DeleteProjectGrantMember(db *gorm.DB, table, grantID, userID string) error {
|
|
role, err := ProjectGrantMemberByIDs(db, table, grantID, userID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
delete := view.PrepareDeleteByObject(table, role)
|
|
return delete(db)
|
|
}
|