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"` } func (p *Product) As() *generated.Product { description := bluemonday.StrictPolicy().Sanitize(p.Description.String) product := generated.Product{ AvailableForSale: false, CompareAtPriceRange: nil, FeaturedImage: nil, Images: nil, IsGiftCard: false, Media: nil, OnlineStoreURL: nil, PriceRange: nil, RequiresSellingPlan: false, SellingPlanGroups: nil, TotalInventory: nil, VariantBySelectedOptions: nil, ID: model.NewId(model.GidProduct, p.Id), Handle: p.Handle.String, Title: p.Title, Vendor: p.Vendor.String, Description: description, DescriptionHTML: scalar.Html(p.Description.String), ProductType: p.Type.String, Tags: p.Tags, Seo: &generated.Seo{ Description: &description, Title: &p.Title, }, CreatedAt: scalar.NewDateTimeFrom(p.CreatedAt), UpdatedAt: scalar.NewDateTimeFrom(p.UpdatedAt), } if p.PublishedAt != nil { product.PublishedAt = scalar.NewDateTimeFrom(*p.PublishedAt) } return &product }