Skip to content

Change product quantity to be a string#18

Closed
LightJack05 wants to merge 2 commits intomainfrom
product-quantity
Closed

Change product quantity to be a string#18
LightJack05 wants to merge 2 commits intomainfrom
product-quantity

Conversation

@LightJack05
Copy link
Member

  • apparently a quantity can be a string and therefore should be deserialized as such

@LightJack05 LightJack05 self-assigned this Jan 27, 2026
Copilot AI review requested due to automatic review settings January 27, 2026 08:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Product data model to treat product_quantity as a string instead of a number, based on upstream data sometimes representing quantity as text.

Changes:

  • Changed Product.ProductQuantity type from float64 to string for JSON/BSON decoding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

FoodGroupsTags []interface{} `json:"food_groups_tags" bson:"food_groups_tags,truncate"`
States string `json:"states" bson:"states"`
ProductQuantity float64 `json:"product_quantity" bson:"product_quantity,truncate"`
ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"`
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing ProductQuantity from float64 to string will likely break BSON decoding from MongoDB when existing documents store product_quantity as a numeric type (and vice versa if some docs store it as a string). The Go MongoDB driver cannot decode a BSON double/int directly into a Go string, so FindOne().Decode()/cursor.All() can start failing at runtime for mixed-type data. Consider introducing a dedicated type for this field that implements BSON unmarshalling (and JSON unmarshalling if needed) to accept both string and numeric representations and normalize to a string, rather than switching the struct field to plain string.

Copilot uses AI. Check for mistakes.
FoodGroupsTags []interface{} `json:"food_groups_tags" bson:"food_groups_tags,truncate"`
States string `json:"states" bson:"states"`
ProductQuantity float64 `json:"product_quantity" bson:"product_quantity,truncate"`
ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"`
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bson:"product_quantity,truncate" was previously meaningful for a numeric type; on a string field it’s inconsistent with the rest of this struct (no other string fields use truncate) and can be misleading. Recommend dropping the truncate option if the field remains non-numeric, or keeping the field numeric internally and converting at the API boundary.

Suggested change
ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"`
ProductQuantity string `json:"product_quantity" bson:"product_quantity"`

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant