Getting a poll

Let's write a function to fetch the poll details by poll ID. It's another simple query that returns the Poll object along with its result.

The heart of the function is as follows:

return if (pollRecord != null) {    val poll = Poll(pollRecord.pollId, pollRecord.pollTitle, pollRecord.pollQuestion)    val respondentDetails = RespondentDetails(respondentDisplayName = respondentRecord.respondentDisplayName,            respondentEmail = respondentRecord.respondentEmailId)    val stateOne = PollResponseStatistics("NO", 10)    val stateTwo = PollResponseStatistics("YES", 90)    val pollDetailsResponse = PollDetailsResponse(poll, respondentDetails, listOf(stateOne, stateTwo))    ApiGatewayResponse.builder().setStatusCode(200).setObjectBody(pollDetailsResponse) ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.