Skip to content

feat: Use search endpoint for finals filtering instead of text search #282

@tsurbs

Description

@tsurbs

Summary

This is a pull request for branch finals-use-search-endpoint.

This PR refactors the finals search functionality to use the existing /courses/search backend endpoint instead of client-side text filtering on the finals.json data.

Changes

New File: apps/frontend/src/app/api/finals.ts

  • Added useFetchFinalsSearch hook that calls the /courses/search endpoint with keywords
  • Returns a list of matching courseIDs from the backend's full-text search

Updated: apps/frontend/src/components/finals/FinalsViewer.tsx

  • Imports the new useFetchFinalsSearch hook
  • Uses React Query to fetch search results when user types in the search box
  • Filters the finals.json data based on matching courseIDs from the search API
  • Standardizes course IDs (e.g., 48321A -> 48-321) for proper matching
  • Maintains backward compatibility with the "own courses" filtering feature

Why?

Previously, the finals search was using client-side text filtering on the course code field in finals.json. This was limited because:

  1. It only searched the course code, not the course name or description
  2. Users couldn't find courses by course name (e.g., "Calculus" wouldn't find 21-120)

Now, the search uses the backend's full-text search which indexes:

  • Course names
  • Course descriptions
  • Course IDs

This provides a much better search experience while still maintaining the local finals data for fast filtering of results.

Testing

  • Type checking passes (no new TypeScript errors)
  • The logic properly handles:
    • No search query (shows all finals)
    • Search with results (filters finals by matching courseIDs)
    • Search with no results (shows empty state)
    • Own courses filtering combined with search

Branch: finals-use-search-endpoint
Create PR at: https://github.com/ScottyLabs/cmucourses/pull/new/finals-use-search-endpoint

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions