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 custom endpoint for GET posts #109

Merged
merged 15 commits into from
Sep 5, 2023

Conversation

sidemt
Copy link
Member

@sidemt sidemt commented Aug 23, 2023

Checklist:

Partially implements #94

This PR adds the following 3 endpoints replicating the current API:

  • GET /content/posts/
  • GET /content/posts/{id}/
  • GET /content/posts/slug/{slug}/

Each endpoint accepts query parameter include=authors,tags to include author and tags in the response.

@sidemt sidemt changed the title Feat/custom endpoint Add custom endpoint for GET posts Aug 23, 2023
@sidemt sidemt marked this pull request as ready for review August 23, 2023 13:47
@sidemt sidemt requested a review from a team as a code owner August 23, 2023 13:47
Copy link
Member

@raisedadead raisedadead left a comment

Choose a reason for hiding this comment

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

@yoko consider adding unit tests. That way we can mock the shape of the response and make sure these endpoints respect the shape that is expected (that is content is similar to the current content API)

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
sqlite3 5.1.6 network, shell +56 8.14 MB daniellockyer
supertest 6.3.3 network +8 788 kB titanism

@sidemt
Copy link
Member Author

sidemt commented Aug 30, 2023

@raisedadead I tried adding tests according this document: https://docs.strapi.io/dev-docs/testing#set-up-a-testing-environment

However, the test environment uses sqlite3 for database and I've been unable to find the way to use postgres instead. Also, I can't find how I can integrate this test setup with our Docker setup. (I'm not even sure if we need to do so.)

Could you take a look at the current code and see if I'm going the right path?

With the current code, I can run the test from the console like this:
image

Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a comment

Choose a reason for hiding this comment

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

Hey Yoko, I just noticed a few code style things that could be improved:

publish-backend/tests/app.test.js Outdated Show resolved Hide resolved
publish-backend/tests/helpers/strapi.js Outdated Show resolved Hide resolved
@raisedadead
Copy link
Member

...the test environment uses sqlite3 for database and I've been unable to find the way to use postgres instead.

That is perfectly fine, as none of our code is Postres-specific. We are good here because we will do everything using Strapi's backend.

@sidemt
Copy link
Member Author

sidemt commented Aug 30, 2023

Thank you for your review, @ojeytonwilliams @raisedadead

I have applied Oliver's suggestions and added one more test case to check the behavior of the include query parameter.

@sidemt
Copy link
Member Author

sidemt commented Sep 5, 2023

Getting this change in for now. If there are any issues, I'll work on them in a separate PR. Thanks.

@sidemt sidemt merged commit faee716 into freeCodeCamp:main Sep 5, 2023
2 checks passed
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