0002343-endpoint-tessere #2
@ -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"
|
rootProject.name = "Backend_API_DSU"
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ object ParametriTable : IdTable<Int>("parametri"){
|
|||||||
override val primaryKey = PrimaryKey(id)
|
override val primaryKey = PrimaryKey(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
object TessereTable : IdTable<Int>("tessere"){
|
object TessereTable : IdTable<Int>("view_tessere_api"){
|
||||||
override val id = integer("id").entityId()
|
override val id = integer("id").entityId()
|
||||||
val idUtente = integer("id_utente")
|
val idUtente = integer("id_utente")
|
||||||
val codiceFiscale = varchar("codice_fiscale", 255)
|
val codiceFiscale = varchar("codice_fiscale", 255)
|
||||||
|
@ -6,7 +6,9 @@ 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.*
|
||||||
@ -19,5 +21,6 @@ fun Application.configureRouting(dbUrl : String, username : String, password : S
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
|
tessere(TessereRepositoryImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,48 +1,35 @@
|
|||||||
package eu.maiora.routes
|
package eu.maiora.routes
|
||||||
|
|
||||||
import eu.maiora.model.ParametriRepositoryImpl
|
|
||||||
import eu.maiora.model.TessereRepositoryImpl
|
import eu.maiora.model.TessereRepositoryImpl
|
||||||
import io.jsonwebtoken.Jwts
|
|
||||||
import io.jsonwebtoken.SignatureAlgorithm
|
|
||||||
import io.jsonwebtoken.security.Keys
|
|
||||||
import io.ktor.client.statement.*
|
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.request.*
|
import io.ktor.server.auth.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
|
|
||||||
fun Route.tessere(tessereRepository: TessereRepositoryImpl, parametriRepository: ParametriRepositoryImpl){
|
fun Route.tessere(tessereRepository: TessereRepositoryImpl){
|
||||||
route("/tessere"){
|
route("/api/tessere"){
|
||||||
get("{cf}"){
|
authenticate("auth-jwt") {
|
||||||
//verifica JWT
|
get("{cf}"){
|
||||||
val parametro = parametriRepository.parametroByChiave("jwt_secret")
|
// Ottieni il codice fiscale dal percorso
|
||||||
if(parametro != null){
|
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)
|
||||||
|
|
||||||
// Ottieni il codice fiscale dal percorso
|
if (tessera != null) {
|
||||||
val cf = call.parameters["cf"]
|
call.respond(tessera)
|
||||||
|
} else {
|
||||||
if (cf == null) {
|
call.respondText("Tessera non trovata", status = HttpStatusCode.NotFound)
|
||||||
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