Skip to content

feat: add include to get all query#27

Merged
zetsux merged 2 commits intomainfrom
task/add-include-to-get-all-query
Oct 25, 2025
Merged

feat: add include to get all query#27
zetsux merged 2 commits intomainfrom
task/add-include-to-get-all-query

Conversation

@zetsux
Copy link
Owner

@zetsux zetsux commented Oct 25, 2025

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:

  • Added validation and error handling for invalid sort and include parameters, with new error types ErrInvalidSort and ErrInvalidInclude in other.go.
  • Updated PaginationRequest to support an includes parameter for specifying related models to preload.

Generic Query Logic Improvements:

  • Refactored applySorting to return errors for invalid sort columns, and introduced applyIncludes to validate and apply requested includes; both are now used in GetWithPagination, which returns errors if invalid parameters are provided.
  • Updated GetWithPagination signature to accept allowed includes, and updated its usage in the user query logic to use userAllowedSorts and userAllowedIncludes. [1] [2]

Closes #26

Change

Check all options that are relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of my code
  • I have made sure that my fix is effective / my feature works
  • All other features still works locally with my changes
  • I have made API documentation and example response in Postman

@zetsux zetsux requested a review from Copilot October 25, 2025 08:08
@zetsux zetsux self-assigned this Oct 25, 2025
Copy link

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

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 includes query parameter support to PaginationRequest for 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.

@zetsux zetsux force-pushed the task/add-include-to-get-all-query branch from e5c83a6 to f1ea4f4 Compare October 25, 2025 08:11
@zetsux zetsux merged commit 1b78716 into main Oct 25, 2025
1 check passed
@zetsux zetsux deleted the task/add-include-to-get-all-query branch October 25, 2025 08:14
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.

Add include to generic get all query

2 participants