forked from maiora/backend-api
Compare commits
No commits in common. "a633d1aac64ca8893b65647399a250f2b7e40c60" and "71443ff6f324e89e467a5987c89c47d5ef017c55" have entirely different histories.
a633d1aac6
...
71443ff6f3
@ -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"
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,6 @@ import eu.maiora.routes.auth
|
|||||||
import eu.maiora.routes.composizioni
|
import eu.maiora.routes.composizioni
|
||||||
import eu.maiora.routes.movimenti
|
import eu.maiora.routes.movimenti
|
||||||
import eu.maiora.routes.tessere
|
import eu.maiora.routes.tessere
|
||||||
import eu.maiora.routes.valorePasti
|
|
||||||
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.*
|
||||||
@ -20,6 +19,5 @@ fun Application.configureRouting() {
|
|||||||
tessere(TessereRepositoryImpl())
|
tessere(TessereRepositoryImpl())
|
||||||
movimenti(MovimentiRepositoryImpl())
|
movimenti(MovimentiRepositoryImpl())
|
||||||
composizioni(ComposizioniRepositoryImpl())
|
composizioni(ComposizioniRepositoryImpl())
|
||||||
valorePasti(ValorePastiRepositoryImpl())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
|||||||
logger.info(
|
logger.info(
|
||||||
"param: " +
|
"param: " +
|
||||||
receivedResponse.param
|
receivedResponse.param
|
||||||
)
|
);
|
||||||
|
|
||||||
// Decodifica la stringa da Base64 a oggetto Credentials
|
// Decodifica la stringa da Base64 a oggetto Credentials
|
||||||
val decodedBytes = Base64.getDecoder().decode(receivedResponse.param)
|
val decodedBytes = Base64.getDecoder().decode(receivedResponse.param)
|
||||||
|
@ -1,50 +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)
|
|
||||||
call.respond( ValorePasti(idTessera.toLong(),
|
|
||||||
idVassoio.toLong(), data,
|
|
||||||
prezzo.replace(',', '.').toDouble(),
|
|
||||||
punti.toInt()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +1,19 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<!-- Appender per la console -->
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||||
<!-- Appender per il file di log con rotazione basata su tempo e dimensione -->
|
<file>./logFile.log</file>
|
||||||
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>./log/logFile.log</file> <!-- File di log principale -->
|
|
||||||
<append>true</append>
|
<append>true</append>
|
||||||
|
|
||||||
<!-- RollingPolicy per dimensione e tempo -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
|
||||||
<!-- Pattern per il nome dei file ruotati: include la data -->
|
|
||||||
<FileNamePattern>./log/logFile.%d{yyyy-MM-dd}.%i.log</FileNamePattern> <!-- %i è il numero di file generato -->
|
|
||||||
|
|
||||||
<!-- Limita la dimensione del file a 100MB -->
|
|
||||||
<maxFileSize>100MB</maxFileSize> <!-- Ruota il file quando raggiunge 100MB -->
|
|
||||||
|
|
||||||
<!-- Conserva i log per due settimane -->
|
|
||||||
<maxHistory>15</maxHistory> <!-- Limita a 15 giorni i log archiviati -->
|
|
||||||
|
|
||||||
<!-- Limita la dimensione totale dei file di log a 5GB -->
|
|
||||||
<totalSizeCap>5GB</totalSizeCap>
|
|
||||||
</rollingPolicy>
|
|
||||||
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
<root level="trace">
|
||||||
<!-- Configurazione del livello di log -->
|
<appender-ref ref="FILE"/>
|
||||||
<root level="DEBUG">
|
|
||||||
<appender-ref ref="ROLLING_FILE"/>
|
|
||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<logger name="io.netty" level="INFO"/>
|
<logger name="io.netty" level="INFO"/>
|
||||||
|
</configuration>
|
||||||
</configuration>
|
|
Loading…
Reference in New Issue
Block a user