After {224505}, we need to setup the following route to receive the post request that is sent.
The post request is sent when clicking on either of the "save" buttons (depicts or captions).
The data sent is a JSON array of contribution objects.
As we currently do, each individual contribution in the array needs to be added to the database on as a new row.
Steps to process data:
- Parse request.data from string back into JSON data
- For each contribution in the array, convert edit_content property back to a string. This contains JSON data (e.g. {item: Q123, isProminent: true} for depict contribution, or {language: "en", value: "Person playing chess"} for a caption contribution
- Add each contribution to the database. All properties should already be present and named as they are in the database, e.g. campaign_id, edit_type, edit_content etc. However, the user_id will need to be added to each contribution by checking the current logged in user
- return success message from post API call. This will be used in the client side to display a "contribution saved message"
Note: Receiving posted data has been tested using the following basic route, but has not been committed to avoid merge conflicts
@campaigns.route('/api/post-contribution', methods=['POST']) def postContribution(): print(request.data, file=sys.stderr) return("Success!")