Fix for broken commands - #56
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.