2
0

product.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Product struct {
  11. Id string `db:"id"`
  12. Title string `db:"title"`
  13. Description dbr.NullString `db:"description"`
  14. Handle dbr.NullString `db:"handle"`
  15. CreatedAt time.Time `db:"created_at"`
  16. UpdatedAt time.Time `db:"updated_at"`
  17. PublishedAt *time.Time `db:"published_at"`
  18. DeletedAt *time.Time `db:"deleted_at"`
  19. Type dbr.NullString `db:"type"`
  20. Scope string `db:"scope"`
  21. Status string `db:"status"`
  22. Tags []string `db:"tags"`
  23. TemplateSuffix dbr.NullString `db:"template_suffix"`
  24. Vendor dbr.NullString `db:"vendor"`
  25. Collections []string `db:"collections"`
  26. Images []string `db:"images"`
  27. Options []string `db:"options"`
  28. Variants []string `db:"variants"`
  29. }
  30. func (p *Product) As() *generated.Product {
  31. description := bluemonday.StrictPolicy().Sanitize(p.Description.String)
  32. product := generated.Product{
  33. AvailableForSale: false,
  34. Collections: nil,
  35. CompareAtPriceRange: nil,
  36. CreatedAt: scalar.NewDateTimeFrom(p.CreatedAt),
  37. Description: description,
  38. DescriptionHTML: scalar.Html(p.Description.String),
  39. FeaturedImage: nil,
  40. Handle: p.Handle.String,
  41. ID: model.NewId(model.GidProduct, p.Id),
  42. Images: nil,
  43. IsGiftCard: false,
  44. Media: nil,
  45. Metafield: nil,
  46. Metafields: nil,
  47. OnlineStoreURL: nil,
  48. Options: nil,
  49. PriceRange: nil,
  50. ProductType: p.Type.String,
  51. PublishedAt: 0,
  52. RequiresSellingPlan: false,
  53. SellingPlanGroups: nil,
  54. Seo: &generated.Seo{
  55. Description: &description,
  56. Title: &p.Title,
  57. },
  58. Tags: p.Tags,
  59. Title: p.Title,
  60. TotalInventory: nil,
  61. UpdatedAt: scalar.NewDateTimeFrom(p.UpdatedAt),
  62. VariantBySelectedOptions: nil,
  63. Variants: nil,
  64. Vendor: p.Vendor.String,
  65. }
  66. if p.PublishedAt != nil {
  67. product.PublishedAt = scalar.NewDateTimeFrom(*p.PublishedAt)
  68. }
  69. return &product
  70. }