2
0

product_collection.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package relation
  2. import (
  3. "github.com/gshopify/service-wrapper/model"
  4. "github.com/gshopify/service-wrapper/scalar"
  5. "github.com/mailru/dbr"
  6. "github.com/microcosm-cc/bluemonday"
  7. "gshopper.com/gshopify/products/graphql/generated"
  8. "time"
  9. )
  10. type ProductCollection struct {
  11. Id string `db:"id"`
  12. Title string `db:"title"`
  13. Description string `db:"description"`
  14. Handle dbr.NullString `db:"handle"`
  15. Scope string `db:"scope"`
  16. SortOrder string `db:"sort_order"`
  17. Image dbr.NullString `db:"image"`
  18. TemplateSuffix dbr.NullString `db:"template_suffix"`
  19. CreatedAt time.Time `db:"created_at"`
  20. UpdatedAt time.Time `db:"updated_at"`
  21. PublishedAt *time.Time `db:"published_at"`
  22. DeletedAt *time.Time `db:"deleted_at"`
  23. }
  24. func (c *ProductCollection) As() *generated.Collection {
  25. description := bluemonday.StrictPolicy().Sanitize(c.Description)
  26. return &generated.Collection{
  27. Description: description,
  28. DescriptionHTML: scalar.Html(c.Description),
  29. Handle: c.Handle.String,
  30. ID: model.NewId(model.GidCollection, c.Id),
  31. Image: nil, //TODO:
  32. OnlineStoreURL: nil, //TODO:
  33. Seo: &generated.Seo{
  34. Description: &description,
  35. Title: &c.Title,
  36. },
  37. Title: c.Title,
  38. UpdatedAt: scalar.NewDateTimeFrom(c.UpdatedAt),
  39. }
  40. }