forked from maiora/backend-api
Compare commits
No commits in common. "dev" 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_FAER_ecommerce"
|
rootProject.name = "Backend_API"
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import java.util.*
|
|||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val properties = loadConfig()
|
val properties = loadConfig()
|
||||||
val port = properties.getProperty("server.ecommerce.port").toInt()
|
val port = properties.getProperty("server.port").toInt()
|
||||||
embeddedServer(Netty, port = port, host = "0.0.0.0") {
|
embeddedServer(Netty, port = port, host = "0.0.0.0") {
|
||||||
module(properties)
|
module(properties)
|
||||||
}.start(wait = true)
|
}.start(wait = true)
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ViewEcommercePrezSconDisp(
|
|
||||||
val id : Long,
|
|
||||||
val idCliente : Long,
|
|
||||||
val idArticolo : Long,
|
|
||||||
val idMagazzino : Long,
|
|
||||||
val magazzino : String,
|
|
||||||
val valoreCarcassa : Double,
|
|
||||||
val prezzo : Double,
|
|
||||||
val sconto : Double,
|
|
||||||
val sconto1 : Double,
|
|
||||||
val sconto2 : Double,
|
|
||||||
val sconto3 : Double,
|
|
||||||
val netto : Double,
|
|
||||||
val numeroPezzi : Int
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface ViewEcommercePrezSconDispRepository {
|
|
||||||
suspend fun disponibilitaByIdArtIdClie(idCliente: Long, idArticolo : Long ): List<ViewEcommercePrezSconDisp>?
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
import eu.maiora.loadConfig
|
|
||||||
import org.jetbrains.exposed.sql.LongColumnType
|
|
||||||
|
|
||||||
class ViewEcommercePrezSconDispRepositoryImpl : ViewEcommercePrezSconDispRepository {
|
|
||||||
override suspend fun disponibilitaByIdArtIdClie(idCliente: Long, idArticolo : Long): List<ViewEcommercePrezSconDisp>? = suspendTransaction {
|
|
||||||
// Cerca le disponibilità e i prezzi dato articolo e cliente dalla table function ViewEcommercePrezSconDispTable
|
|
||||||
val properties = loadConfig()
|
|
||||||
|
|
||||||
val result = exec("SELECT * FROM dbo.Get_Prez_Scon_Disp(?, ?)", listOf(
|
|
||||||
LongColumnType() to idCliente,
|
|
||||||
LongColumnType() to idArticolo
|
|
||||||
)) { rs ->
|
|
||||||
val list = mutableListOf<ViewEcommercePrezSconDisp>()
|
|
||||||
while (rs.next()) {
|
|
||||||
val element : ViewEcommercePrezSconDisp
|
|
||||||
if(idCliente == properties.getProperty("qricambi.id").toLong()){
|
|
||||||
element = ViewEcommercePrezSconDisp(
|
|
||||||
id = rs.getLong("id"),
|
|
||||||
idCliente = rs.getLong("id_cliente"),
|
|
||||||
idArticolo = rs.getLong("id_articolo"),
|
|
||||||
idMagazzino = -1,
|
|
||||||
magazzino = "",
|
|
||||||
valoreCarcassa = rs.getDouble("valore_carcassa"),
|
|
||||||
prezzo = 0.0,
|
|
||||||
sconto = 0.0,
|
|
||||||
sconto1 = 0.0,
|
|
||||||
sconto2 = 0.0,
|
|
||||||
sconto3 = 0.0,
|
|
||||||
netto = 0.0,
|
|
||||||
numeroPezzi = rs.getInt("numero_pezzi")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
element = ViewEcommercePrezSconDisp(
|
|
||||||
id = rs.getLong("id"),
|
|
||||||
idCliente = rs.getLong("id_cliente"),
|
|
||||||
idArticolo = rs.getLong("id_articolo"),
|
|
||||||
idMagazzino = rs.getLong("id_magazzino"),
|
|
||||||
magazzino = rs.getString("magazzino"),
|
|
||||||
valoreCarcassa = rs.getDouble("valore_carcassa"),
|
|
||||||
prezzo = rs.getDouble("prezzo"),
|
|
||||||
sconto = rs.getDouble("sconto"),
|
|
||||||
sconto1 = rs.getDouble("sconto_1"),
|
|
||||||
sconto2 = rs.getDouble("sconto_2"),
|
|
||||||
sconto3 = rs.getDouble("sconto_3"),
|
|
||||||
netto = rs.getDouble("netto"),
|
|
||||||
numeroPezzi = rs.getInt("numero_pezzi")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
list.add(element)
|
|
||||||
|
|
||||||
}
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
result?.ifEmpty { emptyList() }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ViewEcommerceValoreUsato(
|
|
||||||
val id : Long,
|
|
||||||
val idCliente : Long,
|
|
||||||
val idArticolo : Long,
|
|
||||||
val valoreUsato : Double
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
interface ViewEcommerceValoreUsatoRepository {
|
|
||||||
suspend fun getValoreByIdArtIdClie(idCliente: Long, idArticolo : Long ): List<ViewEcommerceValoreUsato>?
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package eu.maiora.model
|
|
||||||
|
|
||||||
import eu.maiora.db.*
|
|
||||||
import org.jetbrains.exposed.sql.LongColumnType
|
|
||||||
|
|
||||||
class ViewEcommerceValoreUsatoRepositoryImpl : ViewEcommerceValoreUsatoRepository {
|
|
||||||
override suspend fun getValoreByIdArtIdClie(idCliente: Long, idArticolo : Long): List<ViewEcommerceValoreUsato>? = suspendTransaction {
|
|
||||||
// Cerca il valore della carcassa dalla table function ViewEcommerceValoreUsatoTable
|
|
||||||
|
|
||||||
val result = exec("SELECT * FROM dbo.Get_Valore_usato(?, ?)", listOf(
|
|
||||||
LongColumnType() to idCliente,
|
|
||||||
LongColumnType() to idArticolo
|
|
||||||
)) { rs ->
|
|
||||||
val list = mutableListOf<ViewEcommerceValoreUsato>()
|
|
||||||
while (rs.next()) {
|
|
||||||
val element : ViewEcommerceValoreUsato
|
|
||||||
element = ViewEcommerceValoreUsato(
|
|
||||||
id = rs.getLong("id"),
|
|
||||||
idCliente = rs.getLong("id_cliente"),
|
|
||||||
idArticolo = rs.getLong("id_articolo"),
|
|
||||||
valoreUsato = rs.getDouble("valore_usato")
|
|
||||||
)
|
|
||||||
list.add(element)
|
|
||||||
|
|
||||||
}
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
result?.ifEmpty { emptyList() }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,7 @@
|
|||||||
package eu.maiora.plugins
|
package eu.maiora.plugins
|
||||||
|
|
||||||
import eu.maiora.model.AccountsRepositoryImpl
|
import eu.maiora.model.AccountsRepositoryImpl
|
||||||
import eu.maiora.model.ViewEcommercePrezSconDispRepositoryImpl
|
|
||||||
import eu.maiora.model.ViewEcommerceValoreUsatoRepository
|
|
||||||
import eu.maiora.model.ViewEcommerceValoreUsatoRepositoryImpl
|
|
||||||
import eu.maiora.routes.auth
|
import eu.maiora.routes.auth
|
||||||
import eu.maiora.routes.prezziScontiMagazzino
|
|
||||||
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.*
|
||||||
@ -17,6 +13,5 @@ fun Application.configureRouting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
prezziScontiMagazzino(ViewEcommerceValoreUsatoRepositoryImpl(), ViewEcommercePrezSconDispRepositoryImpl())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
package eu.maiora.routes
|
|
||||||
|
|
||||||
import eu.maiora.model.ViewEcommercePrezSconDisp
|
|
||||||
import eu.maiora.model.ViewEcommercePrezSconDispRepository
|
|
||||||
import eu.maiora.model.ViewEcommerceValoreUsatoRepository
|
|
||||||
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.prezziScontiMagazzino(viewEcommerceValoreUsatoRepository: ViewEcommerceValoreUsatoRepository,
|
|
||||||
viewEcommercePrezSconDispRepository: ViewEcommercePrezSconDispRepository){
|
|
||||||
route("/api/prezziScontiMagazzino"){
|
|
||||||
authenticate("auth-jwt") {
|
|
||||||
get(){
|
|
||||||
// Ottieni l'id articolo dal percorso
|
|
||||||
val idArticolo = call.parameters["idArticolo"]
|
|
||||||
// Ottieni l'id cliente dal percorso
|
|
||||||
val idCliente = call.parameters["idCliente"]
|
|
||||||
|
|
||||||
if (idArticolo.isNullOrEmpty()) {
|
|
||||||
call.respondText("ID articolo non valido", status = HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idCliente.isNullOrEmpty()) {
|
|
||||||
call.respondText("ID cliente non valido", status = HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val dataValoreUsato = viewEcommerceValoreUsatoRepository.getValoreByIdArtIdClie(idCliente.toLong(), idArticolo.toLong())
|
|
||||||
if(!dataValoreUsato.isNullOrEmpty() && dataValoreUsato.size == 1){
|
|
||||||
val data = viewEcommercePrezSconDispRepository.disponibilitaByIdArtIdClie(idCliente.toLong(), idArticolo.toLong())
|
|
||||||
if(!data.isNullOrEmpty()){
|
|
||||||
var listaElementiConValoreUsato = ArrayList<ViewEcommercePrezSconDisp>()
|
|
||||||
data.forEach { e ->
|
|
||||||
val nuovoElemento = e.copy(valoreCarcassa = dataValoreUsato[0].valoreUsato)
|
|
||||||
listaElementiConValoreUsato.add(nuovoElemento)
|
|
||||||
}
|
|
||||||
call.respond(listaElementiConValoreUsato)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
call.respondText("Articolo ecommerce non trovato (prezzi sconti e disponibilita)", status = HttpStatusCode.NotFound)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(dataValoreUsato.isNullOrEmpty()){
|
|
||||||
call.respondText(
|
|
||||||
"Errore nel recupero del valore usato. Nessun record trovato. idArticolo:$idArticolo - idCliente:$idCliente",
|
|
||||||
status = HttpStatusCode.NotFound)
|
|
||||||
}
|
|
||||||
else if(dataValoreUsato.size > 1){
|
|
||||||
call.respondText(
|
|
||||||
"Errore nel recupero del valore usato. Trovati record multipli. idArticolo:$idArticolo - idCliente:$idCliente",
|
|
||||||
status = HttpStatusCode.NotFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
call.respond("OK")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
<!-- Appender per il file di log con rotazione basata su tempo e dimensione -->
|
<!-- Appender per il file di log con rotazione basata su tempo e dimensione -->
|
||||||
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>./log_ecommerce/logFile.log</file> <!-- File di log principale -->
|
<file>./log/logFile.log</file> <!-- File di log principale -->
|
||||||
<append>true</append>
|
<append>true</append>
|
||||||
|
|
||||||
<!-- RollingPolicy per dimensione e tempo -->
|
<!-- RollingPolicy per dimensione e tempo -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
<!-- Pattern per il nome dei file ruotati: include la data -->
|
<!-- Pattern per il nome dei file ruotati: include la data -->
|
||||||
<FileNamePattern>./log_ecommerce/logFile.%d{yyyy-MM-dd}.%i.log</FileNamePattern> <!-- %i è il numero di file generato -->
|
<FileNamePattern>./log/logFile.%d{yyyy-MM-dd}.%i.log</FileNamePattern> <!-- %i è il numero di file generato -->
|
||||||
|
|
||||||
<!-- Limita la dimensione del file a 100MB -->
|
<!-- Limita la dimensione del file a 100MB -->
|
||||||
<maxFileSize>100MB</maxFileSize> <!-- Ruota il file quando raggiunge 100MB -->
|
<maxFileSize>100MB</maxFileSize> <!-- Ruota il file quando raggiunge 100MB -->
|
||||||
|
Loading…
Reference in New Issue
Block a user