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

     1  package api
     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 API 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  	Group                                   sql.NullString `db:"group_name"`
    20  	TargetURLs                              sql.NullString `db:"target_urls"`
    21  	OrdID                                   sql.NullString `db:"ord_id"`
    22  	LocalTenantID                           sql.NullString `db:"local_tenant_id"`
    23  	ShortDescription                        sql.NullString `db:"short_description"`
    24  	SystemInstanceAware                     sql.NullBool   `db:"system_instance_aware"`
    25  	PolicyLevel                             sql.NullString `db:"policy_level"`
    26  	CustomPolicyLevel                       sql.NullString `db:"custom_policy_level"`
    27  	APIProtocol                             sql.NullString `db:"api_protocol"`
    28  	Tags                                    sql.NullString `db:"tags"`
    29  	Countries                               sql.NullString `db:"countries"`
    30  	Links                                   sql.NullString `db:"links"`
    31  	APIResourceLinks                        sql.NullString `db:"api_resource_links"`
    32  	ReleaseStatus                           sql.NullString `db:"release_status"`
    33  	SunsetDate                              sql.NullString `db:"sunset_date"`
    34  	Successors                              sql.NullString `db:"successors"`
    35  	ChangeLogEntries                        sql.NullString `db:"changelog_entries"`
    36  	Labels                                  sql.NullString `db:"labels"`
    37  	Visibility                              string         `db:"visibility"`
    38  	Disabled                                sql.NullBool   `db:"disabled"`
    39  	PartOfProducts                          sql.NullString `db:"part_of_products"`
    40  	LineOfBusiness                          sql.NullString `db:"line_of_business"`
    41  	Industry                                sql.NullString `db:"industry"`
    42  	ImplementationStandard                  sql.NullString `db:"implementation_standard"`
    43  	CustomImplementationStandard            sql.NullString `db:"custom_implementation_standard"`
    44  	CustomImplementationStandardDescription sql.NullString `db:"custom_implementation_standard_description"`
    45  	Extensible                              sql.NullString `db:"extensible"`
    46  	ResourceHash                            sql.NullString `db:"resource_hash"`
    47  	Hierarchy                               sql.NullString `db:"hierarchy"`
    48  	SupportedUseCases                       sql.NullString `db:"supported_use_cases"`
    49  	DocumentationLabels                     sql.NullString `db:"documentation_labels"`
    50  
    51  	*repo.BaseEntity
    52  	version.Version
    53  }
    54  
    55  // GetParent returns the parent type and the parent ID of the entity.
    56  func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) {
    57  	if e.ApplicationID.Valid {
    58  		return resource.Application, e.ApplicationID.String
    59  	} else if e.ApplicationTemplateVersionID.Valid {
    60  		return resource.ApplicationTemplateVersion, e.ApplicationTemplateVersionID.String
    61  	}
    62  
    63  	return "", ""
    64  }
    65  
    66  // DecorateWithTenantID decorates the entity with the given tenant ID.
    67  func (e *Entity) DecorateWithTenantID(tenant string) interface{} {
    68  	return struct {
    69  		*Entity
    70  		TenantID string `db:"tenant_id"`
    71  	}{
    72  		Entity:   e,
    73  		TenantID: tenant,
    74  	}
    75  }