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

Add an endpoint for get pickersets #1381

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

70ray
Copy link
Collaborator

@70ray 70ray commented Dec 1, 2024

We could avoid the expand_pickersets() function by creating the pickersets with character names to start with but then we would have to change some other stuff to use the data in this form.

Sandbox at: https://www.pgdp.org/~rp31/c.branch/api_pickers

api/v1_projects.inc Outdated Show resolved Hide resolved
api/v1_projects.inc Outdated Show resolved Hide resolved
pinc/CharSuites.inc Outdated Show resolved Hide resolved
Copy link
Member

@cpeel cpeel left a comment

Choose a reason for hiding this comment

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

Having this in the PickerSet class makes a lot more sense, thanks for moving it in there.

api/v1_projects.inc Outdated Show resolved Hide resolved
api/v1_projects.inc Outdated Show resolved Hide resolved
@70ray
Copy link
Collaborator Author

70ray commented Dec 7, 2024

Sandbox updated.

Copy link
Member

@cpeel cpeel left a comment

Choose a reason for hiding this comment

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

Brilliant.

For other reviewers, this can be tested with:

export API_KEY=review
curl -i -H "Accept: application/json" -H "X-API-KEY: $API_KEY" \
     -X GET "https://www.pgdp.org/~rp31/c.branch/api_pickers/api/v1/projects/projectID45b5cfaa0ff81/pickersets"

@srjfoo
Copy link
Member

srjfoo commented Dec 7, 2024

Brilliant.

For other reviewers, this can be tested with:

export API_KEY=review
curl -i -H "Accept: application/json" -H "X-API-KEY: $API_KEY" \
     -X GET "https://www.pgdp.org/~rp31/c.branch/api_pickers/api/v1/projects/projectID45b5cfaa0ff81/pickersets"

Thanks, Casey, that helps immensely.

@70ray, in looking at the output, the thing that stood out to me is that the numbers don't show the actual character. They're also bracketed by square brackets instead of curly, as with the others. I have a memory of you fixing something similar to that in the code -- is that what's going on here? (see screenshot below of picker set labeled 1.)

image

@cpeel
Copy link
Member

cpeel commented Dec 8, 2024

@70ray, in looking at the output, the thing that stood out to me is that the numbers don't show the actual character. They're also bracketed by square brackets instead of curly, as with the others. I have a memory of you fixing something similar to that in the code -- is that what's going on here? (see screenshot below of picker set labeled 1.)

Oh, very good catch Sharon! We need to massage those into a string type instead of an int type. I forget exactly how we do that but you are correct we do that elsewhere.

@70ray
Copy link
Collaborator Author

70ray commented Dec 8, 2024

@70ray, in looking at the output, the thing that stood out to me is that the numbers don't show the actual character. They're also bracketed by square brackets instead of curly, as with the others. I have a memory of you fixing something similar to that in the code -- is that what's going on here? (see screenshot below of picker set labeled 1.)

Oh, very good catch Sharon! We need to massage those into a string type instead of an int type. I forget exactly how we do that but you are correct we do that elsewhere.

An easy work-around would be to return pairs [character, name] rather than an assciative array. This would be just as easy for the client to use. So the result would be:
image
It is possible to use JSON_FORCE_OBJECT with json_encode() but this would make it encode all arrays as objects which we don't want.

@cpeel
Copy link
Member

cpeel commented Dec 8, 2024

An easy work-around would be to return pairs [character, name] rather than an assciative array. This would be just as easy for the client to use.

We could, but we're doing something to coerce some array key numbers into strings already if you look at the very top of Sharon's screenshot:
image

What are we doing that coerces the 1?

@70ray
Copy link
Collaborator Author

70ray commented Dec 8, 2024

An easy work-around would be to return pairs [character, name] rather than an assciative array. This would be just as easy for the client to use.

We could, but we're doing something to coerce some array key numbers into strings already if you look at the very top of Sharon's screenshot: image

What are we doing that coerces the 1?

It seems that "1" is because the keys are a mixture of numbers and other characters, but if you use consecutive numbers starting from 0 it gets turned into an ordinary array. But we can coerce it into an object with (object).

@70ray
Copy link
Collaborator Author

70ray commented Dec 8, 2024

But it seems an object is not the same sort of thing as an associative array.

@70ray
Copy link
Collaborator Author

70ray commented Dec 8, 2024

Test has been adjusted so it works with an object. Is this a good solution or would returning the [char, name] pairs be better? I like the pairs better.

@70ray
Copy link
Collaborator Author

70ray commented Dec 8, 2024

Sandbox updated.

@cpeel
Copy link
Member

cpeel commented Dec 8, 2024

Is this a good solution or would returning the [char, name] pairs be better? I like the pairs better.

I think this solution works well. I'm partial to the hash as I think it lets clients easily get the keys via built-in functions. I'm not against the pairs though if you'd rather do that -- both seem acceptable to me. Whichever you prefer is fine.

@70ray
Copy link
Collaborator Author

70ray commented Dec 9, 2024

I looked at how this appears when it gets to the javascript. Unfortunately the "1: numbers and math" key appears as an integer so the subsets get in the wrong order. mdn says:
"Within each component of the prototype chain, all non-negative integer keys (those that can be array indices) will be traversed first in ascending order by value, then other string keys in ascending chronological order of property creation."
I think the best solution would be to treat the components that we want to keep in the right order as simple arrays. I'll made it like this.

@70ray
Copy link
Collaborator Author

70ray commented Dec 9, 2024

Github doesn't seem to be running the checks

@70ray
Copy link
Collaborator Author

70ray commented Dec 10, 2024

Conflicts resolved, snadbox updated.

Copy link
Member

@cpeel cpeel left a comment

Choose a reason for hiding this comment

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

This LGTM!

@cpeel cpeel added the ready-for-merge PR is ready for merging after freeze/slush label Dec 11, 2024
@cpeel cpeel merged commit 6e3e761 into DistributedProofreaders:master Dec 11, 2024
12 checks passed
@70ray 70ray deleted the api_pickers branch December 12, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge PR is ready for merging after freeze/slush
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants