Enhance Money.Scan to support JSON input#158
Open
atakanozceviz wants to merge 1 commit intoRhymond:masterfrom
Open
Enhance Money.Scan to support JSON input#158atakanozceviz wants to merge 1 commit intoRhymond:masterfrom
atakanozceviz wants to merge 1 commit intoRhymond:masterfrom
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: