feat(blog):add dynamic sorting, filtering, and pagination to blog retrieval#1198
Open
Karadumk wants to merge 5 commits intohngprojects:devfrom
Open
feat(blog):add dynamic sorting, filtering, and pagination to blog retrieval#1198Karadumk wants to merge 5 commits intohngprojects:devfrom
Karadumk wants to merge 5 commits intohngprojects:devfrom
Conversation
samuelogboye
requested changes
Mar 1, 2025
api/v1/services/blog.py
Outdated
| if author_id: | ||
| query = query.filter(Blog.author_id == author_id) | ||
| if category: | ||
| query = query.filter(Blog.category == category) |
Contributor
There was a problem hiding this comment.
This category filter is case-sensitive, consider using ilike instead of ==
Author
There was a problem hiding this comment.
I've updated the category filter to use ilike instead of ==, making it case-insensitive. Now, searches will match categories regardless of letter case.
api/v1/services/blog.py
Outdated
|
|
||
| blogs = self.db.query(Blog).filter(Blog.is_deleted == False).all() | ||
| return blogs | ||
| return blogs |
Contributor
There was a problem hiding this comment.
When implementing pagination, it's often useful to return the total count of records (before applying limit and offset) so that clients can calculate the total number of pages.
Author
There was a problem hiding this comment.
I added total count to the response to support frontend pagination as suggested. Now the response includes both blogs and total_count.
…t invalid sorting
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 PR introduces dynamic sorting, filtering, and pagination for the blog retrieval endpoint. Users can now specify sorting fields, filter by relevant attributes, and paginate results efficiently. Additionally, validation has been added to ensure that
sort_byparameters are valid columns. The response now includes metadata liketotal_countto improve frontend pagination.Motivation and Context
This change enhances the flexibility of blog retrieval, making it easier for users to query and navigate blog posts effectively. It also prevents invalid sorting parameters and improves API usability for frontend developers.
How Has This Been Tested?
Types of Changes
Checklist