package relation import ( "github.com/gshopify/service-wrapper/model" "github.com/gshopify/service-wrapper/scalar" "github.com/mailru/dbr" "github.com/microcosm-cc/bluemonday" "gshopper.com/gshopify/products/graphql/generated" "time" ) type Product struct { Id string `db:"id"` Title string `db:"title"` Description dbr.NullString `db:"description"` Handle dbr.NullString `db:"handle"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` PublishedAt *time.Time `db:"published_at"` DeletedAt *time.Time `db:"deleted_at"` Type dbr.NullString `db:"type"` Scope string `db:"scope"` Status string `db:"status"` Tags []string `db:"tags"` TemplateSuffix dbr.NullString `db:"template_suffix"` Vendor dbr.NullString `db:"vendor"` Collections []string `db:"collections"` Images []string `db:"images"` Options []string `db:"options"` Variants []string `db:"variants"` } func (p *Product) As() *generated.Product { description := bluemonday.StrictPolicy().Sanitize(p.Description.String) product := generated.Product{ AvailableForSale: false, Collections: nil, CompareAtPriceRange: nil, CreatedAt: scalar.NewDateTimeFrom(p.CreatedAt), Description: description, DescriptionHTML: scalar.Html(p.Description.String), FeaturedImage: nil, Handle: p.Handle.String, ID: model.NewId(model.GidProduct, p.Id), Images: nil, IsGiftCard: false, Media: nil, Metafield: nil, Metafields: nil, OnlineStoreURL: nil, Options: nil, PriceRange: nil, ProductType: p.Type.String, PublishedAt: 0, RequiresSellingPlan: false, SellingPlanGroups: nil, Seo: &generated.Seo{ Description: &description, Title: &p.Title, }, Tags: p.Tags, Title: p.Title, TotalInventory: nil, UpdatedAt: scalar.NewDateTimeFrom(p.UpdatedAt), VariantBySelectedOptions: nil, Variants: nil, Vendor: p.Vendor.String, } if p.PublishedAt != nil { product.PublishedAt = scalar.NewDateTimeFrom(*p.PublishedAt) } return &product }