Compare commits
No commits in common. "1222798b112de4c1c0b200137bc8af43ca5384f6" and "cd597a52c2ad61ec358f196a7eea8d7b56d53e96" have entirely different histories.
1222798b11
...
cd597a52c2
@ -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"
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package eu.maiora.db
|
|||||||
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
||||||
import eu.maiora.model.Accounts
|
import eu.maiora.model.Accounts
|
||||||
import eu.maiora.model.Parametri
|
import eu.maiora.model.Parametri
|
||||||
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
|
||||||
@ -28,17 +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)
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
||||||
|
|
||||||
@ -53,16 +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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
||||||
dao.id.value,
|
dao.id.value,
|
||||||
@ -76,15 +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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
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 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
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,9 +6,7 @@ package eu.maiora.plugins
|
|||||||
//import eu.maiora.routes.logScriptRouting
|
//import eu.maiora.routes.logScriptRouting
|
||||||
import eu.maiora.model.AccountsRepositoryImpl
|
import eu.maiora.model.AccountsRepositoryImpl
|
||||||
import eu.maiora.model.ParametriRepositoryImpl
|
import eu.maiora.model.ParametriRepositoryImpl
|
||||||
import eu.maiora.model.TessereRepositoryImpl
|
|
||||||
import eu.maiora.routes.auth
|
import eu.maiora.routes.auth
|
||||||
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.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
@ -21,6 +19,5 @@ fun Application.configureRouting(dbUrl : String, username : String, password : S
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
tessere(TessereRepositoryImpl())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user