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 read endpoints #11

Merged
merged 6 commits into from
Sep 24, 2024
Merged

Conversation

feliciagan
Copy link

  • implement endpoint to read questions for question list (with filter and search functionality).
  • implement endpoint to read question using specific question id.

-implement endpoint to read questions for question list (with filter and search functionality)
-implement endpoint to read question using specific question id
@@ -10,4 +12,8 @@ router.post("/questions", createQuestion);

router.put("/questions/:id", updateQuestion);

router.post("/questionsquery/:currPage", readQuestionsList);

Choose a reason for hiding this comment

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

should it be a GET request? since we are reading and not creating questions

Copy link
Author

Choose a reason for hiding this comment

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

hmm will get be enough for sending the conditions to search and filter by

Copy link
Author

Choose a reason for hiding this comment

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

like if the search string is very long and the person filter by many conditions

Choose a reason for hiding this comment

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

oh i think the length of the query shouldnt affect anything? the conditions can be specified as a list i think

Copy link
Author

Choose a reason for hiding this comment

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

doesnt the url hv a length limit though?

Copy link

Choose a reason for hiding this comment

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

Ohh I think I get your concern, I was searching up on this and some do suggest using POST instead of GET to handle the case of queries with long params (not sure if it's good practice though)

I feel like it's quite unlikely to hit the URL length limit (around 2k characters?) But if we really want to be safe, alternatively we can either

  • restrict the length of query params in the frontend (eg. character limit on the search keyword)
  • do error handling in the backend (catch 414 and have the frontend display something similar to page not found)

Copy link
Author

Choose a reason for hiding this comment

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

hmm alright i'll change to GET, then it might be better to restrict search character limit + filter categories in the frontend? (i'll still catch 414 just in case but i think just catch 414 only is abit late, like we let the user query with so many conditions already then we tell them that we can't search with that many.)
is that ok?

Copy link
Author

Choose a reason for hiding this comment

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

wait is it possible for you to check if the url too long on the front end instead

Copy link

Choose a reason for hiding this comment

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

I think yes but hmm what do we show the user if the url is too long? I think like what you mentioned it's better not to let the user submit a very long query then only inform them that it's too long right

I can do the character restrictions for the search and filter parameters in the frontend if that helps~

Copy link
Author

Choose a reason for hiding this comment

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

yea i think if we can guarantee that url will never be too long with restrictions we can forgo the url too long check? otherwise we probably have to put error message like "too many keywords pls try with less" cuz if we just return server error they might try the same thing again.

- changed getting the question list from using POST request to using GET request
- allow frontend to specify question limit per page through request query
try {
const { page, qnLimit, title, complexities, categories } = req.query;

if (!page || !qnLimit) {

Choose a reason for hiding this comment

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

should we set a default if the user doesn't specify? maybe fetch the first page containing 10 questions

Copy link
Author

Choose a reason for hiding this comment

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

would it be better for the frontend to handle the error message returned and resend the correct request instead? cuz if not then the user click to go to pg 11 then they go back to pg 1 also a bit weird. also on that note im not sure if this error will actually happen cuz the frontend shld always be sending it correctly?

Copy link
Author

Choose a reason for hiding this comment

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

@ruiqi7 what do u think? since u doing the frontend

Copy link

@ruiqi7 ruiqi7 Sep 23, 2024

Choose a reason for hiding this comment

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

I think yes, the frontend will be sending it properly

- add endpoint for reading unique question categories for frontend filter component
- update api documentation
- return total number of questions instead of pages
@ruiqi7 ruiqi7 merged commit d798d3e into CS3219-AY2425S1:development Sep 24, 2024
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