collection.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Collection struct {
  11. Id string `db:"id"`
  12. Title string `db:"title"`
  13. Description string `db:"description"`
  14. Handle dbr.NullString `db:"handle"`
  15. Thumbnail dbr.NullString `db:"thumbnail"`
  16. CreatedAt time.Time `db:"created_at"`
  17. UpdatedAt time.Time `db:"updated_at"`
  18. DeletedAt *time.Time `db:"deleted_at"`
  19. }
  20. func (c *Collection) As() *generated.Collection {
  21. description := bluemonday.StrictPolicy().Sanitize(c.Description)
  22. return &generated.Collection{
  23. Description: description,
  24. DescriptionHTML: scalar.Html(c.Description),
  25. Handle: c.Handle.String,
  26. ID: model.NewId(model.GidCollection, c.Id),
  27. Image: nil, //TODO:
  28. Metafield: nil,
  29. Metafields: nil,
  30. OnlineStoreURL: nil, //TODO:
  31. Seo: &generated.Seo{
  32. Description: &description,
  33. Title: &c.Title,
  34. },
  35. Title: c.Title,
  36. UpdatedAt: scalar.NewDateTimeFrom(c.UpdatedAt),
  37. }
  38. }