-
Notifications
You must be signed in to change notification settings - Fork 190
Open
Description
Description
This chore focuses on refactoring the blog service to improve maintainability, reduce redundancy, and ensure consistent response formatting. Key improvements include extracting reusable logic, simplifying search queries, and optimizing how blog data is retrieved and structured.
Motivation
Refactoring is necessary to:
- Reduce duplicate logic when fetching blogs.
- Improve response consistency for single blog and paginated responses.
- Optimize database queries by minimizing redundant user fetch operations.
- Enhance maintainability and readability of the blog service.
Proposed Changes
- Extracted findBlogById() to avoid repetitive blog fetching logic and improve error handling.
- Introduced formatBlogResponse() for consistent single blog response formatting.
- Refactored pagination with formatPaginatedResponse() to remove redundant logic.
- Optimized blog creation & update by ensuring users are only fetched when necessary.
- Simplified search logic with buildWhereClause() for better readability and maintainability.
Expected Outcome
- Code is more modular and easier to maintain.
- Response formatting is standardized across different endpoints.
- Database queries are optimized, reducing unnecessary fetch operations.
- The blog service is easier to extend with future features
Acceptance Criteria
- findBlogById() is used to fetch blog posts instead of inline queries.
- formatBlogResponse() is implemented for single blog responses.
- formatPaginatedResponse() handles pagination across the blog service.
- Blog creation and updates do not fetch the user unnecessarily.
- Searching for blogs uses buildWhereClause() for better structure.
Additional Context
Metadata
Metadata
Assignees
Labels
No labels