Skip to content

Fix for broken commands - #56

Merged
Sharkwald merged 12 commits into
mainfrom
fix-for-broken-commands
Mar 18, 2026
Merged

Fix for broken commands#56
Sharkwald merged 12 commits into
mainfrom
fix-for-broken-commands

Conversation

@Sharkwald

Copy link
Copy Markdown
Owner

No description provided.

Sharkwald and others added 12 commits March 18, 2026 11:03
The project has 'Custom Search API' enabled in GCP but not 'Custom Search
JSON API', which is what the NuGet library (Google.Apis.CustomSearchAPI.v1)
requires, causing HTTP 403 errors at runtime.

Replace the NuGet library with direct HttpClient calls to the Custom Search
API REST endpoint, following the same IHttpClientFactory + System.Text.Json
pattern used by other commands (Giphy, Wikipedia, etc.).

Changes:
- Remove Google.Apis.CustomSearchAPI.v1 package reference
- Rewrite GoogleSearchCommand: inject IHttpClientFactory, build URL manually,
  parse JSON response with System.Text.Json, extract error.message on failure
- Rewrite GoogleImageSearchCommand: same approach, add &searchType=image,
  add IHttpClientFactory constructor param and try-catch error handling
- Remove FakeGoogleHttpClientFactory from TestHelpers (no longer needed)
- Update GoogleSearchCommandTests to use TestHelpers.CreateHttpClientFactory
- Expand GoogleImageSearchCommandTests with result/no-result/error cases
- Update handler tests to supply IHttpClientFactory mock arg
- Update integration test factory method to use DefaultHttpClientFactory

All 210 unit tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace nullable GoogleSearchResult? return type with GoogleCommandResult
discriminated union, matching the pattern used by GoogleSearchCommand.

- GoogleImageSearchCommand.ExecuteAsync now returns Task<GoogleCommandResult>
  returning EmptySearchTermErrorResult, NoResultsFoundResult, GoogleApiErrorResult,
  or GoogleSearchResult as appropriate
- GoogleImageHandler updated to use the same switch expression pattern
- GoogleImageHandlerTests updated: null-based setups replaced with typed results,
  NullResult test renamed to NoResultsFound
- GoogleImageSearchCommandTests updated to assert typed result records

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract shared logic into GoogleCommandBase and move all Google-related
types into a Bottomly/Commands/Google/ subfolder.

New structure:
- GoogleCommandResult.cs  — discriminated union result types
- GoogleCommandBase.cs    — shared HTTP call, JSON parsing, error handling
- GoogleSearchCommand.cs  — sets ExtraQueryParams to null (text search)
- GoogleImageSearchCommand.cs — sets ExtraQueryParams to &searchType=image

GoogleCommandBase accepts an optional ILogger? so GoogleSearchCommand can
pass its typed logger while GoogleImageSearchCommand needs none.

Old GoogleSearchCommand.cs and GoogleImageSearchCommand.cs deleted.
Handlers and test files updated to use Bottomly.Commands.Google namespace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replaces abstract string? with virtual string returning string.Empty,
so the property can never be null. GoogleSearchCommand drops the
redundant override; GoogleImageSearchCommand keeps its override.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sharkwald
Sharkwald merged commit 1aab991 into main Mar 18, 2026
1 check passed
@Sharkwald
Sharkwald deleted the fix-for-broken-commands branch March 18, 2026 15:56
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.

1 participant