product.go 2.6 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. Subtitle dbr.NullString `db:"subtitle"`
  14. Description dbr.NullString `db:"description"`
  15. Handle dbr.NullString `db:"handle"`
  16. IsGiftcard bool `db:"is_giftcard"`
  17. Thumbnail dbr.NullString `db:"thumbnail"`
  18. ProfileId string `db:"profile_id"`
  19. Weight dbr.NullInt64 `db:"weight"`
  20. Length dbr.NullInt64 `db:"length"`
  21. Height dbr.NullInt64 `db:"height"`
  22. Width dbr.NullInt64 `db:"width"`
  23. HsCode dbr.NullString `db:"hs_code"`
  24. OriginCountry dbr.NullString `db:"origin_country"`
  25. Vendor dbr.NullString `db:"vendor"`
  26. MidCode dbr.NullString `db:"mid_code"`
  27. Material dbr.NullString `db:"material"`
  28. CreatedAt time.Time `db:"created_at"`
  29. UpdatedAt time.Time `db:"updated_at"`
  30. DeletedAt *time.Time `db:"deleted_at"`
  31. CollectionIds []string `db:"collection_ids"`
  32. TypeId dbr.NullString `db:"type_id"`
  33. Discountable bool `db:"discountable"`
  34. Status string `db:"status"`
  35. Tags []string `db:"tags"`
  36. ExternalId dbr.NullString `db:"external_id"`
  37. }
  38. func (p *Product) As() *generated.Product {
  39. description := bluemonday.StrictPolicy().Sanitize(p.Description.String)
  40. return &generated.Product{
  41. AvailableForSale: false,
  42. CompareAtPriceRange: nil,
  43. CreatedAt: scalar.NewDateTimeFrom(p.CreatedAt),
  44. Description: description,
  45. DescriptionHTML: scalar.Html(p.Description.String),
  46. FeaturedImage: nil,
  47. Handle: p.Handle.String,
  48. ID: model.NewId(model.GidProduct, p.Id),
  49. Images: nil,
  50. IsGiftCard: p.IsGiftcard,
  51. Media: nil,
  52. Metafield: nil,
  53. Metafields: nil,
  54. OnlineStoreURL: nil,
  55. PriceRange: nil,
  56. ProductType: p.TypeId.String,
  57. PublishedAt: scalar.NewDateTimeFrom(p.CreatedAt),
  58. RequiresSellingPlan: false,
  59. SellingPlanGroups: nil,
  60. Seo: &generated.Seo{
  61. Description: &description,
  62. Title: &p.Title,
  63. },
  64. Tags: p.Tags,
  65. Title: p.Title,
  66. TotalInventory: nil,
  67. UpdatedAt: scalar.NewDateTimeFrom(p.UpdatedAt),
  68. VariantBySelectedOptions: nil,
  69. Variants: "",
  70. Vendor: p.Vendor.String,
  71. }
  72. }