ssciwr / mondey

In development
https://mondey.lkeegan.dev
GNU Affero General Public License v3.0
0 stars 1 forks source link

add UserAnswer model and endpoints #123

Closed lkeegan closed 1 month ago

lkeegan commented 1 month ago

The questions that the user should answer about themselves are modelled in the database by UserQuestion:

https://github.com/ssciwr/mondey/blob/2daf2483221204a7d0c82fb0bd905846b5d5868e/mondey_backend/src/mondey_backend/models/questions.py#L30-L40

There is an endpoint to retrieve the list of questions here:

https://github.com/ssciwr/mondey/blob/2daf2483221204a7d0c82fb0bd905846b5d5868e/mondey_backend/src/mondey_backend/routers/questions.py#L15-L22

We need to add a UserAnswer model to store the answer by a particular user for a particular question, e.g. something like

UserAnswer

And we need endpoints to retrieve the current set of answers, and to upload the new set of answers. I'd suggest adding these to the user router: https://github.com/ssciwr/mondey/blob/main/mondey_backend/src/mondey_backend/routers/users.py

We don't need full CRUD endpoints for these, just a get that returns the list of current answers for the user (if any), e.g.

@router.get("/user-answers/", response_model=list[UserAnswerPublic])
    def get_current_user_answers(session: SessionDep, current_active_user: CurrentActiveUserDep):
        ....

and a put that replaces the existing answers with new ones, e.g.

@router.put("/user-answers/")
    def update_current_user_answers(session: SessionDep, current_active_user: CurrentActiveUserDep, answers: list[UserAnswerPublic]):
        ....