Skip to content
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

[CHORE]refactor(blog-service): extract helper methods for reusability and consistency #1359

Open
5 tasks
olugbenga1 opened this issue Mar 2, 2025 · 0 comments

Comments

@olugbenga1
Copy link
Contributor

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

@olugbenga1 olugbenga1 changed the title [CHORE] [CHORE]refactor(blog-service): extract helper methods for reusability and consistency Mar 2, 2025
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

No branches or pull requests

1 participant