Skip to content

Factor out backend/routes/tmdb.ts: extract buildListEndpoint helper #137

@arediss

Description

@arediss

Context

packages/backend/src/routes/tmdb.ts = 443 lines, 21 handlers. 13 handlers follow the exact same copy-paste pattern:

getLang(request) → TMDB service → flagNsfwFromDb → return { results, nsfwTmdbIds }

Clone handlers:

  • /trending (l.121)
  • /movies/popular (l.132)
  • /tv/popular (l.143)
  • /movies/upcoming (l.165)
  • /tv/trending-anime (l.154)
  • /tv/top_rated (l.198)
  • /tv/airing_today (l.209)
  • /tv/on_the_air (l.220)
  • /search (l.231)
  • /movie/:id/recommendations (l.288)
  • /tv/:id/recommendations (l.301)
  • /discover/mixed (l.379)
  • /discover/:mediaType/genre/:genreId (l.324)

Scope

  • Extract a buildListEndpoint(service, options?) helper to factor out the 13 handlers
  • Group by subdomain: tmdb/list.ts, tmdb/details.ts, tmdb/discover.ts, tmdb/genres.ts
  • Add unit tests on the extracted helper (NSFW filtering, language, pagination)

Success criteria

  • tmdb.ts reduced to pure orchestration (< 150 lines)
  • Adding a new list endpoint = 1 helper call

Parent: #145

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend, database, APIs, integrationsquick-winSmall effort, high impact — can be done in a single sessionrefactor

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions