-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(blog):add dynamic sorting, filtering, and pagination to blog retrieval #1198
base: dev
Are you sure you want to change the base?
Conversation
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This category filter is case-sensitive, consider using ilike instead of ==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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_by
parameters are valid columns. The response now includes metadata liketotal_count
to 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