Skip to content

refactor(seerrclient): isolate generated API quirks behind an internal client layer#90

Merged
electather merged 5 commits intomainfrom
refactor/internal-seerr-client
Mar 16, 2026
Merged

refactor(seerrclient): isolate generated API quirks behind an internal client layer#90
electather merged 5 commits intomainfrom
refactor/internal-seerr-client

Conversation

@electather
Copy link
Owner

Summary

Closes #84

Introduces internal/seerrclient — a concrete Client type that wraps the auto-generated pkg/api client and hides three categories of generated-code quirks so that feature code never has to deal with them directly:

  1. float32 IDs — the generated client uses float32 for all numeric IDs (movie IDs, page numbers). Wrapper methods (MovieGet, MovieRecommendations, etc.) accept int and convert internally.
  2. Union-type unmarshal bugSearchMulti and all Discover methods use RawGet to bypass the generated client's broken deserialisation where TV results become PersonResult.
  3. URL encoding — Seerr requires %20 for spaces, not +. An encodingRoundTripper on every Client handles this for generated-client calls; RawGet already handles it for raw requests.
  4. Trending defaultsDiscoverTrending strips mediaType=all and timeWindow=day before sending, since some server versions reject them with HTTP 400.

Changes

  • internal/seerrclient/client.goClient struct, New(), NewWithKey(), RawGet(), Unwrap(), encodingRoundTripper
  • internal/seerrclient/search.goSearchMulti, DiscoverMovies, DiscoverTV, DiscoverTrending (with default-stripping)
  • internal/seerrclient/movies.goMovieGet, MovieRecommendations, MovieSimilar, MovieRatings, MovieRatingsCombined
  • cmd/search/search.go — deleted encodingRoundTripper and newAPIClient(); subcommands now use seerrclient.New()
  • cmd/search/{multi,movies,tv,trending,company,keyword}.go — migrated to seerrclient
  • cmd/movies/{get,recommendations,similar,ratings,ratings_combined}.go — migrated to seerrclient
  • cmd/mcp/tools_search.go — replaced apiutil.RawGet calls with seerrclient methods
  • cmd/mcp/tools_movies.go — replaced float32 casts with seerrclient movie methods
  • tests/seerrclient_test.go — 5 new tests (TDD)

Test plan

  • go test -v ./... passes
  • go fmt ./... produces no diff
  • go build succeeds

Tests written before implementation (TDD):

go test -v ./tests/ -run TestClient
  • TestClientRawGetSpaceEncoding — spaces encoded as %20 not +
  • TestClientSearchMultiPreservesAllMediaTypes — movie + tv + person all returned
  • TestClientDiscoverTrendingStripsDefaultParamsmediaType=all and timeWindow=day stripped
  • TestClientDiscoverTrendingPassesThroughExplicitParams — explicit page=2 passes through
  • TestClientMovieGetPassesIntID — int ID 550 reaches path /api/v1/movie/550

Checklist

  • New tests added for new behaviour
  • Documentation updated (README, command --help, comments)
  • No unrelated changes included

- Add genre, studio/network, language, sortBy, date range, vote average,
  and runtime filters to search_discover_movies and search_discover_tv
- Fix report_issue prompt to remove non-existent mediaType arg on issue_create
- Fix issue_create tool description to list all 5 issue types correctly
- Add search_company and search_keyword tools
- Add movies_ratings_combined tool
- Add settings_jobs_cancel and settings_jobs_schedule tools
- Remove orphaned WatchProviders resource handlers that were never registered
- Add inventory.go with MCPToolCount/MCPResourceCount/MCPPromptCount constants
- Update serve.go log lines to use inventory constants instead of stale literals
- Update README tool count (43 -> 52) and add missing tools and resources table
…I quirks

Introduce internal/seerrclient with a concrete Client type that wraps the
auto-generated pkg/api client and hides three generated-code quirks:

- float32 IDs: MovieGet/Recommendations/Similar/Ratings methods accept int
  and convert internally so callers never see float32 casts.
- Union-type unmarshal bug: SearchMulti and Discover* use RawGet to bypass
  the generated client, which deserialises TV results as PersonResult.
- URL encoding: an encodingRoundTripper on the client replaces + with %20
  for generated-client calls (company/keyword queries); RawGet already
  handles this for raw requests.
- Trending defaults: DiscoverTrending strips mediaType=all and
  timeWindow=day before sending to avoid HTTP 400 on some server versions.

Migrate cmd/search, cmd/movies, and cmd/mcp to use the new client.
Delete the now-redundant encodingRoundTripper and newAPIClient from
cmd/search/search.go.

Add tests/seerrclient_test.go covering all five new behaviours (TDD).
@electather electather merged commit 6214682 into main Mar 16, 2026
2 checks passed
@electather electather deleted the refactor/internal-seerr-client branch March 16, 2026 18:54
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

Successfully merging this pull request may close these issues.

refactor: phase 2 roadmap — isolate generated API quirks behind an internal Seerr client layer

1 participant