Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify report controller parameters #1826

Merged
merged 2 commits into from
Dec 27, 2022

Conversation

mikkamp
Copy link
Contributor

@mikkamp mikkamp commented Dec 21, 2022

Changes proposed in this Pull Request:

Based on the discussion here, this PR cleans up the report controllers to make the code reusable and take advantage of the existing function WP_REST_Request::get_default_params

Detailed test instructions:

Unit testing is still not implemented for the Report Controllers (I started an attempt, but it's going to take a substantial effort to unit test these classes so I left it out for now).

The reports can be tested manually as outlined in PR #251, although this PR doesn't change the report data so we would only want to confirm that the parameter defaults still get mapped in the same way.

The easiest way to test that is to set a break point in prepare_query_arguments and confirm that the arguments are as expected:
image

Note
The DateTime's will vary but it should cover the time range from -7 days to now.

A GET request without query parameters can be sent to https://domain.test/wp-json/wc/gla/ads/reports/programs.

Changelog entry

  • Tweak - Simplify report controller parameters.

@mikkamp mikkamp requested a review from a team December 21, 2022 17:03
@mikkamp mikkamp self-assigned this Dec 21, 2022
@github-actions github-actions bot added the changelog: tweak Small change, that isn't actually very important. label Dec 21, 2022
@@ -39,7 +39,7 @@ public function __construct( ContainerInterface $container ) {
* @return array
*/
public function get_collection_params(): array {
$params = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Shouldn't we call the parent here as well to get context, page, per_page, and search from there?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really can because while we try to reuse as much as possible from the parent controller, we get our data from the Google API instead of from a local DB. Which means some of those query parameters are different.

  • context: we redefine this one, although we don't really use context much internally
  • page: we can't reuse this because the Google API expects a next page token so we can't query a specific page
  • per_page: we redefine this since the Google API sets some different limitations on how many records you can retrieve per request
  • search: for the parent controller this is for searching for posts that match a particular search string (again this isn't really appropriate for our controllers)

Copy link
Member

@tomalec tomalec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the code, smoke tested locally, and checked by fiddling with the debugger.
Left on a note, for a potential improvement #1826 (comment)

@mikkamp mikkamp merged commit 3675176 into develop Dec 27, 2022
@mikkamp mikkamp deleted the tweak/simplify-resport-controller-parameters branch December 27, 2022 14:17
@eason9487 eason9487 mentioned this pull request Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: tweak Small change, that isn't actually very important.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants