- 
                Notifications
    
You must be signed in to change notification settings  - Fork 162
 
Enhance Money.Scan to support JSON input #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
          
Reviewer's GuideThis PR extends the Money.Scan method to parse JSON representations of Money (both string and []byte), refactors type-switch handling for cleaner assertions and error messages, and augments unit tests with JSON scenarios and improved comparison logic. Sequence diagram for Money.Scan with JSON inputsequenceDiagram
    participant DB as Database
    participant Money as Money
    participant JSON as UnmarshalJSON
    DB->>Money: Scan(src interface{})
    alt src is string and starts with '{'
        Money->>JSON: UnmarshalJSON(m, []byte(src))
    else src is []byte
        Money->>JSON: UnmarshalJSON(m, src)
    else src is string (legacy)
        Money->>Money: Parse amount and currency
    else
        Money->>Money: Return error
    end
    File-Level Changes
 Tips and commandsInteracting with Sourcery
 Customizing Your ExperienceAccess your dashboard to: 
 Getting Help
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @atakanozceviz - I've reviewed your changes - here's some feedback:
- Consider trimming leading whitespace from src before checking for '{' to avoid misclassifying JSON strings with leading spaces.
 - Wrap or annotate errors returned from UnmarshalJSON so that JSON scanning failures include more context about the input causing the issue.
 - Update the default Scan error messages to reflect JSON support (instead of always mentioning the DBMoneyValueSeparator) to avoid confusing errors for JSON inputs.
 
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider trimming leading whitespace from src before checking for '{' to avoid misclassifying JSON strings with leading spaces.
- Wrap or annotate errors returned from UnmarshalJSON so that JSON scanning failures include more context about the input causing the issue.
- Update the default Scan error messages to reflect JSON support (instead of always mentioning the DBMoneyValueSeparator) to avoid confusing errors for JSON inputs.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Enhance Money.Scan to accept and unmarshal JSON payloads, streamline type assertions and error messages, and extend tests to cover the new JSON behavior.
New Features:
Enhancements:
Tests: