Documentation ¶
Index ¶
- Constants
- func QueryForCollections(q *gorm.DB) *gorm.DB
- type Collection
- type CollectionAsset
- type CollectionAssets
- type Collections
- type CreateCollection
- type NameOwnerPair
- type ResourceWithID
- type Service
- func (s *Service) AddAsset(ctx context.Context, tx *gorm.DB, owner, name string, no NameOwnerPair, ...) (*Collection, *ign.ErrMsg)
- func (s *Service) CollectionList(p *ign.PaginationRequest, tx *gorm.DB, owner *string, order, search string, ...) (*Collections, *ign.PaginationResult, *ign.ErrMsg)
- func (s *Service) CreateCollection(ctx context.Context, tx *gorm.DB, cc CreateCollection, creator *users.User) (*Collection, *ign.ErrMsg)
- func (s *Service) GetAssociatedCollections(p *ign.PaginationRequest, tx *gorm.DB, no NameOwnerPair, assetType string, ...) (*Collections, *ign.PaginationResult, *ign.ErrMsg)
- func (s *Service) GetCollection(tx *gorm.DB, owner, name string, user *users.User) (*Collection, *ign.ErrMsg)
- func (s *Service) GetCollectionAssets(p *ign.PaginationRequest, tx *gorm.DB, colOwner, colName string, ...) (interface{}, *ign.PaginationResult, *ign.ErrMsg)
- func (s *Service) GetFile(ctx context.Context, tx *gorm.DB, owner, name, path, version string, ...) (*[]byte, int, *ign.ErrMsg)
- func (s *Service) RemoveAsset(ctx context.Context, tx *gorm.DB, owner, name string, no NameOwnerPair, ...) (*Collection, *ign.ErrMsg)
- func (s *Service) RemoveCollection(tx *gorm.DB, owner, name string, user *users.User) *ign.ErrMsg
- func (s *Service) UpdateCollection(ctx context.Context, tx *gorm.DB, colOwner, colName string, ...) (*Collection, *ign.ErrMsg)
- type UpdateCollection
Constants ¶
const ( // TModel is used to represent the asset type "model" TModel string = "model" // TWorld is used to represent the asset type "world" TWorld string = "world" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Collection ¶
type Collection struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // Added 2 milliseconds to DeletedAt field, and added it to the unique index // to help disambiguate when soft deleted rows are involved. DeletedAt *time.Time `gorm:"type:timestamp(2) NULL; unique_index:idx_colname_owner" sql:"index"` // The name of the collection Name *string `gorm:"unique_index:idx_colname_owner" json:"name,omitempty"` // Unique identifier UUID *string `json:"-"` // A description of the collection (max 65,535 chars) Description *string `gorm:"type:text" json:"description,omitempty"` // Location on disk Location *string `json:"-"` // The owner of this collection (must exist in UniqueOwners). Can be user or org. Owner *string `gorm:"unique_index:idx_colname_owner" json:"owner,omitempty"` // The username of the User that created this collection (usually got from the JWT) Creator *string `json:"-"` // Private - True to make this a private resource Private *bool `json:"private,omitempty"` // A list of thumbnail urls from the associated models/worlds. ThumbnailUrls []string `gorm:"-" json:"thumbnails,omitempty"` }
Collection represents a collection of assets.
A collection has a name, owner and optional description.
swagger:model dbCollection
func ByName ¶
func ByName(tx *gorm.DB, name, owner string) (*Collection, error)
ByName queries a Collection by name and owner.
func NewCollection ¶
func NewCollection(name, desc, owner, creator *string, private bool) (Collection, error)
NewCollection creates a new Model struct
func (*Collection) GetLocation ¶
func (c *Collection) GetLocation() *string
GetLocation returns the location on disk
type CollectionAsset ¶
type CollectionAsset struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` // The collection ID ColID uint `json:"-"` // The related asset ID (eg model ID) AssetID uint `json:"-"` // The name of the related asset AssetName string `json:"asset_name,omitempty"` // The owner of the related asset (org / user) AssetOwner string `json:"asset_owner,omitempty"` // The asset type (model | world). Type string `json:"type,omitempty"` }
CollectionAsset represents an association between a collection and a resource. It was implemented with a "type" to support adding new types easily.
func FindAssociation ¶
func FindAssociation(tx *gorm.DB, colID uint, owner, name, assetType string) (*CollectionAsset, error)
FindAssociation queries CollectionAssets by name, owner and type.
type CollectionAssets ¶
type CollectionAssets []CollectionAsset
CollectionAssets is a list of Collection assets swagger:model dbCollectionAssets
func FindAssociations ¶
func FindAssociations(tx *gorm.DB, col *Collection, limit int) (*CollectionAssets, error)
FindAssociations returns a list of CollectionAssets from a given Collection.
type Collections ¶
type Collections []Collection
Collections is an array of Collection swagger:model dbCollections
type CreateCollection ¶
type CreateCollection struct { // The name // required: true Name string `json:"name" validate:"required,noforwardslash,min=3"` // Optional Owner. Must be a user or an org. // If not set, the current user will be used as owner Owner string `json:"owner" form:"owner"` // Optional description Description string `json:"description" form:"description"` // Optional privacy/visibility setting. Private *bool `json:"private" validate:"omitempty" form:"private"` }
CreateCollection encapsulates data required to create a collection
type NameOwnerPair ¶
type NameOwnerPair struct { // The name // required: true Name string `json:"name" validate:"required,noforwardslash"` // Asset Owner. Must be a user or an org. // required: true Owner string `json:"owner" validate:"required"` }
NameOwnerPair describes a name and owner to find an asset.
type ResourceWithID ¶
type ResourceWithID interface {
GetID() uint
}
ResourceWithID is used for resources that have a DB ID (eg. Model or World)
type Service ¶
type Service struct{}
Service is the main struct exported by this collections Service.
func (*Service) AddAsset ¶
func (s *Service) AddAsset(ctx context.Context, tx *gorm.DB, owner, name string, no NameOwnerPair, assetType string, user *users.User) (*Collection, *ign.ErrMsg)
AddAsset adds an asset to a collection. The user argument is the active user requesting the operation.
func (*Service) CollectionList ¶
func (s *Service) CollectionList(p *ign.PaginationRequest, tx *gorm.DB, owner *string, order, search string, extend bool, user *users.User) (*Collections, *ign.PaginationResult, *ign.ErrMsg)
CollectionList returns a paginated list of Collections. Note: 'extend' argument is to only return collections that the user can add/remove assets (which is not the same as 'updating the collection details').
func (*Service) CreateCollection ¶
func (s *Service) CreateCollection(ctx context.Context, tx *gorm.DB, cc CreateCollection, creator *users.User) (*Collection, *ign.ErrMsg)
CreateCollection creates a new collections. creator argument is the active user requesting the operation.
func (*Service) GetAssociatedCollections ¶
func (s *Service) GetAssociatedCollections(p *ign.PaginationRequest, tx *gorm.DB, no NameOwnerPair, assetType string, user *users.User) (*Collections, *ign.PaginationResult, *ign.ErrMsg)
GetAssociatedCollections returns a paginated list of collections given the name and owner of an associated asset (eg. model or world). The "assetType" argument is used to identify if the name and owner correspond to a model or world. The user argument is the user requesting the operation.
func (*Service) GetCollection ¶
func (s *Service) GetCollection(tx *gorm.DB, owner, name string, user *users.User) (*Collection, *ign.ErrMsg)
GetCollection returns a single Collection by its name and owner's name. Optional: The user argument is the requesting user. It is used to check if the user can perform the operation.
func (*Service) GetCollectionAssets ¶
func (s *Service) GetCollectionAssets(p *ign.PaginationRequest, tx *gorm.DB, colOwner, colName string, assetsType string, user *users.User) (interface{}, *ign.PaginationResult, *ign.ErrMsg)
GetCollectionAssets returns a paginated list of assets from a collection. The optional "assetsType" argument can be used to filter which type of assets to return. The user argument is the user requesting the operation.
func (*Service) GetFile ¶
func (s *Service) GetFile(ctx context.Context, tx *gorm.DB, owner, name, path, version string, user *users.User) (*[]byte, int, *ign.ErrMsg)
GetFile returns the contents (bytes) of a collection file. Version is considered. Returns the file's bytes and the resolved version. The user argument is the user requesting the operation.
func (*Service) RemoveAsset ¶
func (s *Service) RemoveAsset(ctx context.Context, tx *gorm.DB, owner, name string, no NameOwnerPair, assetType string, user *users.User) (*Collection, *ign.ErrMsg)
RemoveAsset removes an asset from a collection. user argument is the active user requesting the operation.
func (*Service) RemoveCollection ¶
RemoveCollection removes a Collection. The user argument is the requesting user. It is used to check if the user can perform the operation.
func (*Service) UpdateCollection ¶
func (s *Service) UpdateCollection(ctx context.Context, tx *gorm.DB, colOwner, colName string, desc, filesPath *string, private *bool, user *users.User) (*Collection, *ign.ErrMsg)
UpdateCollection updates a collection. The user argument is the requesting user. It is used to check if the user can perform the operation. Fields that can be currently updated: desc, private. The filesPath argument points to a tmp folder from which to read the new files. Returns the updated collection. Note: it will be the same instance as 'col' arg.
type UpdateCollection ¶
type UpdateCollection struct { // Optional description Description *string `json:"description" form:"description"` // Optional collection logo File string `json:"file" validate:"omitempty,gt=0" form:"-"` // Private privacy/visibility setting Private *bool `json:"private" validate:"omitempty" form:"private"` }
UpdateCollection encapsulates data that can be updated in a collection
func (UpdateCollection) IsEmpty ¶
func (uc UpdateCollection) IsEmpty() bool
IsEmpty returns true is the struct is empty.