Skip to content

Refactor: Extract business logic from API routes to @/lib directory #359

@Abh1noob

Description

@Abh1noob

Description

Currently, several API route handlers contain business logic that should be extracted to reusable utility functions in the @/lib directory. This will improve code maintainability and reusability.

Files that need refactoring

1. src/app/api/papers/route.ts

Extract to /lib:

  • escapeRegExp utility function (duplicated across files)
  • Paper aggregation logic for extracting unique values: years, slots, exams, campuses, semesters

2. src/app/api/related-subject/route.ts

Extract to /lib:

  • escapeRegExp utility function (duplicate)
  • Subject matching/filtering logic

3. src/app/api/subscribe/route.ts

Extract to /lib:

  • getAuth Google Sheets authentication function
  • appendEmailToSheet Google Sheets API interaction

4. src/app/api/upcoming-papers/route.ts

Extract to /lib:

  • Slot calculation logic (next slot determination)
  • Corresponding slots array generation logic

Benefits

  • Improved code reusability
  • Better separation of concerns
  • Reduced code duplication
  • More maintainable codebase

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions