uwblueprint / somo

Text messaging survey app for Somo
http://www.thesomoproject.org
5 stars 1 forks source link

Refactor survey endpoints to use JSON blob #75

Closed chrisjluc closed 7 years ago

chrisjluc commented 7 years ago

@dinah's post in slack:

/surveys
  POST - create survey object and store entire JSON blob
  PUT - update by overwriting the JSON blob
  SEND - turn JSON blob into models, then trigger send actions

Considerations:
1. Data is not easy to look through in its editing stage. No indexing.
2. Validations. If there is an error in the JSON blob and we don't validate
   until model creation then the user would not be notified until they try to
   send the survey.
3. Editing sent surveys. This setup makes sent surveys immutable objects. Once
   it is sent, the PUT endpoint is essentially useless because the JSON will not
   be serialized into objects again. (Might even make sense to disable PUT since
   we don't want discrepancies between the JSON blob and the associated survey
   objects.) In the human interpretation of what a survey is, does it makes
   sense for sent surveys to be immutable?
4. If we want to allow users to update surveys even after they've been sent, how
   can we support this? Solution: if we hit send again we re-serialize the JSON
   blob (which could have been updated since the last call to /surveys/:id/send)
   to create a new set of models that are distinct from the old models. Notice
   this would mean more than one survey object so there would need to be an
   interface (perhaps another lightweight object) introduced as the two objects
   cannot share the same id. It would be more like versioning of the same survey
   or, a closer model to our existing setup, create from draft.