forked from maiora/backend-api
Compare commits
No commits in common. "311d1fbd3b3b79d7135374532335e187176ecfce" and "e0d64f91d13fc7f6ef9ce840c0c27702d0cbca0c" have entirely different histories.
311d1fbd3b
...
e0d64f91d1
@ -1,22 +1,16 @@
|
|||||||
package eu.maiora.db
|
package eu.maiora.db
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
||||||
import eu.maiora.model.Accounts
|
import eu.maiora.model.Accounts
|
||||||
import eu.maiora.model.Movimenti
|
|
||||||
import eu.maiora.model.Parametri
|
import eu.maiora.model.Parametri
|
||||||
import eu.maiora.model.Tessere
|
import eu.maiora.model.Tessere
|
||||||
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()
|
||||||
@ -45,23 +39,6 @@ object TessereTable : IdTable<Long>("view_tessere_api"){
|
|||||||
override val primaryKey = PrimaryKey(id)
|
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
||||||
|
|
||||||
@ -86,24 +63,6 @@ class TessereDao(id: EntityID<Long>) :LongEntity(id) {
|
|||||||
var punti by TessereTable.punti
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
||||||
dao.id.value,
|
dao.id.value,
|
||||||
@ -126,31 +85,6 @@ fun tessereDaoToModel(dao: TessereDao) = Tessere(
|
|||||||
dao.punti
|
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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,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
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,11 +5,9 @@ package eu.maiora.plugins
|
|||||||
//import eu.maiora.routes.eseguiScriptSQLRoute
|
//import eu.maiora.routes.eseguiScriptSQLRoute
|
||||||
//import eu.maiora.routes.logScriptRouting
|
//import eu.maiora.routes.logScriptRouting
|
||||||
import eu.maiora.model.AccountsRepositoryImpl
|
import eu.maiora.model.AccountsRepositoryImpl
|
||||||
import eu.maiora.model.MovimentiRepositoryImpl
|
|
||||||
import eu.maiora.model.ParametriRepositoryImpl
|
import eu.maiora.model.ParametriRepositoryImpl
|
||||||
import eu.maiora.model.TessereRepositoryImpl
|
import eu.maiora.model.TessereRepositoryImpl
|
||||||
import eu.maiora.routes.auth
|
import eu.maiora.routes.auth
|
||||||
import eu.maiora.routes.movimenti
|
|
||||||
import eu.maiora.routes.tessere
|
import eu.maiora.routes.tessere
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
@ -24,6 +22,5 @@ fun Application.configureRouting(dbUrl : String, username : String, password : S
|
|||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
tessere(TessereRepositoryImpl())
|
tessere(TessereRepositoryImpl())
|
||||||
movimenti(MovimentiRepositoryImpl())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user