github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/eventdef/entity.go (about) 1 package eventdef 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/domain/version" 9 "github.com/kyma-incubator/compass/components/director/internal/repo" 10 ) 11 12 // Entity is a representation of a single EventDefinition in the database. 13 type Entity struct { 14 ApplicationID sql.NullString `db:"app_id"` 15 ApplicationTemplateVersionID sql.NullString `db:"app_template_version_id"` 16 PackageID sql.NullString `db:"package_id"` 17 Name string `db:"name"` 18 Description sql.NullString `db:"description"` 19 GroupName sql.NullString `db:"group_name"` 20 OrdID sql.NullString `db:"ord_id"` 21 LocalTenantID sql.NullString `db:"local_tenant_id"` 22 ShortDescription sql.NullString `db:"short_description"` 23 SystemInstanceAware sql.NullBool `db:"system_instance_aware"` 24 PolicyLevel sql.NullString `db:"policy_level"` 25 CustomPolicyLevel sql.NullString `db:"custom_policy_level"` 26 ChangeLogEntries sql.NullString `db:"changelog_entries"` 27 Links sql.NullString `db:"links"` 28 Tags sql.NullString `db:"tags"` 29 Countries sql.NullString `db:"countries"` 30 ReleaseStatus sql.NullString `db:"release_status"` 31 SunsetDate sql.NullString `db:"sunset_date"` 32 Successors sql.NullString `db:"successors"` 33 Labels sql.NullString `db:"labels"` 34 Visibility string `db:"visibility"` 35 Disabled sql.NullBool `db:"disabled"` 36 PartOfProducts sql.NullString `db:"part_of_products"` 37 LineOfBusiness sql.NullString `db:"line_of_business"` 38 Industry sql.NullString `db:"industry"` 39 Extensible sql.NullString `db:"extensible"` 40 ResourceHash sql.NullString `db:"resource_hash"` 41 Hierarchy sql.NullString `db:"hierarchy"` 42 DocumentationLabels sql.NullString `db:"documentation_labels"` 43 version.Version 44 45 *repo.BaseEntity 46 } 47 48 // GetParent returns the parent type and the parent ID of the entity. 49 func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) { 50 if e.ApplicationID.Valid { 51 return resource.Application, e.ApplicationID.String 52 } else if e.ApplicationTemplateVersionID.Valid { 53 return resource.ApplicationTemplateVersion, e.ApplicationTemplateVersionID.String 54 } 55 56 return "", "" 57 } 58 59 // DecorateWithTenantID decorates the entity with the given tenant ID. 60 func (e *Entity) DecorateWithTenantID(tenant string) interface{} { 61 return struct { 62 *Entity 63 TenantID string `db:"tenant_id"` 64 }{ 65 Entity: e, 66 TenantID: tenant, 67 } 68 }