mirror of
https://github.com/portainer/portainer.git
synced 2025-08-06 22:35:23 +02:00
feat(dataservices): unify access methods and abstract away redundant code [EE-5628] (#9115)
This commit is contained in:
parent
4c6bbe9a2f
commit
4cc96b4b30
171 changed files with 714 additions and 1590 deletions
|
@ -5,43 +5,13 @@ import (
|
|||
"github.com/portainer/portainer/api/dataservices"
|
||||
)
|
||||
|
||||
// Service represents a service for managing environment(endpoint) data.
|
||||
type ServiceTx struct {
|
||||
service *Service
|
||||
tx portainer.Transaction
|
||||
}
|
||||
|
||||
func (service ServiceTx) BucketName() string {
|
||||
return BucketName
|
||||
}
|
||||
|
||||
// Role returns a Role by ID
|
||||
func (service ServiceTx) Role(ID portainer.RoleID) (*portainer.Role, error) {
|
||||
var set portainer.Role
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
|
||||
err := service.tx.GetObject(BucketName, identifier, &set)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &set, nil
|
||||
}
|
||||
|
||||
// Roles returns an array containing all the sets.
|
||||
func (service ServiceTx) Roles() ([]portainer.Role, error) {
|
||||
var sets = make([]portainer.Role, 0)
|
||||
|
||||
return sets, service.tx.GetAll(
|
||||
BucketName,
|
||||
&portainer.Role{},
|
||||
dataservices.AppendFn(&sets),
|
||||
)
|
||||
dataservices.BaseDataServiceTx[portainer.Role, portainer.RoleID]
|
||||
}
|
||||
|
||||
// CreateRole creates a new Role.
|
||||
func (service ServiceTx) Create(role *portainer.Role) error {
|
||||
return service.tx.CreateObject(
|
||||
return service.Tx.CreateObject(
|
||||
BucketName,
|
||||
func(id uint64) (int, interface{}) {
|
||||
role.ID = portainer.RoleID(id)
|
||||
|
@ -49,9 +19,3 @@ func (service ServiceTx) Create(role *portainer.Role) error {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UpdateRole updates a role.
|
||||
func (service ServiceTx) UpdateRole(ID portainer.RoleID, role *portainer.Role) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.UpdateObject(BucketName, identifier, role)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue