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

     1  package ordvendor
     2  
     3  import (
     4  	"database/sql"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  )
     8  
     9  // Entity is the vendor 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  	Partners                     sql.NullString `db:"partners"`
    17  	Tags                         sql.NullString `db:"tags"`
    18  	Labels                       sql.NullString `db:"labels"`
    19  	DocumentationLabels          sql.NullString `db:"documentation_labels"`
    20  }
    21  
    22  // GetID returns the ID
    23  func (e *Entity) GetID() string {
    24  	return e.ID
    25  }
    26  
    27  // GetParent returns the parent type and the parent ID of the entity.
    28  func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) {
    29  	if e.ApplicationID.Valid {
    30  		return resource.Application, e.ApplicationID.String
    31  	} else if e.ApplicationTemplateVersionID.Valid {
    32  		return resource.ApplicationTemplateVersion, e.ApplicationTemplateVersionID.String
    33  	}
    34  
    35  	return "", ""
    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  }