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

     1  package product
     2  
     3  import (
     4  	"database/sql"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  )
     8  
     9  // Entity represents a product entity.
    10  type Entity struct {
    11  	ID                           string         `db:"id"`
    12  	OrdID                        string         `db:"ord_id"`
    13  	ApplicationID                sql.NullString `db:"app_id"`
    14  	ApplicationTemplateVersionID sql.NullString `db:"app_template_version_id"`
    15  	Title                        string         `db:"title"`
    16  	ShortDescription             string         `db:"short_description"`
    17  	Vendor                       string         `db:"vendor"`
    18  	Parent                       sql.NullString `db:"parent"`
    19  	CorrelationIDs               sql.NullString `db:"correlation_ids"`
    20  	Tags                         sql.NullString `db:"tags"`
    21  	Labels                       sql.NullString `db:"labels"`
    22  	DocumentationLabels          sql.NullString `db:"documentation_labels"`
    23  }
    24  
    25  // GetID returns the product ID.
    26  func (e *Entity) GetID() string {
    27  	return e.ID
    28  }
    29  
    30  // GetParent returns the parent type and the parent ID of the entity.
    31  func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) {
    32  	if e.ApplicationID.Valid {
    33  		return resource.Application, e.ApplicationID.String
    34  	} else if e.ApplicationTemplateVersionID.Valid {
    35  		return resource.ApplicationTemplateVersion, e.ApplicationTemplateVersionID.String
    36  	}
    37  
    38  	return "", ""
    39  }
    40  
    41  // DecorateWithTenantID decorates the entity with the given tenant ID.
    42  func (e *Entity) DecorateWithTenantID(tenant string) interface{} {
    43  	return struct {
    44  		*Entity
    45  		TenantID string `db:"tenant_id"`
    46  	}{
    47  		Entity:   e,
    48  		TenantID: tenant,
    49  	}
    50  }