forked from maiora/backend-api
Compare commits
No commits in common. "main" and "main" have entirely different histories.
@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
|
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
|
||||||
}
|
}
|
||||||
rootProject.name = "Backend_API_DSU"
|
rootProject.name = "Backend_API"
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ fun Application.module(configFile: Properties) {
|
|||||||
|
|
||||||
fun loadConfig(): Properties {
|
fun loadConfig(): Properties {
|
||||||
val properties = Properties()
|
val properties = Properties()
|
||||||
val inputStream = FileInputStream("/home/ristocloudadm/config.properties")
|
val inputStream = FileInputStream("/home/backend_api/config.properties")
|
||||||
properties.load(inputStream)
|
properties.load(inputStream)
|
||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
package eu.maiora.db
|
package eu.maiora.db
|
||||||
|
|
||||||
import eu.maiora.model.*
|
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
||||||
|
import eu.maiora.model.Accounts
|
||||||
|
import eu.maiora.model.Parametri
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.jetbrains.exposed.dao.IntEntity
|
import org.jetbrains.exposed.dao.IntEntity
|
||||||
import org.jetbrains.exposed.dao.IntEntityClass
|
import org.jetbrains.exposed.dao.IntEntityClass
|
||||||
import org.jetbrains.exposed.dao.LongEntity
|
|
||||||
import org.jetbrains.exposed.dao.LongEntityClass
|
|
||||||
import org.jetbrains.exposed.dao.id.EntityID
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
import org.jetbrains.exposed.dao.id.IdTable
|
import org.jetbrains.exposed.dao.id.IdTable
|
||||||
import org.jetbrains.exposed.sql.Transaction
|
import org.jetbrains.exposed.sql.Transaction
|
||||||
import org.jetbrains.exposed.sql.javatime.datetime
|
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
object AccountsTable : IdTable<Int>("accounts"){
|
object AccountsTable : IdTable<Int>("accounts"){
|
||||||
override val id = integer("id").entityId()
|
override val id = integer("id").entityId()
|
||||||
@ -31,51 +27,6 @@ object ParametriTable : IdTable<Int>("parametri"){
|
|||||||
override val primaryKey = PrimaryKey(id)
|
override val primaryKey = PrimaryKey(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
object TessereTable : IdTable<Long>("view_tessere_api"){
|
|
||||||
override val id = long("id").entityId()
|
|
||||||
val idUtente = long("id_utente")
|
|
||||||
val codiceFiscale = varchar("codice_fiscale", 255)
|
|
||||||
val numero = varchar("numero", 255)
|
|
||||||
val saldo = double("saldo")
|
|
||||||
val punti = integer("punti")
|
|
||||||
|
|
||||||
override val primaryKey = PrimaryKey(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
object MovimentiTable : IdTable<Long>("view_movimenti_api"){
|
|
||||||
override val id = long("id").entityId()
|
|
||||||
val idTessera = long("id_tessera")
|
|
||||||
val numero = varchar("numero_tessera", 255)
|
|
||||||
val operazione = varchar("operazione", 255)
|
|
||||||
val dataMovimento = datetime("data_movimento")
|
|
||||||
val transazione = varchar("transazione", 255)
|
|
||||||
val dispositivo = varchar("dispositivo", 255)
|
|
||||||
val riferimento= varchar("riferimento", 255)
|
|
||||||
val saldoPre = double("saldo_pre")
|
|
||||||
val importo = double("importo")
|
|
||||||
val saldoPost = double("saldo_post")
|
|
||||||
val puntiPre = integer("punti_pre")
|
|
||||||
val punti = integer("punti")
|
|
||||||
val puntiPost = integer("punti_post")
|
|
||||||
}
|
|
||||||
|
|
||||||
object ComposizioniTable : IdTable<Long>("view_composizioni"){
|
|
||||||
override val id = long("id").entityId()
|
|
||||||
val idVassoio = long("id_vassoio")
|
|
||||||
val vassoio = varchar("vassoio", 255)
|
|
||||||
val idCategoria = long("id_categoria")
|
|
||||||
val categoria = varchar("categoria", 255)
|
|
||||||
val quantita = integer("quantita")
|
|
||||||
}
|
|
||||||
|
|
||||||
object RicaricheTable : IdTable<Long>("ricariche_app"){
|
|
||||||
override val id = long("id").autoIncrement("seq_ricariche_app").entityId()
|
|
||||||
val codiceTransazione = varchar("codice_transazione", 255)
|
|
||||||
val messaggio = varchar("messaggio", 255).nullable()
|
|
||||||
val idTessera = long("id_tessera")
|
|
||||||
val importo = double("importo")
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
||||||
|
|
||||||
@ -90,53 +41,6 @@ class ParametriDAO(id: EntityID<Int>) :IntEntity(id) {
|
|||||||
var valore by ParametriTable.valore
|
var valore by ParametriTable.valore
|
||||||
}
|
}
|
||||||
|
|
||||||
class TessereDao(id: EntityID<Long>) :LongEntity(id) {
|
|
||||||
companion object : LongEntityClass<TessereDao>(TessereTable)
|
|
||||||
|
|
||||||
var idUtente by TessereTable.idUtente
|
|
||||||
var codiceFiscale by TessereTable.codiceFiscale
|
|
||||||
var numero by TessereTable.numero
|
|
||||||
var saldo by TessereTable.saldo
|
|
||||||
var punti by TessereTable.punti
|
|
||||||
}
|
|
||||||
|
|
||||||
class MovimentiDao(id: EntityID<Long>) :LongEntity(id) {
|
|
||||||
companion object : LongEntityClass<MovimentiDao>(MovimentiTable)
|
|
||||||
|
|
||||||
var idTessera by MovimentiTable.idTessera
|
|
||||||
var numero by MovimentiTable.numero
|
|
||||||
var operazione by MovimentiTable.operazione
|
|
||||||
var dataMovimento by MovimentiTable.dataMovimento
|
|
||||||
var transazione by MovimentiTable.transazione
|
|
||||||
var dispositivo by MovimentiTable.dispositivo
|
|
||||||
var riferimento by MovimentiTable.riferimento
|
|
||||||
var saldoPre by MovimentiTable.saldoPre
|
|
||||||
var importo by MovimentiTable.importo
|
|
||||||
var saldoPost by MovimentiTable.saldoPost
|
|
||||||
var puntiPre by MovimentiTable.puntiPre
|
|
||||||
var punti by MovimentiTable.punti
|
|
||||||
var puntiPost by MovimentiTable.puntiPost
|
|
||||||
}
|
|
||||||
|
|
||||||
class ComposizioniDao(id: EntityID<Long>) :LongEntity(id){
|
|
||||||
companion object : LongEntityClass<ComposizioniDao>(ComposizioniTable)
|
|
||||||
|
|
||||||
var idVassoio by ComposizioniTable.idVassoio
|
|
||||||
var vassoio by ComposizioniTable.vassoio
|
|
||||||
var idCategoria by ComposizioniTable.idCategoria
|
|
||||||
var categoria by ComposizioniTable.categoria
|
|
||||||
var quantita by ComposizioniTable.quantita
|
|
||||||
}
|
|
||||||
|
|
||||||
class RicaricheDao(id: EntityID<Long>) :LongEntity(id){
|
|
||||||
companion object : LongEntityClass<RicaricheDao>(RicaricheTable)
|
|
||||||
|
|
||||||
var codiceTransazione by RicaricheTable.codiceTransazione
|
|
||||||
var messaggio by RicaricheTable.messaggio
|
|
||||||
var idTessera by RicaricheTable.idTessera
|
|
||||||
var importo by RicaricheTable.importo
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
||||||
dao.id.value,
|
dao.id.value,
|
||||||
@ -150,46 +54,6 @@ fun parametriDaoToModel(dao: ParametriDAO) = Parametri(
|
|||||||
dao.valore
|
dao.valore
|
||||||
)
|
)
|
||||||
|
|
||||||
fun tessereDaoToModel(dao: TessereDao) = Tessere(
|
|
||||||
dao.id.value,
|
|
||||||
dao.idUtente,
|
|
||||||
dao.codiceFiscale,
|
|
||||||
dao.numero,
|
|
||||||
dao.saldo,
|
|
||||||
dao.punti
|
|
||||||
)
|
|
||||||
|
|
||||||
fun movimentiDaoToModel(dao: MovimentiDao) :Movimenti{
|
|
||||||
val formatter = DateTimeFormatter.ofPattern("ddMMyyyy HH:mm")
|
|
||||||
val formattedDate = dao.dataMovimento.format(formatter)
|
|
||||||
|
|
||||||
return Movimenti(
|
|
||||||
dao.id.value,
|
|
||||||
dao.idTessera,
|
|
||||||
dao.numero,
|
|
||||||
dao.operazione,
|
|
||||||
formattedDate,
|
|
||||||
dao.transazione,
|
|
||||||
dao.dispositivo,
|
|
||||||
dao.riferimento,
|
|
||||||
dao.saldoPre,
|
|
||||||
dao.importo,
|
|
||||||
dao.saldoPost,
|
|
||||||
dao.puntiPre,
|
|
||||||
dao.punti,
|
|
||||||
dao.puntiPost
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun composizioniDaoToModel(dao: ComposizioniDao) = Composizioni(
|
|
||||||
dao.id.value,
|
|
||||||
dao.idVassoio,
|
|
||||||
dao.vassoio,
|
|
||||||
dao.idCategoria,
|
|
||||||
dao.categoria,
|
|
||||||
dao.quantita
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
||||||
newSuspendedTransaction(Dispatchers.IO, statement = block)
|
newSuspendedTransaction(Dispatchers.IO, statement = block)
|
@ -1,13 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Composizioni(
|
|
||||||
val id: Long,
|
|
||||||
val idVassoio : Long,
|
|
||||||
val vassoio : String,
|
|
||||||
val idCategoria : Long,
|
|
||||||
val categoria : String,
|
|
||||||
val quantita : Int
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface ComposizioniRepository {
|
|
||||||
suspend fun listaComposizioni(): List<Composizioni>
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
import org.jetbrains.exposed.sql.SortOrder
|
|
||||||
|
|
||||||
class ComposizioniRepositoryImpl : ComposizioniRepository {
|
|
||||||
override suspend fun listaComposizioni(): List<Composizioni> = suspendTransaction {
|
|
||||||
// Cerca la lista di composizioni
|
|
||||||
ComposizioniDao.all()
|
|
||||||
.toList()
|
|
||||||
.map { composizioniDaoToModel(it) } // Converte il DAO in un oggetto Composizioni
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Movimenti(
|
|
||||||
val id: Long,
|
|
||||||
val idTessera: Long,
|
|
||||||
val numero: String,
|
|
||||||
val operazione: String,
|
|
||||||
val dataMovimento: String,
|
|
||||||
val transazione: String,
|
|
||||||
val dispositivo: String,
|
|
||||||
val riferimento: String,
|
|
||||||
val saldoPre: Double,
|
|
||||||
val importo: Double,
|
|
||||||
val saldoPost: Double,
|
|
||||||
val puntiPre: Int,
|
|
||||||
val punti: Int,
|
|
||||||
val puntiPost: Int
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface MovimentiRepository {
|
|
||||||
suspend fun movimentiByIdTessera(idTessera : Long): List<Movimenti>?
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
import org.jetbrains.exposed.sql.SortOrder
|
|
||||||
|
|
||||||
class MovimentiRepositoryImpl : MovimentiRepository {
|
|
||||||
override suspend fun movimentiByIdTessera(idTessera : Long): List<Movimenti> = suspendTransaction {
|
|
||||||
// Cerca la lista di movimenti
|
|
||||||
MovimentiDao.find { MovimentiTable.idTessera eq idTessera }
|
|
||||||
.orderBy(MovimentiTable.dataMovimento to SortOrder.DESC)
|
|
||||||
.toList() // Restituisce la lista dei movimenti
|
|
||||||
.map { movimentiDaoToModel(it) } // Converte il DAO in un oggetto Movimenti
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Ricariche(
|
|
||||||
val id : Long? = null,
|
|
||||||
val codiceTransazione : String,
|
|
||||||
val messaggio : String? = null,
|
|
||||||
val idTessera : Long,
|
|
||||||
val importo : Double
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface RicaricheRepository {
|
|
||||||
suspend fun insert(ricarica : Ricariche): Ricariche
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
import org.jetbrains.exposed.sql.insert
|
|
||||||
import org.jetbrains.exposed.sql.insertAndGetId
|
|
||||||
|
|
||||||
class RicaricheRepositoryImpl : RicaricheRepository {
|
|
||||||
override suspend fun insert(ricarica : Ricariche): Ricariche = suspendTransaction {
|
|
||||||
// Inserisci una nuova ricarica
|
|
||||||
// ID non definito: viene gestito dalla sequence
|
|
||||||
val idRicaricaInserted = RicaricheTable.insertAndGetId {
|
|
||||||
it[codiceTransazione] = ricarica.codiceTransazione
|
|
||||||
it[messaggio] = ricarica.messaggio
|
|
||||||
it[idTessera] = ricarica.idTessera
|
|
||||||
it[importo] = ricarica.importo
|
|
||||||
}.value
|
|
||||||
|
|
||||||
Ricariche(
|
|
||||||
idRicaricaInserted,
|
|
||||||
ricarica.codiceTransazione,
|
|
||||||
ricarica.messaggio,
|
|
||||||
ricarica.idTessera,
|
|
||||||
ricarica.importo
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Tessere(
|
|
||||||
val id: Long,
|
|
||||||
val idUtente : Long,
|
|
||||||
val codiceFiscale : String,
|
|
||||||
val numero : String,
|
|
||||||
val saldo : Double,
|
|
||||||
val punti : Int
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface TessereRepository {
|
|
||||||
suspend fun tesseraByCodiceFiscale(cf : String): Tessere?
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
|
|
||||||
class TessereRepositoryImpl : TessereRepository {
|
|
||||||
override suspend fun tesseraByCodiceFiscale(cf: String): Tessere? = suspendTransaction {
|
|
||||||
// Cerca tessere in base al codice fiscale
|
|
||||||
TessereDao.find { TessereTable.codiceFiscale eq cf }
|
|
||||||
.singleOrNull() // Restituisce un singolo risultato o null se non trovato
|
|
||||||
?.let { tessereDaoToModel(it) } // Converte il DAO in un oggetto Tessere
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ValorePasti(
|
|
||||||
val idTessera : Long,
|
|
||||||
val idVassoio : Long,
|
|
||||||
val data : String,
|
|
||||||
val prezzo : Double,
|
|
||||||
val punti : Int
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface ValorePastiRepository {
|
|
||||||
suspend fun valorePastoByTessVassData(idTessera : String, idVassoio : String, data : String): String
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
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 ValorePastiRepositoryImpl : ValorePastiRepository {
|
|
||||||
override suspend fun valorePastoByTessVassData(idTessera : String, idVassoio : String, data : String): String = suspendTransaction {
|
|
||||||
// Cerca valore del pasto e punti in base alla tessera, al vassoio e al giorno
|
|
||||||
|
|
||||||
val result = exec("SELECT SIR.trova_tariffa(?, ?, ?) FROM dual",
|
|
||||||
listOf(
|
|
||||||
Pair(LongColumnType(), idTessera),
|
|
||||||
Pair(LongColumnType(), idVassoio),
|
|
||||||
Pair(VarCharColumnType(), data)
|
|
||||||
)){ rs ->
|
|
||||||
var resultString: String? = null
|
|
||||||
// Processiamo il ResultSet restituito dalla query
|
|
||||||
if (rs.next()) {
|
|
||||||
resultString = rs.getString(1) // Leggiamo il primo risultato
|
|
||||||
}
|
|
||||||
resultString
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
result ?: "Nessun risultato"
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package eu.maiora.plugins
|
package eu.maiora.plugins
|
||||||
|
|
||||||
import eu.maiora.model.*
|
import eu.maiora.model.AccountsRepositoryImpl
|
||||||
import eu.maiora.routes.*
|
import eu.maiora.routes.auth
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
@ -13,10 +13,5 @@ fun Application.configureRouting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
tessere(TessereRepositoryImpl())
|
|
||||||
movimenti(MovimentiRepositoryImpl())
|
|
||||||
composizioni(ComposizioniRepositoryImpl())
|
|
||||||
valorePasti(ValorePastiRepositoryImpl())
|
|
||||||
ricariche(RicaricheRepositoryImpl())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package eu.maiora.routes
|
|
||||||
|
|
||||||
import eu.maiora.model.ComposizioniRepositoryImpl
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.auth.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.composizioni(composizioniRepository: ComposizioniRepositoryImpl){
|
|
||||||
route("/api/composizioni"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
get(){
|
|
||||||
val listaComposizioni = composizioniRepository.listaComposizioni()
|
|
||||||
call.respond(listaComposizioni)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package eu.maiora.routes
|
|
||||||
|
|
||||||
import eu.maiora.model.MovimentiRepositoryImpl
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.auth.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.movimenti(movimentiRepository: MovimentiRepositoryImpl){
|
|
||||||
route("/api/movimenti"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
get("{idTessera}"){
|
|
||||||
// Ottieni l'id della tessera dal percorso
|
|
||||||
val idTessera = call.parameters["idTessera"]
|
|
||||||
|
|
||||||
if (idTessera == null) {
|
|
||||||
call.respondText("ID tessera non valido", status = HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cerca la tessera per codice fiscale
|
|
||||||
val listaMovimenti = movimentiRepository.movimentiByIdTessera(idTessera.toLong())
|
|
||||||
|
|
||||||
|
|
||||||
if (listaMovimenti != null) {
|
|
||||||
call.respond(listaMovimenti)
|
|
||||||
} else {
|
|
||||||
call.respondText("Movimenti non trovati", status = HttpStatusCode.NotFound)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
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.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.ricariche(ricaricheRepository: RicaricheRepository){
|
|
||||||
route("/api/ricariche"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
post(){
|
|
||||||
try{
|
|
||||||
val ricaricaRequest = call.receive<Ricariche>()
|
|
||||||
|
|
||||||
//solo per il codiceTransazione (String) è necessario controllare se è vuoto
|
|
||||||
if(ricaricaRequest.codiceTransazione.isBlank()){
|
|
||||||
call.respond(
|
|
||||||
HttpStatusCode.BadRequest,
|
|
||||||
"Errore nel processare la richiesta: codiceTransazione vuoto"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inserisci la ricarica nel database
|
|
||||||
val ricaricaInserita = ricaricheRepository.insert(ricaricaRequest)
|
|
||||||
|
|
||||||
// Rispondi con l'oggetto Ricariche, che include l'ID generato
|
|
||||||
call.respond(HttpStatusCode.Created, ricaricaInserita)
|
|
||||||
}
|
|
||||||
catch (e: Exception){
|
|
||||||
call.respond(
|
|
||||||
HttpStatusCode.BadRequest,
|
|
||||||
"Errore nel processare la richiesta: ${e.cause}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package eu.maiora.routes
|
|
||||||
|
|
||||||
import eu.maiora.model.TessereRepositoryImpl
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.auth.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.tessere(tessereRepository: TessereRepositoryImpl){
|
|
||||||
route("/api/tessere"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
get("{cf}"){
|
|
||||||
// Ottieni il codice fiscale dal percorso
|
|
||||||
val cf = call.parameters["cf"]
|
|
||||||
|
|
||||||
if (cf == null) {
|
|
||||||
call.respondText("Codice fiscale non valido", status = HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cerca la tessera per codice fiscale
|
|
||||||
val tessera = tessereRepository.tesseraByCodiceFiscale(cf)
|
|
||||||
|
|
||||||
if (tessera != null) {
|
|
||||||
call.respond(tessera)
|
|
||||||
} else {
|
|
||||||
call.respondText("Tessera non trovata", status = HttpStatusCode.NotFound)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package eu.maiora.routes
|
|
||||||
|
|
||||||
import eu.maiora.model.TessereRepositoryImpl
|
|
||||||
import eu.maiora.model.ValorePasti
|
|
||||||
import eu.maiora.model.ValorePastiRepository
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.auth.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.valorePasti(valorePastiRepository: ValorePastiRepository){
|
|
||||||
route("/api/valorePasti"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
get(){
|
|
||||||
// Ottieni i parametri dal percorso
|
|
||||||
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user