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

     1  package spec
     2  
     3  import (
     4  	"database/sql"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  )
     8  
     9  // Entity represents a specification entity.
    10  type Entity struct {
    11  	ID            string         `db:"id"`
    12  	APIDefID      sql.NullString `db:"api_def_id"`
    13  	EventAPIDefID sql.NullString `db:"event_def_id"`
    14  	SpecData      sql.NullString `db:"spec_data"`
    15  
    16  	APISpecFormat sql.NullString `db:"api_spec_format"`
    17  	APISpecType   sql.NullString `db:"api_spec_type"`
    18  
    19  	EventSpecFormat sql.NullString `db:"event_spec_format"`
    20  	EventSpecType   sql.NullString `db:"event_spec_type"`
    21  
    22  	CustomType sql.NullString `db:"custom_type"`
    23  }
    24  
    25  // GetID returns the ID of the entity.
    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.APIDefID.Valid {
    33  		return resource.API, e.APIDefID.String
    34  	}
    35  	return resource.EventDefinition, e.EventAPIDefID.String
    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  }