Repository navigation
feat(metadata): validated SortOrders constructor, validations & tests - #571
Merged
Merged
Conversation
twuebi
force-pushed
the
tp/sort-orders
branch
from
September 19, 2025 16:22
97f5f0a to
cc64760
Compare
zeroshade
reviewed
Sep 19, 2025
Comment on lines
+178
to
+187
| if len(s.fields) == 0 { | ||
| s.fields = []SortField{} | ||
| s.orderID = 0 | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| if s.orderID == -1 { | ||
| s.orderID = InitialSortOrderID // initialize default sort order id | ||
| } |
Member
There was a problem hiding this comment.
Do we want to have the same error as NewSortOrder if order-id == UnsortedSortOrderID and len(fields) == 0?
Contributor
Author
There was a problem hiding this comment.
The if statement in NewSortOrder has a bug, it should've been if orderID == UnsortedSortOrderID && len(fields) != 0 {, gonna add a test..
|
|
||
| for idx, field := range fields { | ||
| if field.Transform == nil { | ||
| return SortOrder{}, fmt.Errorf("sort field at index %d has no transform", idx) |
Member
There was a problem hiding this comment.
we should have a %w with ErrInvalid or something of that sort
Comment on lines
+204
to
+209
| if field.Direction != SortASC && field.Direction != SortDESC { | ||
| return SortOrder{}, ErrInvalidSortDirection | ||
| } | ||
| if field.NullOrder != NullsFirst && field.NullOrder != NullsLast { | ||
| return SortOrder{}, ErrInvalidNullOrder | ||
| } |
Member
There was a problem hiding this comment.
as with the transform, you should use fmt.Errorf("%w: sort field at index %d", ErrInvalidSortDirection) etc.
zeroshade
reviewed
Sep 22, 2025
| return nil | ||
| } | ||
|
|
||
| func NewSortOrder(orderID int, fields []SortField) (SortOrder, error) { |
zeroshade
approved these changes
Sep 22, 2025
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.
Uh oh!
There was an error while loading. Please reload this page.