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 ProductCollection struct { Id string `db:"id"` Title string `db:"title"` Description string `db:"description"` Handle dbr.NullString `db:"handle"` Scope string `db:"scope"` SortOrder string `db:"sort_order"` Image dbr.NullString `db:"image"` TemplateSuffix dbr.NullString `db:"template_suffix"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` PublishedAt *time.Time `db:"published_at"` DeletedAt *time.Time `db:"deleted_at"` } func (c *ProductCollection) As() *generated.Collection { var ( description = bluemonday.StrictPolicy().Sanitize(c.Description) collection = &generated.Collection{ Description: description, DescriptionHTML: scalar.Html(c.Description), Handle: c.Handle.String, ID: model.NewId(model.GidCollection, c.Id), Image: nil, //TODO: OnlineStoreURL: nil, //TODO: Seo: &generated.Seo{ Description: &description, Title: &c.Title, }, Title: c.Title, UpdatedAt: scalar.NewDateTimeFrom(c.UpdatedAt), } ) if order := generated.CollectionSortOrder(c.SortOrder); order.IsValid() { collection.Metafields = append(collection.Metafields, &generated.Metafield{ Namespace: model.GidCollection.String(), Key: "sort_order", Type: model.MetaFieldTypeSingleLineTextField.String(), Value: order.String(), }) } if scope := model.PublishScope(c.Scope); scope.IsValid() { collection.Metafields = append(collection.Metafields, &generated.Metafield{ Namespace: model.GidCollection.String(), Key: "scope", Type: model.MetaFieldTypeSingleLineTextField.String(), Value: scope.String(), }) } return collection }