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

     1  package fetchrequest
     2  
     3  import (
     4  	"database/sql"
     5  	"time"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     8  )
     9  
    10  // Entity represents a fetch request.
    11  type Entity struct {
    12  	ID              string         `db:"id"`
    13  	URL             string         `db:"url"`
    14  	SpecID          sql.NullString `db:"spec_id"`
    15  	DocumentID      sql.NullString `db:"document_id"`
    16  	Mode            string         `db:"mode"`
    17  	Auth            sql.NullString `db:"auth"`
    18  	Filter          sql.NullString `db:"filter"`
    19  	StatusCondition string         `db:"status_condition"`
    20  	StatusMessage   sql.NullString `db:"status_message"`
    21  	StatusTimestamp time.Time      `db:"status_timestamp"`
    22  }
    23  
    24  // GetID returns the ID of the fetch request.
    25  func (e *Entity) GetID() string {
    26  	return e.ID
    27  }
    28  
    29  // GetParent returns the parent type and the parent ID of the entity.
    30  func (e *Entity) GetParent(currentResourceType resource.Type) (resource.Type, string) {
    31  	if e.SpecID.Valid {
    32  		if currentResourceType == resource.APISpecFetchRequest {
    33  			return resource.APISpecification, e.SpecID.String
    34  		} else {
    35  			return resource.EventSpecification, e.SpecID.String
    36  		}
    37  	}
    38  	return resource.Document, e.DocumentID.String
    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  }