github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/package/entity.go (about)

     1  package ordpackage
     2  
     3  import (
     4  	"database/sql"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  )
     8  
     9  // Entity represents the ORD package entity.
    10  type Entity struct {
    11  	ID                           string         `db:"id"`
    12  	ApplicationID                sql.NullString `db:"app_id"`
    13  	ApplicationTemplateVersionID sql.NullString `db:"app_template_version_id"`
    14  	OrdID                        string         `db:"ord_id"`
    15  	Vendor                       sql.NullString `db:"vendor"`
    16  	Title                        string         `db:"title"`
    17  	ShortDescription             string         `db:"short_description"`
    18  	Description                  string         `db:"description"`
    19  	Version                      string         `db:"version"`
    20  	PackageLinks                 sql.NullString `db:"package_links"`
    21  	Links                        sql.NullString `db:"links"`
    22  	LicenseType                  sql.NullString `db:"licence_type"`
    23  	SupportInfo                  sql.NullString `db:"support_info"`
    24  	Tags                         sql.NullString `db:"tags"`
    25  	Countries                    sql.NullString `db:"countries"`
    26  	Labels                       sql.NullString `db:"labels"`
    27  	PolicyLevel                  string         `db:"policy_level"`
    28  	CustomPolicyLevel            sql.NullString `db:"custom_policy_level"`
    29  	PartOfProducts               sql.NullString `db:"part_of_products"`
    30  	LineOfBusiness               sql.NullString `db:"line_of_business"`
    31  	Industry                     sql.NullString `db:"industry"`
    32  	ResourceHash                 sql.NullString `db:"resource_hash"`
    33  	DocumentationLabels          sql.NullString `db:"documentation_labels"`
    34  }
    35  
    36  // GetID returns the ID of the entity.
    37  func (e *Entity) GetID() string {
    38  	return e.ID
    39  }
    40  
    41  // GetParent returns the parent type and the parent ID of the entity.
    42  func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) {
    43  	if e.ApplicationID.Valid {
    44  		return resource.Application, e.ApplicationID.String
    45  	} else if e.ApplicationTemplateVersionID.Valid {
    46  		return resource.ApplicationTemplateVersion, e.ApplicationTemplateVersionID.String
    47  	}
    48  
    49  	return "", ""
    50  }
    51  
    52  // DecorateWithTenantID decorates the entity with the given tenant ID.
    53  func (e *Entity) DecorateWithTenantID(tenant string) interface{} {
    54  	return struct {
    55  		*Entity
    56  		TenantID string `db:"tenant_id"`
    57  	}{
    58  		Entity:   e,
    59  		TenantID: tenant,
    60  	}
    61  }