Once we have the request model and the function for generating a random ID, we will create a new object that we will store in the database. The code for that will look like this:
exports.createPoll = functions.https.onRequest { req, res -> val reqBody = req.rawBody val poll = JSON.parse<RequestPoll>(reqBody) val newPoll = ResponsePoll(getRandomPollId().toString(), poll.pollQuestion, poll.pollOptions)}
The final onRequest function will look like this:
exports.createPoll = functions.https.onRequest { req, res -> val reqBody = req.rawBody val poll = JSON.parse<RequestPoll>(reqBody) val newPoll = ResponsePoll(getRandomPollId().toString(), poll.pollQuestion, poll.pollOptions) res.status(200).send(JSON.stringify(newPoll)) ...