forked from maiora/backend-api
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
fe3011a9fc | |||
d99190326b | |||
550e28f871 | |||
10f76edde1 | |||
5f8eb3882f | |||
a6dbb27f7f |
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
|
||||
}
|
||||
rootProject.name = "Backend_API"
|
||||
rootProject.name = "Backend_API_FAER_ecommerce"
|
||||
|
||||
|
@ -14,7 +14,7 @@ import java.util.*
|
||||
|
||||
fun main() {
|
||||
val properties = loadConfig()
|
||||
val port = properties.getProperty("server.port").toInt()
|
||||
val port = properties.getProperty("server.ecommerce.port").toInt()
|
||||
embeddedServer(Netty, port = port, host = "0.0.0.0") {
|
||||
module(properties)
|
||||
}.start(wait = true)
|
||||
|
20
src/main/kotlin/eu/maiora/model/ViewEcommercePrezSconDisp.kt
Normal file
20
src/main/kotlin/eu/maiora/model/ViewEcommercePrezSconDisp.kt
Normal file
@ -0,0 +1,20 @@
|
||||
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
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
package eu.maiora.model
|
||||
|
||||
interface ViewEcommercePrezSconDispRepository {
|
||||
suspend fun disponibilitaByIdArtIdClie(idCliente: Long, idArticolo : Long ): List<ViewEcommercePrezSconDisp>?
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
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() }
|
||||
|
||||
}
|
||||
}
|
11
src/main/kotlin/eu/maiora/model/ViewEcommerceValoreUsato.kt
Normal file
11
src/main/kotlin/eu/maiora/model/ViewEcommerceValoreUsato.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package eu.maiora.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ViewEcommerceValoreUsato(
|
||||
val id : Long,
|
||||
val idCliente : Long,
|
||||
val idArticolo : Long,
|
||||
val valoreUsato : Double
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
package eu.maiora.model
|
||||
|
||||
interface ViewEcommerceValoreUsatoRepository {
|
||||
suspend fun getValoreByIdArtIdClie(idCliente: Long, idArticolo : Long ): List<ViewEcommerceValoreUsato>?
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
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,7 +1,11 @@
|
||||
package eu.maiora.plugins
|
||||
|
||||
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.prezziScontiMagazzino
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
@ -13,5 +17,6 @@ fun Application.configureRouting() {
|
||||
}
|
||||
|
||||
auth(AccountsRepositoryImpl())
|
||||
prezziScontiMagazzino(ViewEcommerceValoreUsatoRepositoryImpl(), ViewEcommercePrezSconDispRepositoryImpl())
|
||||
}
|
||||
}
|
||||
|
74
src/main/kotlin/eu/maiora/routes/PrezziScontiMagazzino.kt
Normal file
74
src/main/kotlin/eu/maiora/routes/PrezziScontiMagazzino.kt
Normal file
@ -0,0 +1,74 @@
|
||||
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 name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>./log/logFile.log</file> <!-- File di log principale -->
|
||||
<file>./log_ecommerce/logFile.log</file> <!-- File di log principale -->
|
||||
<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 -->
|
||||
<FileNamePattern>./log_ecommerce/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 -->
|
||||
|
Loading…
Reference in New Issue
Block a user