Assuming you have the following model for a user.
data class User(
val id: UUID = UUID.randomUUID(),
val name: String,
val username: String,
val password: String
)
And you want to insert it into the database, relating the payload to a logged in tenant account. You can do it by mapping the request into a RPC Style payload.
@RequestAware
data class InsertUserReq(
@Path val tenantId: UUID,
@Body val user: User
)
@Singleton class App {
val tenantUsers = mutableMapOf<UUID, MutableList<User>>()
@deploy
fun setup(router: SimplifiedRouter){
router.post('/users', ::insertUser)
}
fun insertUser(req: InsertUserReq) {
val users = tenantUsers.computeIfAbsent(req.tenantId) { mutableListOf() }
users.add(req.user)
}
}