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

feat(api): Add sortOrder to API_GetComments #3156

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ioslife
Copy link
Contributor

@ioslife ioslife commented Jan 30, 2025

Alter the GetComments endpoint from #2552 to add a sortOrder query param

  • API_GetComments - returns the comments associated to a game or achievement
  • i : game or achievement id
  • u : username
  • t : 1 = game, 2 = achievement, 3 = user
  • o : offset - number of entries to skip (default: 0)
  • c : count - number of entries to return (default: 100, max: 500)
  • s : sortOrder - sort comments. 0 = ascending, 1 = descending (default: 0)
  • int Count number of comment records returned in the response
  • int Total number of comment records the game/achievement/user actually has overall
  • array Results
  • object [value]
  • int User username of the commenter
  • string Submitted date time the comment was submitted
  • string CommentText text of the comment
    */

@ioslife
Copy link
Contributor Author

ioslife commented Jan 30, 2025

FYI – I am open to a different query letter here

@@ -15,6 +15,7 @@
* t : 1 = game, 2 = achievement, 3 = user
* o : offset - number of entries to skip (default: 0)
* c : count - number of entries to return (default: 100, max: 500)
* s : sortOrder - sort comments. 0 = ascending, 1 = descending (default: 0)
Copy link
Member

Choose a reason for hiding this comment

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

This could be too ambiguous in terms of what the orderBy() is. I'm also thinking integers as possible values may be inflexible if this pattern is extended to other API endpoints.

I think we may want to change this to use JSON:API-like enum values, ie: createdAt and -createdAt.

Copy link
Member

Choose a reason for hiding this comment

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

We do have a few public APIs where filter parameters are effectively booleans (0=all,1=filtered), and some that are direct mapping of enums (3=core,5=unofficial).

But as this is not an enum, and it's not being implemented as a boolean (s: sort descending (0=no,1=yes)), I agree that it makes sense to have it be more free-form.

@@ -15,6 +15,7 @@
* t : 1 = game, 2 = achievement, 3 = user
* o : offset - number of entries to skip (default: 0)
* c : count - number of entries to return (default: 100, max: 500)
* s : sortOrder - sort comments. 0 = ascending, 1 = descending (default: 0)
Copy link
Member

Choose a reason for hiding this comment

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

We do have a few public APIs where filter parameters are effectively booleans (0=all,1=filtered), and some that are direct mapping of enums (3=core,5=unofficial).

But as this is not an enum, and it's not being implemented as a boolean (s: sort descending (0=no,1=yes)), I agree that it makes sense to have it be more free-form.


if ($sortOrder == 1) {
$commentsQuery->orderBy('Submitted', 'DESC');
}
Copy link
Member

Choose a reason for hiding this comment

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

You'll probably want an explicit orderBy for ascending to. It's unsafe to assume that an unordered query returns sorted data.

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.

3 participants