Creating a poll

Let's now save all the poll-related information.

We will read the entire raw JSON body and map it to the PollCreationRequest class. 

jOOQ's TransactionalRunnable is a functional interface that has the Single Abstract Method (SAM) as its run function:

 void run(Configuration configuration) throws Exception;

This makes TransactionalRunnable  written in the lambda style.

We verify whether the user is a valid user with a jOOQ transaction:

it.transaction { configuration ->    val respondentRecord = DSL.using(configuration)            .fetchOne(Respondent.RESPONDENT,                    Respondent.RESPONDENT.RESPONDENT_ID.eq(pollToCreate.createdBy))}

Note that respondentRecord is non-null. And this ensures it's a valid ID.

Rest is a simple db transaction that dumps ...

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.