Documentation ¶
Index ¶
- func CreateTags(s *gorm.DB, tags []string) error
- func ElasticSearchRemoveModel(ctx context.Context, model *Model)
- func ElasticSearchUpdateAll(ctx context.Context, tx *gorm.DB)
- func ElasticSearchUpdateModel(ctx context.Context, tx *gorm.DB, model Model)
- func QueryForModels(q *gorm.DB) *gorm.DB
- func TagsToStrSlice(tags Tags) []string
- type CloneModel
- type CreateModel
- type CreateReport
- type Model
- type ModelDownload
- type ModelLike
- type ModelMetadata
- type ModelMetadatum
- type ModelReport
- type Models
- type Service
- func (ms *Service) CloneModel(ctx context.Context, tx *gorm.DB, smOwner, smName string, cm CloneModel, ...) (*Model, *ign.ErrMsg)
- func (ms *Service) ComputeAllCounters(tx *gorm.DB) *ign.ErrMsg
- func (ms *Service) CreateModel(ctx context.Context, tx *gorm.DB, cm CreateModel, uuidStr, filesPath string, ...) (*Model, *ign.ErrMsg)
- func (ms *Service) CreateModelLike(tx *gorm.DB, owner, modelName string, user *users.User) (*ModelLike, int, *ign.ErrMsg)
- func (ms *Service) CreateModelReport(tx *gorm.DB, owner, modelName, reason string) (*ModelReport, *ign.ErrMsg)
- func (ms *Service) DownloadZip(ctx context.Context, tx *gorm.DB, owner, modelName, version string, ...) (*Model, *string, int, *ign.ErrMsg)
- func (ms *Service) GetFile(ctx context.Context, tx *gorm.DB, owner, name, path, version string, ...) (*[]byte, int, *ign.ErrMsg)
- func (ms *Service) GetModel(tx *gorm.DB, owner, name string, user *users.User) (*Model, *ign.ErrMsg)
- func (ms *Service) GetModelProto(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) (*fuel.Model, *ign.ErrMsg)
- func (ms *Service) ModelFileTree(ctx context.Context, tx *gorm.DB, owner, modelName, version string, ...) (*fuel.FileTree, *ign.ErrMsg)
- func (ms *Service) ModelList(p *ign.PaginationRequest, tx *gorm.DB, owner *string, order, search string, ...) (*fuel.Models, *ign.PaginationResult, *ign.ErrMsg)
- func (ms *Service) ModelToProto(model *Model) *fuel.Model
- func (ms *Service) RemoveModel(ctx context.Context, tx *gorm.DB, owner, modelName string, user *users.User) *ign.ErrMsg
- func (ms *Service) RemoveModelLike(tx *gorm.DB, owner, modelName string, user *users.User) (*ModelLike, int, *ign.ErrMsg)
- func (ms *Service) UpdateModel(ctx context.Context, tx *gorm.DB, owner, modelName string, ...) (*Model, *ign.ErrMsg)
- type Tag
- type Tags
- type UpdateModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTags ¶
CreateTags populates DB Tags with the given tags. This function also trims tags before trying to add them.
func ElasticSearchRemoveModel ¶
ElasticSearchRemoveModel removes a model from elastic search
func ElasticSearchUpdateAll ¶
ElasticSearchUpdateAll will update ElasticSearch with all the models in the SQL database.
func ElasticSearchUpdateModel ¶
ElasticSearchUpdateModel will update ElasticSearch with a single model.
func QueryForModels ¶
QueryForModels returns a gorm query configured to query Models with preloaded License, Tags and Categories.
func TagsToStrSlice ¶
TagsToStrSlice creates a string slice from the given Tags.
Types ¶
type CloneModel ¶
type CloneModel struct { // The name of the Model // required: false Name string `json:"name" validate:"omitempty,noforwardslash,min=3,nopercent" form:"name"` // Optional Owner of the model. Must be a user or an org. // If not set, the current user will be used as owner Owner string `json:"owner" form:"owner"` // Private privacy/visibility setting Private *bool `json:"private" validate:"omitempty" form:"private"` }
CloneModel encapsulates data required to clone a model
type CreateModel ¶
type CreateModel struct { // The name of the Model // required: true Name string `json:"name" validate:"required,min=3,noforwardslash,nopercent" form:"name"` // Optional Owner of the model. Must be a user or an org. // If not set, the current user will be used as owner Owner string `json:"owner" form:"owner"` // Url name URLName string `json:"urlName" validate:"omitempty,base64" form:"urlName"` // License ID // required: true // minimum: 1 License int `json:"license" validate:"required,gte=1" form:"license"` // The associated permissions. 0 for public, 1 for private models. // enum: 0, 1 Permission int `json:"permission" validate:"gte=0,lte=1" form:"permission"` // Optional description Description string `json:"description" form:"description"` // A comma separated list of tags Tags string `json:"tags" validate:"printascii" form:"tags"` // One or more files // required: true File string `json:"file" validate:"omitempty,gt=0" form:"-"` // Optional privacy/visibility setting. Private *bool `json:"private" validate:"omitempty" form:"private"` // Categories // maximum: 2 Categories string `json:"categories" validate:"printascii" form:"categories"` // Metadata associated to this model Metadata *ModelMetadata `json:"metadata" form:"metadata"` }
CreateModel encapsulates data required to create a model
type CreateReport ¶
type CreateReport struct {
Reason string `json:"reason" form:"reason"`
}
CreateReport encapsulates the data required to report a model
type Model ¶
type Model 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_modelname_owner" sql:"index"` // The name of the model Name *string `gorm:"unique_index:idx_modelname_owner" json:"name,omitempty"` // Optional user friendly name to use in URLs URLName *string `json:"url_name,omitempty"` // Unique identifier for the the model UUID *string `json:"-"` // A description of the model (max 65,535 chars) // Interesting post about TEXT vs VARCHAR(30000) performance: // https://nicj.net/mysql-text-vs-varchar-performance/ Description *string `gorm:"type:text" json:"description,omitempty"` // Number of likes Likes int `json:"likes,omitempty"` // Bytes of the model, when downloaded as a zip Filesize int `json:"filesize,omitempty"` // Number of downloads Downloads int `json:"downloads,omitempty"` // Date and time the model was first uploaded UploadDate *time.Time `json:"upload_date,omitempty"` // Date and time the model was modified ModifyDate *time.Time `json:"modify_date,omitempty"` // Tags associated to this model Tags Tags `gorm:"many2many:model_tags;" json:"tags,omitempty"` // Metadata associated to this model Metadata ModelMetadata `json:"metadata,omitempty"` // Location of the model on disk Location *string `json:"-"` // The owner of this model (must exist in UniqueOwners). Can be user or org. Owner *string `gorm:"unique_index:idx_modelname_owner" json:"owner,omitempty"` // The username of the User that created this model (usually got from the JWT) Creator *string `json:"creator,omitempty"` // Permission - 0: public, 1: owner, (future: team, others) Permission int `json:"permission,omitempty"` // The license associated to this model License license.License `json:"license,omitempty"` LicenseID int `json:"lic_id,omitempty"` // Private - True to make this a private resource Private *bool `json:"private,omitempty"` // Categories associated to this model Categories category.Categories `gorm:"many2many:model_categories;" json:"categories,omitempty"` }
Model represents information about a simulation model
A model contains information about a single simulation object, such as a robot, table, or structure.
swagger:model dbModel
func GetModelByName ¶
GetModelByName queries a Model by model name and owner.
func NewModel ¶
func NewModel(uuidStr, name, urlName, desc, location, owner, creator *string, lic license.License, permission int, tags Tags, private bool, categories *category.Categories, metadata *ModelMetadata) (Model, error)
NewModel creates a new Model struct
func NewModelAndUUID ¶
func NewModelAndUUID(name, urlName, desc, location, owner, creator *string, lic license.License, permission int, tags Tags, private bool, categories *category.Categories, metadata *ModelMetadata) (Model, error)
NewModelAndUUID creates a Model struct with a new UUID.
func (*Model) GetLocation ¶
GetLocation returns the model's location on disk
func (*Model) SetLocation ¶
SetLocation sets the location path
type ModelDownload ¶
type ModelDownload struct { gorm.Model // The ID of the user that made the download UserID *uint // The ID of the model that was downloaded ModelID *uint // User-Agent sent in the http request (optional) UserAgent string }
ModelDownload represents a single download of a model.
type ModelLike ¶
type ModelLike struct { // Override default GORM Model fields ID uint `gorm:"primary_key"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // The ID of the user that made the like UserID *uint `gorm:"unique_index:idx_user_model_like"` // The ID of the model that was liked ModelID *uint `gorm:"unique_index:idx_user_model_like"` }
ModelLike represents a like of a model.
type ModelMetadata ¶
type ModelMetadata []ModelMetadatum
ModelMetadata is an array of ModelMetadatum
swagger:model
type ModelMetadatum ¶
type ModelMetadatum struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // ModelID is the ID of the resource to which this metadata is attached. ModelID uint // Pull in the common resources Metadatum. commonres.Metadatum }
ModelMetadatum is here so that world and model metadata are stored in separate tables.
swagger:model
type ModelReport ¶
type ModelReport struct { generics.Report // ModelID represents the model that was reported ModelID *uint `json:"model,omitempty"` }
ModelReport contains information about a model's user report
type Service ¶
type Service struct{}
Service is the main struct exported by this Models Service. It was meant as a way to structure code and help future extensions.
func (*Service) CloneModel ¶
func (ms *Service) CloneModel(ctx context.Context, tx *gorm.DB, smOwner, smName string, cm CloneModel, creator *users.User) (*Model, *ign.ErrMsg)
CloneModel clones a model. creator argument is the active user requesting the operation.
func (*Service) ComputeAllCounters ¶
ComputeAllCounters is an initialization function that iterates all models and updates their likes and downloads counter, based on the number of records in corresponding tables model_likes and model_downloads.
func (*Service) CreateModel ¶
func (ms *Service) CreateModel(ctx context.Context, tx *gorm.DB, cm CreateModel, uuidStr, filesPath string, creator *users.User) (*Model, *ign.ErrMsg)
CreateModel creates a new model. creator argument is the active user requesting the operation.
func (*Service) CreateModelLike ¶
func (ms *Service) CreateModelLike(tx *gorm.DB, owner, modelName string, user *users.User) (*ModelLike, int, *ign.ErrMsg)
CreateModelLike creates a ModelLike. Returns the created modelLike, the current count of likes, or an ign.errMsg.
func (*Service) CreateModelReport ¶
func (ms *Service) CreateModelReport(tx *gorm.DB, owner, modelName, reason string) (*ModelReport, *ign.ErrMsg)
CreateModelReport creates a ModelReport
func (*Service) DownloadZip ¶
func (ms *Service) DownloadZip(ctx context.Context, tx *gorm.DB, owner, modelName, version string, u *users.User, agent string) (*Model, *string, int, *ign.ErrMsg)
DownloadZip returns the path to a zip file representing a model at the given version. This method increments the downloads counter. Optional argument "user" represents the user (if any) requesting the operation. Returns the model, as well as a pointer to the zip's filepath and the resolved version.
func (*Service) GetFile ¶
func (ms *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 model file. Model version is considered. Returns the file's bytes and the resolved version of the model.
func (*Service) GetModel ¶
func (ms *Service) GetModel(tx *gorm.DB, owner, name string, user *users.User) (*Model, *ign.ErrMsg)
GetModel returns a model by its name and owner's name.
func (*Service) GetModelProto ¶
func (ms *Service) GetModelProto(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) (*fuel.Model, *ign.ErrMsg)
GetModelProto returns a model proto struct, given a model name and owner. The user argument is the user requesting the operation.
func (*Service) ModelFileTree ¶
func (ms *Service) ModelFileTree(ctx context.Context, tx *gorm.DB, owner, modelName, version string, user *users.User) (*fuel.FileTree, *ign.ErrMsg)
ModelFileTree gets the model's FileTree
func (*Service) ModelList ¶
func (ms *Service) ModelList(p *ign.PaginationRequest, tx *gorm.DB, owner *string, order, search string, likedBy *users.User, user *users.User, categories *category.Categories) (*fuel.Models, *ign.PaginationResult, *ign.ErrMsg)
ModelList returns a paginated list of models. If the likedBy argument is set, it will return the list of models liked by a user. This function returns a list of fuel.Model that can then be mashalled into json or protobuf. TODO: find a way to MERGE this with the one from Worlds service.
func (*Service) ModelToProto ¶
ModelToProto creates a new 'fuel.Model' from the given model. NOTE: returned "thumbnail urls" are pointing to the "tip" version.
func (*Service) RemoveModel ¶
func (ms *Service) RemoveModel(ctx context.Context, tx *gorm.DB, owner, modelName string, user *users.User) *ign.ErrMsg
RemoveModel removes a model. The user argument is the requesting user. It is used to check if the user can perform the operation.
func (*Service) RemoveModelLike ¶
func (ms *Service) RemoveModelLike(tx *gorm.DB, owner, modelName string, user *users.User) (*ModelLike, int, *ign.ErrMsg)
RemoveModelLike removes a ModelLike. Returns the removed modelLike, the current count of likes, or an ign.errMsg.
func (*Service) UpdateModel ¶
func (ms *Service) UpdateModel(ctx context.Context, tx *gorm.DB, owner, modelName string, desc, tagstr, filesPath *string, private *bool, user *users.User, metadata *ModelMetadata, categories *string) (*Model, *ign.ErrMsg)
UpdateModel updates a model. 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, tags, and the model files. The filesPath argument points to a tmp folder from which to read the model's files. Returns the updated model
type Tag ¶
Tag is a string that can be used to mark other resources, such as models and worlds
swagger:model
type Tags ¶
type Tags []Tag
Tags is an array of Tag
swagger:model
func FindTagsByName ¶
FindTagsByName get a slice of DB Tags by name
type UpdateModel ¶
type UpdateModel struct { // Optional description Description *string `json:"description" form:"description"` // Optional list of tags (comma separated) Tags *string `json:"tags" form:"tags"` // One or more files File string `json:"file" validate:"omitempty,gt=0" form:"-"` // Private privacy/visibility setting Private *bool `json:"private" validate:"omitempty" form:"private"` // Metadata associated to this model Metadata *ModelMetadata `json:"metadata" form:"metadata"` // Optional pair of categories (comma separated) Categories *string `json:"categories" validate:"omitempty" form:"categories"` }
UpdateModel encapsulates data that can be updated in a model
func (UpdateModel) IsEmpty ¶
func (um UpdateModel) IsEmpty() bool
IsEmpty returns true is the struct is empty.