StackSurveyor / stacksurveyor-backend

The Codebase for StackSurveyor's Backend API
GNU General Public License v3.0
4 stars 1 forks source link

Survey Schema and User relation #2

Open DevHyperCoder opened 3 years ago

DevHyperCoder commented 3 years ago

Survey Schema:

"surveyId":{
    "title": "New Survey",
    "userId":"<user uuid>",
    "participants": ["*"] // read the doc
}

Here, i do not think a one to many (User -> Survey) is necessary, because the most common way someone will access the survey is by using the id. I assume the dashboard (or profile) of the logged in user will be accessed less frequently compared to attending a survey.

We need to create a

So, for the first endpoint, it will be a simple task of searching the db and in the second, we would need to find all surveys where userId=currUser.id

Suggestions please :)

ahnaf-zamil commented 3 years ago

My recommendation is not to create a route called /surveys for all of the logged-in user's surveys. Instead, we can just have a /survey subroute, and just do /survey/@me. This would return all of the surveys created by the logged-in user.

DevHyperCoder commented 3 years ago

oh thats nice ; so we will take in a string, and if its @me, handle all surveys and if its not, parse it into a integer (or UUID) and get the id ?

ahnaf-zamil commented 3 years ago

That's not what I meant. Let me tell you my idea of how the /survey/@me endpoint would work.

  1. Access the logged-in user's object by parsing the authorization JWT and access it's UUID.
  2. Since Cassandra is not relational, we can just write a query like Select * from surveys where user_id=theuserid. This query isn't valid cql, but I hope it explains the stuff.
  3. Then we just make a JSON payload and then send the list of survey objects back to the client.
DevHyperCoder commented 3 years ago

yea i understand that. i was mentioning the parsing because, if we need to get a specifc survey (id = 2) for eg, we would do GET /survey/2 correct ?

ahnaf-zamil commented 3 years ago

For accessing a specific survey, yes. Then we can just get the survey ID and then make a query for that

DevHyperCoder commented 3 years ago

which field in survey should be unique ? survey id will be always unique. what about the title ?

ahnaf-zamil commented 3 years ago

Title doesn't need to be unique. People might have similar titles like "Job Application", or "Discord Mod Application", etc.