I am looking for a function that manages programmatically the parameters in a GET, to create DB queries dynamically.
At the moment, i have the following:
route("/sCap"){
val dao: DAOFacade = DAOFacadeImpl()
get{
val codiceParam = call.request.queryParameters["codice"]
val listSCap = dao.allSCapFiltered(codiceParam)
if(listSCap.isEmpty())
call.respondText("Nessun elemento trovato", status = HttpStatusCode.NotFound)
else
call.respond(listSCap)
}
...
}
and in the DAO:
override suspend fun allSCapFiltered(codice: String?): List<SCap> {
return if(codice.isNullOrEmpty()){
DatabaseFactory.dbQuery {
S_Cap.selectAll().map(::resultRowToSCap)
}
} else {
DatabaseFactory.dbQuery {
S_Cap
.select { S_Cap.codice like "%$codice%" }
.map(::resultRowToSCap)
}
}
}
is there a way to manage all the parameters expected dynamically, based on properties of data class?
data class SCap(val idcap: Int?,
val regione: String?,
val prov: String?,
val comune: String?,
val cap: Int?,
val codice: String?
)
Thanks everyone for suggestions!