github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/webhook/entity.go (about) 1 package webhook 2 3 import ( 4 "database/sql" 5 "time" 6 7 "github.com/kyma-incubator/compass/components/director/pkg/resource" 8 ) 9 10 // Entity is a webhook entity. 11 type Entity struct { 12 ID string `db:"id"` 13 ApplicationID sql.NullString `db:"app_id"` 14 ApplicationTemplateID sql.NullString `db:"app_template_id"` 15 RuntimeID sql.NullString `db:"runtime_id"` 16 IntegrationSystemID sql.NullString `db:"integration_system_id"` 17 FormationTemplateID sql.NullString `db:"formation_template_id"` 18 CollectionIDKey sql.NullString `db:"correlation_id_key"` 19 Type string `db:"type"` 20 Mode sql.NullString `db:"mode"` 21 URL sql.NullString `db:"url"` 22 Auth sql.NullString `db:"auth"` 23 RetryInterval sql.NullInt32 `db:"retry_interval"` 24 Timeout sql.NullInt32 `db:"timeout"` 25 URLTemplate sql.NullString `db:"url_template"` 26 InputTemplate sql.NullString `db:"input_template"` 27 HeaderTemplate sql.NullString `db:"header_template"` 28 OutputTemplate sql.NullString `db:"output_template"` 29 StatusTemplate sql.NullString `db:"status_template"` 30 CreatedAt *time.Time `db:"created_at"` 31 } 32 33 // GetID returns the ID of the entity. 34 func (e *Entity) GetID() string { 35 return e.ID 36 } 37 38 // GetParent returns the parent type and the parent ID of the entity. 39 func (e *Entity) GetParent(_ resource.Type) (resource.Type, string) { 40 if e.RuntimeID.Valid { 41 return resource.Runtime, e.RuntimeID.String 42 } else if e.ApplicationID.Valid { 43 return resource.Application, e.ApplicationID.String 44 } else if e.FormationTemplateID.Valid { 45 return resource.FormationTemplate, e.FormationTemplateID.String 46 } 47 return "", "" 48 } 49 50 // Collection is a collection of webhook entities. 51 type Collection []Entity 52 53 // Len returns the number of entities in the collection. 54 func (c Collection) Len() int { 55 return len(c) 56 } 57 58 // DecorateWithTenantID decorates the entity with the given tenant ID. 59 func (e *Entity) DecorateWithTenantID(tenant string) interface{} { 60 return struct { 61 *Entity 62 TenantID string `db:"tenant_id"` 63 }{ 64 Entity: e, 65 TenantID: tenant, 66 } 67 }