github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/document/entity.go (about) 1 package document 2 3 import ( 4 "database/sql" 5 6 "github.com/kyma-incubator/compass/components/director/pkg/resource" 7 8 "github.com/kyma-incubator/compass/components/director/internal/repo" 9 ) 10 11 // Entity is a representation of a document entity in the database. 12 type Entity struct { 13 BndlID string `db:"bundle_id"` 14 AppID sql.NullString `db:"app_id"` 15 ApplicationTemplateVersionID sql.NullString `db:"app_template_version_id"` 16 Title string `db:"title"` 17 DisplayName string `db:"display_name"` 18 Description string `db:"description"` 19 Format string `db:"format"` 20 Kind sql.NullString `db:"kind"` 21 Data sql.NullString `db:"data"` 22 *repo.BaseEntity 23 } 24 25 // GetParent returns the parent type and the parent ID of the entity. 26 func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) { 27 return resource.Bundle, e.BndlID 28 } 29 30 // Collection is a collection of entities. 31 type Collection []Entity 32 33 // Len returns the length of the collection. 34 func (r Collection) Len() int { 35 return len(r) 36 } 37 38 // DecorateWithTenantID decorates the entity with the given tenant ID. 39 func (e *Entity) DecorateWithTenantID(tenant string) interface{} { 40 return struct { 41 *Entity 42 TenantID string `db:"tenant_id"` 43 }{ 44 Entity: e, 45 TenantID: tenant, 46 } 47 }