Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request adds support for dynamically including related models in paginated queries and improves validation of query parameters. The changes introduce a new includes parameter to the pagination request structure and add validation for both sorting and include parameters with proper error handling.
Key Changes:
- Added
includesquery parameter support toPaginationRequestfor specifying related models to preload - Introduced validation and error handling for invalid sort and include parameters with new error types
- Refactored query functions to return errors for invalid parameters instead of silently falling back to defaults
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| support/base/request.go | Added Includes field to PaginationRequest struct to accept comma-separated list of relations |
| infrastructure/query/user.go | Renamed allowedSorts to userAllowedSorts, added userAllowedIncludes array, and updated GetWithPagination call to pass allowed includes |
| infrastructure/query/generic.go | Refactored applySorting and added applyIncludes functions to validate and apply parameters with error returns; updated GetWithPagination signature |
| core/helper/errors/other.go | Added ErrInvalidSort and ErrInvalidInclude error variables for validation failures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e5c83a6 to
f1ea4f4
Compare
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.
Description
This pull request enhances the query and pagination infrastructure by introducing support for dynamic includes and improving error handling for sorting and including related data. The changes make it easier to validate and extend query parameters, ensuring only allowed fields are used for sorting and including related models.
Query Parameter Validation and Support:
ErrInvalidSortandErrInvalidIncludeinother.go.PaginationRequestto support anincludesparameter for specifying related models to preload.Generic Query Logic Improvements:
applySortingto return errors for invalid sort columns, and introducedapplyIncludesto validate and apply requested includes; both are now used inGetWithPagination, which returns errors if invalid parameters are provided.GetWithPaginationsignature to accept allowed includes, and updated its usage in the user query logic to useuserAllowedSortsanduserAllowedIncludes. [1] [2]Closes #26
Change
Check all options that are relevant.
Checklist