forked from maiora/backend-api
aggiunta endpoint /verificaVassoio
una POST per recuperare l'id del vassoio più conveniente collegato a utente e prodotti, -1 se non esiste
This commit is contained in:
parent
883c878662
commit
d296748215
@ -0,0 +1,5 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
interface SelezionaComposizioneRepository {
|
||||||
|
suspend fun verificaComposizione(idUtente : Long, listaProdotti : String): Long
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.LongColumnType
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder
|
||||||
|
import org.jetbrains.exposed.sql.VarCharColumnType
|
||||||
|
|
||||||
|
class SelezionaComposizioneRepositoryImpl : SelezionaComposizioneRepository {
|
||||||
|
override suspend fun verificaComposizione(idUtente : Long, listaProdotti : String): Long = suspendTransaction {
|
||||||
|
// Cerca il vassoio in base all'utente e alla lista dei prodotti
|
||||||
|
|
||||||
|
val result = exec("SELECT SIR.seleziona_composizione(?, ?) FROM dual",
|
||||||
|
listOf(
|
||||||
|
Pair(VarCharColumnType(), listaProdotti),
|
||||||
|
Pair(LongColumnType(), idUtente)
|
||||||
|
)){ rs ->
|
||||||
|
var resultString: String? = null
|
||||||
|
// Processiamo il ResultSet restituito dalla query
|
||||||
|
if (rs.next()) {
|
||||||
|
resultString = rs.getString(1) // Leggiamo il primo risultato
|
||||||
|
}
|
||||||
|
resultString?.toLong()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result ?: -1L
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -27,5 +27,6 @@ fun Application.configureRouting() {
|
|||||||
PrenotazioniPastiDettaglioRepositoryImpl(),
|
PrenotazioniPastiDettaglioRepositoryImpl(),
|
||||||
ViewPrenotazioniPastiRepositoryImpl())
|
ViewPrenotazioniPastiRepositoryImpl())
|
||||||
annullaPrenotazioni(ViewPrenotazioniPastiRepositoryImpl(), PrenotazioniPastiDettaglioRepositoryImpl())
|
annullaPrenotazioni(ViewPrenotazioniPastiRepositoryImpl(), PrenotazioniPastiDettaglioRepositoryImpl())
|
||||||
|
verificaVassoio(SelezionaComposizioneRepositoryImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
78
src/main/kotlin/eu/maiora/routes/VerificaVassoio.kt
Normal file
78
src/main/kotlin/eu/maiora/routes/VerificaVassoio.kt
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package eu.maiora.routes
|
||||||
|
|
||||||
|
import eu.maiora.model.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.request.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
|
||||||
|
fun Route.verificaVassoio(selezionaComposizioneRepository: SelezionaComposizioneRepository){
|
||||||
|
route("/api/verificaVassoio"){
|
||||||
|
authenticate("auth-jwt") {
|
||||||
|
post(){
|
||||||
|
// Ottieni i parametri dal percorso
|
||||||
|
try {
|
||||||
|
val dati = call.receive<DatiVassoio>()
|
||||||
|
|
||||||
|
val idsConcatenati = dati.listaProdotti.joinToString(separator = "|") { it.id.toString() }
|
||||||
|
|
||||||
|
//effettua la chiamata al db alla funzione seleziona_composizione
|
||||||
|
var result = selezionaComposizioneRepository.verificaComposizione(dati.idUtente, idsConcatenati)
|
||||||
|
|
||||||
|
call.respond(result)
|
||||||
|
}
|
||||||
|
catch (e: Exception){
|
||||||
|
println("Errore nella deserializzazione: ${e.message}")
|
||||||
|
call.respond(HttpStatusCode.BadRequest, "Body non valido")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*val idTessera = call.parameters["idTessera"]
|
||||||
|
val idVassoio = call.parameters["idVassoio"]
|
||||||
|
val data = call.parameters["data"]
|
||||||
|
|
||||||
|
if (idTessera == null) {
|
||||||
|
call.respondText("ID tessera non valido", status = HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idVassoio == null) {
|
||||||
|
call.respondText("ID vassoio non valido", status = HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
call.respondText("data non valida", status = HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerca la tessera per codice fiscale
|
||||||
|
val valorePasto = valorePastiRepository.valorePastoByTessVassData(idTessera, idVassoio, data)
|
||||||
|
val prezzo = valorePasto.split("#").get(0)
|
||||||
|
val punti = valorePasto.split("#").get(1)
|
||||||
|
|
||||||
|
if(prezzo == "-1" && punti == "-1")
|
||||||
|
call.respondText("Prezzo e punti non trovati", status = HttpStatusCode.NotFound)
|
||||||
|
|
||||||
|
|
||||||
|
call.respond( ValorePasti(idTessera.toLong(),
|
||||||
|
idVassoio.toLong(), data,
|
||||||
|
prezzo.replace(',', '.').toDouble(),
|
||||||
|
punti.toInt()))*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class DatiVassoio (val idUtente : Long, val listaProdotti: List<ProdottiPrenotabili>)
|
Loading…
Reference in New Issue
Block a user