repository

package
v0.0.0-...-2d73068 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 12 Imported by: 13

Documentation

Overview

Package repository provides the APIs for making 'resource' related database interactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormResourceRepository

type GormResourceRepository struct {
	// contains filtered or unexported fields
}

GormResourceRepository is the implementation of the storage interface for Resource.

func (*GormResourceRepository) CheckExists

func (m *GormResourceRepository) CheckExists(ctx context.Context, id string) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormResourceRepository) Create

func (m *GormResourceRepository) Create(ctx context.Context, resource *Resource) error

Create creates a new record.

func (*GormResourceRepository) Delete

func (m *GormResourceRepository) Delete(ctx context.Context, id string) error

Delete removes a single record.

func (*GormResourceRepository) FindWithRoleByResourceTypeAndIdentity

func (m *GormResourceRepository) FindWithRoleByResourceTypeAndIdentity(ctx context.Context, resourceType string, identityID uuid.UUID) ([]string, error)

FindWithRoleByResourceTypeAndIdentity returns the IDs of the resources of the given type for which the given user (identity) has a role in.

func (*GormResourceRepository) Load

Load returns a single Resource as a Database Model

func (*GormResourceRepository) LoadChildren

func (m *GormResourceRepository) LoadChildren(ctx context.Context, id string) ([]Resource, error)

LoadChildren returns direct children resources of the given resource or an empty array if no children found

func (*GormResourceRepository) Save

func (m *GormResourceRepository) Save(ctx context.Context, resource *Resource) error

Save modifies a single record.

func (*GormResourceRepository) TableName

func (m *GormResourceRepository) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

type Resource

type Resource struct {
	gormsupport.Lifecycle

	// This is the primary key value
	ResourceID string `sql:"type:string" gorm:"primary_key;column:resource_id"`
	// The parent resource ID
	ParentResourceID *string
	// The parent resource
	ParentResource *Resource `gorm:"foreignkey:ParentResourceID;association_foreignkey:ResourceID"`
	// The resource type
	ResourceType resourcetype.ResourceType `gorm:"foreignkey:ResourceTypeID;association_foreignkey:ResourceTypeID"`
	// The identifier for the resource type
	ResourceTypeID uuid.UUID
	// Resource name
	Name string
}

func (Resource) GetLastModified

func (m Resource) GetLastModified() time.Time

GetLastModified returns the last modification time

func (Resource) TableName

func (m Resource) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

type ResourceRepository

type ResourceRepository interface {
	base.Exister
	Load(ctx context.Context, id string) (*Resource, error)
	LoadChildren(ctx context.Context, id string) ([]Resource, error)
	Create(ctx context.Context, resource *Resource) error
	Save(ctx context.Context, resource *Resource) error
	Delete(ctx context.Context, id string) error
	FindWithRoleByResourceTypeAndIdentity(ctx context.Context, resourceType string, identityID uuid.UUID) ([]string, error)
}

ResourceRepository represents the storage interface.

func NewResourceRepository

func NewResourceRepository(db *gorm.DB) ResourceRepository

NewResourceRepository creates a new storage type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL