I'm currently developing a web application with a backend in Python using FastAPI, and I'll be deploying it to AWS Lambda and using AWS DynamoDB as the database. The frontend will be built using ReactJS in the future. I need help implementing a functionality where certain endpoints can only be accessed conditionally, based on a previous call.
Detailed Requirements
- A user can navigate to a specific
question
. - The user can call the
get_explanation
endpoint for this specific question. - Once the user receives the explanation, they can enter a follow-up question in a text input box.
- This input text will be sent to a
follow_up_question
endpoint, where the user can ask a follow-up question about the explanation. - After the user gets a response to the follow-up question, the input text box should become unusable. The user can only ask one follow-up question after getting the explanation.
My Questions
- What are the most efficient ways of designing the backend so that the
follow_up_question
endpoint can only be called if theget_explanation
endpoint has already been called for the same question item? - How can I ensure that once the
follow_up_question
endpoint has been called for that question, it can't be called again? - How should I handle this logic on the frontend using ReactJS to ensure a smooth user experience?
- Some of you may suggest using the database to track state, but is this really the most efficient way?