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

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  )
     8  
     9  // Product missing godoc
    10  type Product struct {
    11  	ID                           string
    12  	OrdID                        string
    13  	ApplicationID                *string
    14  	ApplicationTemplateVersionID *string
    15  	Title                        string
    16  	ShortDescription             string
    17  	Vendor                       string
    18  	Parent                       *string
    19  	CorrelationIDs               json.RawMessage
    20  	Tags                         json.RawMessage
    21  	Labels                       json.RawMessage
    22  	DocumentationLabels          json.RawMessage
    23  }
    24  
    25  // ProductInput missing godoc
    26  type ProductInput struct {
    27  	OrdID               string          `json:"ordId"`
    28  	Title               string          `json:"title"`
    29  	ShortDescription    string          `json:"shortDescription"`
    30  	Vendor              string          `json:"vendor"`
    31  	Parent              *string         `json:"parent"`
    32  	CorrelationIDs      json.RawMessage `json:"correlationIds"`
    33  	Tags                json.RawMessage `json:"tags"`
    34  	Labels              json.RawMessage `json:"labels"`
    35  	DocumentationLabels json.RawMessage `json:"documentationLabels"`
    36  }
    37  
    38  // ToProduct missing godoc
    39  func (i *ProductInput) ToProduct(id string, resourceType resource.Type, resourceID string) *Product {
    40  	if i == nil {
    41  		return nil
    42  	}
    43  
    44  	product := &Product{
    45  		ID:                  id,
    46  		OrdID:               i.OrdID,
    47  		Title:               i.Title,
    48  		ShortDescription:    i.ShortDescription,
    49  		Vendor:              i.Vendor,
    50  		Parent:              i.Parent,
    51  		CorrelationIDs:      i.CorrelationIDs,
    52  		Tags:                i.Tags,
    53  		Labels:              i.Labels,
    54  		DocumentationLabels: i.DocumentationLabels,
    55  	}
    56  
    57  	if resourceType == resource.ApplicationTemplateVersion {
    58  		product.ApplicationTemplateVersionID = &resourceID
    59  	} else if resourceType == resource.Application {
    60  		product.ApplicationID = &resourceID
    61  	}
    62  
    63  	return product
    64  }
    65  
    66  // SetFromUpdateInput missing godoc
    67  func (p *Product) SetFromUpdateInput(update ProductInput) {
    68  	p.Title = update.Title
    69  	p.ShortDescription = update.ShortDescription
    70  	p.Vendor = update.Vendor
    71  	p.Parent = update.Parent
    72  	p.CorrelationIDs = update.CorrelationIDs
    73  	p.Tags = update.Tags
    74  	p.Labels = update.Labels
    75  	p.DocumentationLabels = update.DocumentationLabels
    76  }