feat: add relation manipulation to api, and update get routes to return relations as well#802
Merged
Conversation
…rocessedpubschema for all pub operations
…ssedPub, to match what is returned by getPubWithChildren etc
…orrect query parameters to get pub endpoints
THis way you won't have to generate the token yourself everytime
allisonking
reviewed
Nov 25, 2024
| query: getPubQuerySchema.extend({ | ||
| pubTypeId: pubTypesIdSchema.optional().describe("Filter by pub type ID."), | ||
| stageId: stagesIdSchema.optional().describe("Filter by stage ID."), | ||
| limit: z.number().default(10).optional(), |
Contributor
There was a problem hiding this comment.
Hmm I get different results for
curl 'http://localhost:3000/api/v0/c/arcadia-research/site/pubs' --header 'Authorization: Bearer xxxxxxxxxxxxxxxx.00000000-0000-0000-0000-000000000000' | jq 'length'
18
curl 'http://localhost:3000/api/v0/c/arcadia-research/site/pubs?limit=10' --header 'Authorization: Bearer xxxxxxxxxxxxxxxx.00000000-0000-0000-0000-000000000000' | jq 'length'
10
Contributor
There was a problem hiding this comment.
I think limit can't be optional if we want the default to kick in (same for offset, I suppose, but that probably matters less since undefined also is 0)
allisonking
reviewed
Nov 25, 2024
Contributor
allisonking
left a comment
There was a problem hiding this comment.
went through the very thorough testing instructions (thanks for writing all those curl commands out!!!) and everything worked as expected! except for the limit thing, but other than that I think it looks 💯
* fix: ___________ INIT for easy cherry picking later because i somehow still don't know how to rebase * feat: add capabilities based auth to site api * chore: change some error codes to be more accurate
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.
Issue(s) Resolved
Resolves #738. I discussed this with @allisonking, as she probably did not have enough time to get to it this sprint, and it would be a small thing to add for me.
Resolves #739
High-level Explanation of PR
This PR adds endpoints for
updatePubatPATCH /pubs/<pubId>removePubatDELETE /pubs/<pubId>upsertPubRelationsatPATCH /pubs/<pubId>/relationsreplacePubRelationsatPUT /pubs/<pubId>/relationsremovePubRelationsandremoveAllPubRelationsBySlugsatDELETE /pubs/<pubId>/relationsIt also updates the old
GET /pubsandGET /pubs/<pubId>endpoints to use the newgetPubsWithchildrenAndRelationsfunction, and to accept more query parameters.Additionally, it:
Preferheader on update endpoints. SettingPrefer: return=minimalwill not return anything forPUT/PATCH/POSTroutes. This makes the request somewhat faster and saves bandwith. (i just learned about this and thought it would be neat to implement, can be removed)I also fixed/changed some things for
getPubsWithRelationsAndChildren:withChildrenandwithRelatedPubsnow work properly (they were inversed, iewithRelatedPubs: falsewould disable fetching of children, and vice versa)Misc:
createPubRecursiveNewto matchgetPubsWithChildrenAndRelatedPubs.Test Plan
This will not be fun, apologies. For now I think it's most important that fetching pubs works, and updating them and their relations. Whether super specific query parameters work as intended is less important (@isTravis please feel free to disagree!).
pnpm reset. thenpnpm dev. You can now usexxxxxxxxxxxxxxxx.00000000-0000-0000-0000-000000000000as a token forarcadia-research| jqat the end to get a nicer view of the result (dobrew install jqif you don't have it yet))You could then find the journal article pub like
Finally, get the journal article pub.
Check that only one pub is returned, dand that is has a lot of children and relations.
It should have some eg a tag
a. First find the Tag pubtypes id. you can do that like this with
jqcurl \ --url http://localhost:3000/api/v0/c/arcadia-research/site/pub-types \ --header 'Authorization: Bearer xxxxxxxxxxxxxxxx.00000000-0000-0000-0000-0000000 00000' \ | jq '.[] | select(.name == "Tag") | .id'b. Then, using the id of the journal article pub above, try to create a new related pub. (technically you can do this for any pub ofc)
Then, check the number of tags returned through the api (we don't have a way to view relationships in the ui yet)
You shuold see at least two tags! Go to the
/pubspage, you should see twoTagpubs.--request PUTinstead. This will replace all the tags instead (it won't delete the tags though, just their relations to this pub)if you now
GETthe pub again, you shuold see there's only one tag!curl --request DELETE \ --url http://localhost:3000/api/v0/c/arcadia-research/site/pubs/d460d438-4ed4-49ca-aea9-9bf2c52ef0ec/relations \ --header 'Authorization: Bearer xxxxxxxxxxxxxxxx.00000000-0000-0000-0000-000000000000' \ --header 'Prefer: return=representation' #this makes sure we get a full thing returned \ --header 'user-agent: Keyrunner' \ --data '{ "arcadia-research:tag": "*" }' | jqin the return value you should not be able to see any
arcadia-research:tagvalues anymore.Screenshots (if applicable)
Notes