Skip to content

Allow single sorting property in sortBy method of database endpoint #93

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

Merged
merged 10 commits into from
Dec 19, 2022

Conversation

mechelon
Copy link
Member

@mechelon mechelon commented Dec 7, 2022

❗ This PR removes support for PHP 7.4 and changes the test engine to PEST.

The sortBy method of the database endpoint now also takes a single Sorting property instead of a Collection, for example:

$sortings = new Collection();

$birthYearFilter = Sorting::propertySort("Birth year", "ascending");

# Sort the entries by birth year first, after that by creation timestamp
$sortings->add($birthYearFilter);
$sortings->add(Sorting::timestampSort("created_time", "ascending"));

return Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
    ->sortBy($sortings)
# ->sortBy($birthYearFilter) // both sortBy variations work!
    ->query()
    ->asCollection()
    ->each(function ($entry) {
        echo $entry->getTitle() . PHP_EOL;
    });

The sortBy method now also uses union types for the parameter which drops PHP 7.4 support (EOL is reached! 🦕).

The sortBy method of the Search endpoint was dropped because it's not allowed anyway to use custom sortings here (see https://developers.notion.com/reference/post-search#errors).

@mechelon mechelon added help wanted Extra attention is needed WTD Triggering whatthediff.ai labels Dec 7, 2022
@what-the-diff
Copy link

what-the-diff bot commented Dec 7, 2022

  • Update composer.json to require PHP 8
  • Add Pest as test runner and remove phpunit
  • Fix sorting in Database endpoint by allowing a single Sorting instance or Collection of Sortings instead of only Collections (which is not possible with the Notion API)
  • Remove sortBy() method from Search endpoint, because it's already available on the parent class EndpointDatabase which all endpoints extend from anyway
  • Improve documentation for buildRequestHeader() method in Notion class due to inconsistency between required version date format vs v* notation used in URL path parameter

@mechelon mechelon changed the title [Draft] Allow single sorting property in sortBy method of database endpoint Allow single sorting property in sortBy method of database endpoint Dec 7, 2022
@mechelon mechelon requested a review from johguentner December 7, 2022 10:35
@mechelon mechelon removed the help wanted Extra attention is needed label Dec 7, 2022
@5am-code 5am-code deleted a comment from what-the-diff bot Dec 7, 2022
Copy link
Member

@johguentner johguentner left a comment

Choose a reason for hiding this comment

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

LGTM! 😎

@mechelon mechelon merged commit 2f75bbd into dev Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WTD Triggering whatthediff.ai
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants