Compare commits
3 Commits
main
...
0002313-we
Author | SHA1 | Date | |
---|---|---|---|
788d52cbbc | |||
0103863e8b | |||
fabdbfd32a |
@ -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_FAER"
|
||||||
|
|
||||||
|
@ -13,22 +13,20 @@ import java.io.FileInputStream
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val properties = loadConfig()
|
embeddedServer(Netty, port = 8098, host = "0.0.0.0", module = Application::module)
|
||||||
val port = properties.getProperty("server.port").toInt()
|
.start(wait = true)
|
||||||
embeddedServer(Netty, port = port, host = "0.0.0.0") {
|
|
||||||
module(properties)
|
|
||||||
}.start(wait = true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Application.module(configFile: Properties) {
|
fun Application.module() {
|
||||||
val config = ApplicationConfig("application.conf")
|
val config = ApplicationConfig("application.conf")
|
||||||
|
val configFile = loadConfig()
|
||||||
val dbUrl = configFile.getProperty("ktor.database.url")
|
val dbUrl = configFile.getProperty("ktor.database.url")
|
||||||
val username = configFile.getProperty("ktor.database.username")
|
val username = configFile.getProperty("ktor.database.username")
|
||||||
val password = configFile.getProperty("ktor.database.password")
|
val password = configFile.getProperty("ktor.database.password")
|
||||||
val secret = config.property("ktor.jwt.secret").getString()
|
val secret = config.property("ktor.jwt.secret").getString()
|
||||||
configureDatabases(dbUrl, username, password)
|
configureDatabases(dbUrl, username, password)
|
||||||
configureSecurity(secret)
|
configureSecurity(secret)
|
||||||
configureRouting()
|
configureRouting(dbUrl, username, password)
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
|
|
||||||
install(CallLogging)
|
install(CallLogging)
|
||||||
@ -47,7 +45,7 @@ fun Application.module(configFile: Properties) {
|
|||||||
|
|
||||||
fun loadConfig(): Properties {
|
fun loadConfig(): Properties {
|
||||||
val properties = Properties()
|
val properties = Properties()
|
||||||
val inputStream = FileInputStream("/home/backend_api/config.properties")
|
val inputStream = FileInputStream("/home/ristocloudadm/config.properties")
|
||||||
properties.load(inputStream)
|
properties.load(inputStream)
|
||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package eu.maiora.db
|
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.db.AccountsTable.entityId
|
||||||
import eu.maiora.model.Parametri
|
import eu.maiora.db.ViewEcommercePrezSconDispTable.double
|
||||||
|
import eu.maiora.db.ViewEcommercePrezSconDispTable.integer
|
||||||
|
import eu.maiora.db.ViewEcommercePrezSconDispTable.long
|
||||||
|
import eu.maiora.db.ViewEcommercePrezSconDispTable.varchar
|
||||||
|
import eu.maiora.model.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.jetbrains.exposed.dao.IntEntity
|
import org.jetbrains.exposed.dao.*
|
||||||
import org.jetbrains.exposed.dao.IntEntityClass
|
|
||||||
import org.jetbrains.exposed.dao.id.EntityID
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
import org.jetbrains.exposed.dao.id.IdTable
|
import org.jetbrains.exposed.dao.id.IdTable
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
import org.jetbrains.exposed.sql.Transaction
|
import org.jetbrains.exposed.sql.Transaction
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
|
|
||||||
@ -19,6 +23,43 @@ object AccountsTable : IdTable<Int>("accounts"){
|
|||||||
override val primaryKey = PrimaryKey(id)
|
override val primaryKey = PrimaryKey(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object ArticoliCrossQRicambiTable : IdTable<Int>("articoli_cross_qricambi"){
|
||||||
|
override val id = ArticoliCrossQRicambiTable.integer("id").entityId()
|
||||||
|
val codiceArticolo = varchar("codice_articolo", 50)
|
||||||
|
val codiceCross = varchar("codice_cross", 50)
|
||||||
|
val tipo = varchar("tipo", 2)
|
||||||
|
val costruttore = varchar("costruttore", 50)
|
||||||
|
}
|
||||||
|
|
||||||
|
object ViewEcommerceArticoliTable : IdTable<Long>("view_ecommerce_articoli"){
|
||||||
|
override val id = ViewEcommerceArticoliTable.long("id").entityId()
|
||||||
|
val codice = varchar("codice", 20)
|
||||||
|
val descrizione = varchar("descrizione", 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
object ViewClientiAgentiTable : IdTable<Long>("view_clienti_agenti"){
|
||||||
|
override val id = ViewClientiAgentiTable.long("id_cliente").entityId()
|
||||||
|
val cliente = varchar("cliente", 255)
|
||||||
|
val idAgente = long("id_agente")
|
||||||
|
val username = varchar("username", 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
object ViewEcommercePrezSconDispTable : IdTable<Long>("view_ecommerce_prez_scon_disp"){
|
||||||
|
override val id = ViewEcommercePrezSconDispTable.long("id").entityId()
|
||||||
|
val idCliente = long("id_cliente")
|
||||||
|
val idArticolo = long("id_articolo")
|
||||||
|
val idMagazzino = long("id_magazzino")
|
||||||
|
val magazzino = varchar("magazzino", 255)
|
||||||
|
val valoreCarcassa = double("valore_carcassa")
|
||||||
|
val prezzo = double("prezzo")
|
||||||
|
val sconto = double("sconto")
|
||||||
|
val sconto1 = double("sconto_1")
|
||||||
|
val sconto2 = double("sconto_2")
|
||||||
|
val sconto3 = double("sconto_3")
|
||||||
|
val netto = double("netto")
|
||||||
|
val numeroPezzi = integer("numero_pezzi")
|
||||||
|
}
|
||||||
|
|
||||||
object ParametriTable : IdTable<Int>("parametri"){
|
object ParametriTable : IdTable<Int>("parametri"){
|
||||||
override val id = integer("id").entityId()
|
override val id = integer("id").entityId()
|
||||||
val chiave = varchar("chiave", 255)
|
val chiave = varchar("chiave", 255)
|
||||||
@ -34,6 +75,47 @@ class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
|||||||
var password by AccountsTable.password
|
var password by AccountsTable.password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ArticoliCrossQRicambiDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
|
companion object : IntEntityClass<ArticoliCrossQRicambiDAO>(ArticoliCrossQRicambiTable)
|
||||||
|
|
||||||
|
var codiceArticolo by ArticoliCrossQRicambiTable.codiceArticolo
|
||||||
|
var codiceCross by ArticoliCrossQRicambiTable.codiceCross
|
||||||
|
var tipo by ArticoliCrossQRicambiTable.tipo
|
||||||
|
var costruttore by ArticoliCrossQRicambiTable.costruttore
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewEcommerceArticoliDAO(id: EntityID<Long>) :LongEntity(id) {
|
||||||
|
companion object : LongEntityClass<ViewEcommerceArticoliDAO>(ViewEcommerceArticoliTable)
|
||||||
|
|
||||||
|
var codice by ViewEcommerceArticoliTable.codice
|
||||||
|
var descrizione by ViewEcommerceArticoliTable.descrizione
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewClientiAgentiDAO(id: EntityID<Long>) :LongEntity(id) {
|
||||||
|
companion object : LongEntityClass<ViewClientiAgentiDAO>(ViewClientiAgentiTable)
|
||||||
|
|
||||||
|
var cliente by ViewClientiAgentiTable.cliente
|
||||||
|
var idAgente by ViewClientiAgentiTable.idAgente
|
||||||
|
var username by ViewClientiAgentiTable.username
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewEcommercePrezSconDispDAO(id: EntityID<Long>) :LongEntity(id) {
|
||||||
|
companion object : LongEntityClass<ViewEcommercePrezSconDispDAO>(ViewEcommercePrezSconDispTable)
|
||||||
|
|
||||||
|
val idCliente by ViewEcommercePrezSconDispTable.idCliente
|
||||||
|
val idArticolo by ViewEcommercePrezSconDispTable.idArticolo
|
||||||
|
val idMagazzino by ViewEcommercePrezSconDispTable.idMagazzino
|
||||||
|
val magazzino by ViewEcommercePrezSconDispTable.magazzino
|
||||||
|
val valoreCarcassa by ViewEcommercePrezSconDispTable.valoreCarcassa
|
||||||
|
val prezzo by ViewEcommercePrezSconDispTable.prezzo
|
||||||
|
val sconto by ViewEcommercePrezSconDispTable.sconto
|
||||||
|
val sconto1 by ViewEcommercePrezSconDispTable.sconto1
|
||||||
|
val sconto2 by ViewEcommercePrezSconDispTable.sconto2
|
||||||
|
val sconto3 by ViewEcommercePrezSconDispTable.sconto3
|
||||||
|
val netto by ViewEcommercePrezSconDispTable.netto
|
||||||
|
val numeroPezzi by ViewEcommercePrezSconDispTable.numeroPezzi
|
||||||
|
}
|
||||||
|
|
||||||
class ParametriDAO(id: EntityID<Int>) :IntEntity(id) {
|
class ParametriDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
companion object : IntEntityClass<ParametriDAO>(ParametriTable)
|
companion object : IntEntityClass<ParametriDAO>(ParametriTable)
|
||||||
|
|
||||||
@ -48,6 +130,43 @@ fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
|||||||
dao.password
|
dao.password
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun articoliCrossQRicambiDaoToModel(dao: ArticoliCrossQRicambiDAO) = ArticoliCrossQRicambi(
|
||||||
|
dao.id.value,
|
||||||
|
dao.codiceArticolo,
|
||||||
|
dao.codiceCross,
|
||||||
|
dao.tipo,
|
||||||
|
dao.costruttore
|
||||||
|
)
|
||||||
|
|
||||||
|
fun viewEcommerceArticoliDaoToModel(dao: ViewEcommerceArticoliDAO) = ViewEcommerceArticoli(
|
||||||
|
dao.id.value,
|
||||||
|
dao.codice,
|
||||||
|
dao.descrizione
|
||||||
|
)
|
||||||
|
|
||||||
|
fun viewClientiAgentiDaoToModel(dao: ViewClientiAgentiDAO) = ViewClientiAgenti(
|
||||||
|
dao.id.value,
|
||||||
|
dao.cliente,
|
||||||
|
dao.idAgente,
|
||||||
|
dao.username
|
||||||
|
)
|
||||||
|
|
||||||
|
fun viewEcommercePrezSconDispDaoToModel(dao: ViewEcommercePrezSconDispDAO) = ViewEcommercePrezSconDisp(
|
||||||
|
dao.id.value,
|
||||||
|
dao.idCliente,
|
||||||
|
dao.idArticolo,
|
||||||
|
dao.idMagazzino,
|
||||||
|
dao.magazzino,
|
||||||
|
dao.valoreCarcassa,
|
||||||
|
dao.prezzo,
|
||||||
|
dao.sconto,
|
||||||
|
dao.sconto1,
|
||||||
|
dao.sconto2,
|
||||||
|
dao.sconto3,
|
||||||
|
dao.netto,
|
||||||
|
dao.numeroPezzi
|
||||||
|
)
|
||||||
|
|
||||||
fun parametriDaoToModel(dao: ParametriDAO) = Parametri(
|
fun parametriDaoToModel(dao: ParametriDAO) = Parametri(
|
||||||
dao.id.value,
|
dao.id.value,
|
||||||
dao.chiave,
|
dao.chiave,
|
||||||
|
13
src/main/kotlin/eu/maiora/model/ArticoliCrossQRicambi.kt
Normal file
13
src/main/kotlin/eu/maiora/model/ArticoliCrossQRicambi.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ArticoliCrossQRicambi(
|
||||||
|
val id : Int,
|
||||||
|
val codiceArticolo : String,
|
||||||
|
val codiceCross : String,
|
||||||
|
val costruttore : String,
|
||||||
|
val tipo : String
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
interface ArticoliCrossQRicambiRepository {
|
||||||
|
suspend fun articoloByCodArt(codice : String): List<ArticoliCrossQRicambi>
|
||||||
|
//suspend fun articoloByCodCross(codice : String): ArticoliCrossQRicambi?
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.or
|
||||||
|
|
||||||
|
class ArticoliCrossQRicambiRepositoryImpl : ArticoliCrossQRicambiRepository {
|
||||||
|
override suspend fun articoloByCodArt(codice: String): List<ArticoliCrossQRicambi> = suspendTransaction {
|
||||||
|
// Cerca un articolo dalla tabella ArticoliCrossQRicambiTable
|
||||||
|
ArticoliCrossQRicambiDAO.find { (ArticoliCrossQRicambiTable.codiceArticolo eq codice) or (ArticoliCrossQRicambiTable.codiceCross eq codice) }
|
||||||
|
.toList() // Restituisce un singolo risultato o null se non trovato
|
||||||
|
.map { articoliCrossQRicambiDaoToModel(it) } // Converte il DAO in un oggetto ArticoliCrossQRicambi
|
||||||
|
|
||||||
|
}
|
||||||
|
/*override suspend fun articoloByCodCross(codice: String): ArticoliCrossQRicambi? = suspendTransaction {
|
||||||
|
// Cerca un articolo dalla tabella ArticoliCrossQRicambiTable
|
||||||
|
ArticoliCrossQRicambiDAO.find { ArticoliCrossQRicambiTable.codiceCross eq codice }
|
||||||
|
.singleOrNull() // Restituisce un singolo risultato o null se non trovato
|
||||||
|
?.let { articoliCrossQRicambiDaoToModel(it) } // Converte il DAO in un oggetto ArticoliCrossQRicambi
|
||||||
|
|
||||||
|
}*/
|
||||||
|
}
|
15
src/main/kotlin/eu/maiora/model/DisponibilitaArticoli.kt
Normal file
15
src/main/kotlin/eu/maiora/model/DisponibilitaArticoli.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class DisponibilitaArticoli(
|
||||||
|
val codiceArticolo : String,
|
||||||
|
val descrizione : String,
|
||||||
|
val costruttore : String,
|
||||||
|
val prezzoNetto : String,
|
||||||
|
val isDisponibile: Boolean,
|
||||||
|
val disponibilita : List<NumPezziPerMagazzino>,
|
||||||
|
val costoCarcassa: String
|
||||||
|
)
|
||||||
|
|
10
src/main/kotlin/eu/maiora/model/NumPezziPerMagazzino.kt
Normal file
10
src/main/kotlin/eu/maiora/model/NumPezziPerMagazzino.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class NumPezziPerMagazzino(
|
||||||
|
val nomeMagazzino : String,
|
||||||
|
val numeroPezziDisponibili : String
|
||||||
|
)
|
||||||
|
|
12
src/main/kotlin/eu/maiora/model/ViewClientiAgenti.kt
Normal file
12
src/main/kotlin/eu/maiora/model/ViewClientiAgenti.kt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ViewClientiAgenti(
|
||||||
|
val idCliente : Long,
|
||||||
|
val cliente : String,
|
||||||
|
val idAgente: Long,
|
||||||
|
val username: String
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
interface ViewClientiAgentiRepository {
|
||||||
|
suspend fun clienteByAgente(username : String): ViewClientiAgenti?
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.or
|
||||||
|
|
||||||
|
class ViewClientiAgentiRepositoryImpl : ViewClientiAgentiRepository {
|
||||||
|
override suspend fun clienteByAgente(username: String): ViewClientiAgenti? = suspendTransaction {
|
||||||
|
// Cerca un cliente dalla tabella ViewClientiAgenti
|
||||||
|
ViewClientiAgentiDAO.find { ViewClientiAgentiTable.username eq username }
|
||||||
|
.singleOrNull() // Restituisce un singolo risultato o null se non trovato
|
||||||
|
?.let { viewClientiAgentiDaoToModel(it) } // Converte il DAO in un oggetto ViewClientiAgenti
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
src/main/kotlin/eu/maiora/model/ViewEcommerceArticoli.kt
Normal file
11
src/main/kotlin/eu/maiora/model/ViewEcommerceArticoli.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ViewEcommerceArticoli(
|
||||||
|
val id : Long,
|
||||||
|
val codice : String,
|
||||||
|
val descrizione: String
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
interface ViewEcommerceArticoliRepository {
|
||||||
|
suspend fun articoloByCodice(codice : String): ViewEcommerceArticoli?
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.or
|
||||||
|
|
||||||
|
class ViewEcommerceArticoliRepositoryImpl : ViewEcommerceArticoliRepository {
|
||||||
|
override suspend fun articoloByCodice(codice: String): ViewEcommerceArticoli? = suspendTransaction {
|
||||||
|
// Cerca un articolo dalla tabella ViewEcommerceArticoliTable
|
||||||
|
ViewEcommerceArticoliDAO.find { ViewEcommerceArticoliTable.codice eq codice }
|
||||||
|
.singleOrNull() // Restituisce un singolo risultato o null se non trovato
|
||||||
|
?.let { viewEcommerceArticoliDaoToModel(it) } // Converte il DAO in un oggetto ViewEcommerceArticoli
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
21
src/main/kotlin/eu/maiora/model/ViewEcommercePrezSconDisp.kt
Normal file
21
src/main/kotlin/eu/maiora/model/ViewEcommercePrezSconDisp.kt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
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,69 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.Expression
|
||||||
|
import org.jetbrains.exposed.sql.LongColumnType
|
||||||
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
|
import org.jetbrains.exposed.sql.or
|
||||||
|
|
||||||
|
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
|
||||||
|
/*ViewEcommercePrezSconDispDAO.find { ViewEcommerceArticoliTable.codice eq codice }
|
||||||
|
.toList() // Restituisce un singolo risultato o null se non trovato
|
||||||
|
.map { viewEcommerceArticoliDaoToModel(it) } // Converte il DAO in un oggetto ViewEcommerceArticoli
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 == 10000023706){
|
||||||
|
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() }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
12
src/main/kotlin/eu/maiora/model/ViewEcommerceValoreUsato.kt
Normal file
12
src/main/kotlin/eu/maiora/model/ViewEcommerceValoreUsato.kt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
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,56 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
import org.jetbrains.exposed.sql.Expression
|
||||||
|
import org.jetbrains.exposed.sql.LongColumnType
|
||||||
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
|
import org.jetbrains.exposed.sql.or
|
||||||
|
|
||||||
|
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
|
||||||
|
//if(idCliente == 10000023706){
|
||||||
|
element = ViewEcommerceValoreUsato(
|
||||||
|
id = rs.getLong("id"),
|
||||||
|
idCliente = rs.getLong("id_cliente"),
|
||||||
|
idArticolo = rs.getLong("id_articolo"),
|
||||||
|
valoreUsato = rs.getDouble("valore_usato")
|
||||||
|
)
|
||||||
|
//}
|
||||||
|
//else {
|
||||||
|
/*element = ViewEcommerceValoreUsato(
|
||||||
|
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,17 +1,23 @@
|
|||||||
package eu.maiora.plugins
|
package eu.maiora.plugins
|
||||||
|
|
||||||
import eu.maiora.model.AccountsRepositoryImpl
|
import eu.maiora.model.*
|
||||||
import eu.maiora.routes.auth
|
import eu.maiora.routes.auth
|
||||||
|
import eu.maiora.routes.disponibilitaArticoli
|
||||||
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.*
|
||||||
|
|
||||||
fun Application.configureRouting() {
|
fun Application.configureRouting(dbUrl : String, username : String, password : String) {
|
||||||
routing {
|
routing {
|
||||||
get("/") {
|
get("/") {
|
||||||
call.respondText("Hello World!")
|
call.respondText("Hello World!")
|
||||||
}
|
}
|
||||||
|
|
||||||
auth(AccountsRepositoryImpl())
|
auth(AccountsRepositoryImpl())
|
||||||
|
disponibilitaArticoli(ArticoliCrossQRicambiRepositoryImpl(),
|
||||||
|
ViewEcommerceArticoliRepositoryImpl(),
|
||||||
|
ViewEcommercePrezSconDispRepositoryImpl(),
|
||||||
|
ViewClientiAgentiRepositoryImpl(),
|
||||||
|
ViewEcommerceValoreUsatoRepositoryImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import java.util.*
|
|||||||
|
|
||||||
|
|
||||||
fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
||||||
route("/api/auth") {
|
route("/auth") {
|
||||||
post() {
|
post() {
|
||||||
// Riceve il body della richiesta e lo deserializza in ReceivedResponse
|
// Riceve il body della richiesta e lo deserializza in ReceivedResponse
|
||||||
val receivedResponse = try {
|
val receivedResponse = try {
|
||||||
@ -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)
|
||||||
|
150
src/main/kotlin/eu/maiora/routes/DisponibilitaArticoli.kt
Normal file
150
src/main/kotlin/eu/maiora/routes/DisponibilitaArticoli.kt
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package eu.maiora.routes
|
||||||
|
|
||||||
|
import eu.maiora.model.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.auth.jwt.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
|
||||||
|
fun Route.disponibilitaArticoli(articoliCrossQRicambiRepository: ArticoliCrossQRicambiRepository,
|
||||||
|
viewEcommerceArticoliRepository: ViewEcommerceArticoliRepository,
|
||||||
|
viewEcommercePrezSconDispRepository: ViewEcommercePrezSconDispRepository,
|
||||||
|
viewClientiAgentiRepository : ViewClientiAgentiRepository,
|
||||||
|
viewEcommerceValoreUsatoRepository: ViewEcommerceValoreUsatoRepository){
|
||||||
|
route("/api/disponibilitaArticoli"){
|
||||||
|
authenticate("auth-jwt") {
|
||||||
|
get("{codiceArticolo}"){
|
||||||
|
val username = call.authentication.principal<JWTPrincipal>()?.payload?.subject ?: ""
|
||||||
|
|
||||||
|
// Ottieni il codice articolo dal percorso
|
||||||
|
val codiceArticolo = call.parameters["codiceArticolo"]
|
||||||
|
|
||||||
|
if (codiceArticolo == null) {
|
||||||
|
call.respondText("Codice articolo non valido", status = HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO verifica utente loggato: se è qricambi partner, richiesta generica,
|
||||||
|
// altrimenti richiesta puntuale
|
||||||
|
// al momento gestiamo solo richiesta generica per tutti
|
||||||
|
|
||||||
|
//ricerca del codice articolo
|
||||||
|
//- verifico che il codice esista nel sistema interno, ovvero nella tabella ARTICOLI_CROSS_QRICAMBI
|
||||||
|
// la ricerca va effettuata prima per CODICE_ARTICOLO e poi per CODICE_CROSS
|
||||||
|
//- se non esiste, restituisco not found
|
||||||
|
//- altrimenti, recupero l'id dell'articolo dalla vista VIEW_ECOMMERCE_ARTICOLI
|
||||||
|
// e tutti i dati da mostrare (vedi GET_PREZ_SCON_DISP, named query in ViewEcommercePrezSconDisp)
|
||||||
|
|
||||||
|
if(username.equals("qricambi")){
|
||||||
|
val idClienteQRicambi = 10000023706
|
||||||
|
val listArticoliCrossQRicambi = articoliCrossQRicambiRepository.articoloByCodArt(codiceArticolo)
|
||||||
|
if(listArticoliCrossQRicambi.isNotEmpty()){
|
||||||
|
//call.respond(listArticoliCrossQRicambi)
|
||||||
|
val articoloEcommerce = viewEcommerceArticoliRepository.articoloByCodice(listArticoliCrossQRicambi[0].codiceArticolo)
|
||||||
|
if(articoloEcommerce != null){
|
||||||
|
//call.respond(articoloEcommerce)
|
||||||
|
val dataValoreUsato = viewEcommerceValoreUsatoRepository.getValoreByIdArtIdClie(idClienteQRicambi, articoloEcommerce.id)
|
||||||
|
val data = viewEcommercePrezSconDispRepository.disponibilitaByIdArtIdClie(idClienteQRicambi, articoloEcommerce.id)
|
||||||
|
if(data != null){
|
||||||
|
var listNumPezziPerMagazzino = ArrayList<NumPezziPerMagazzino>()
|
||||||
|
/*data.forEach { e ->
|
||||||
|
listNumPezziPerMagazzino.add(NumPezziPerMagazzino(e.magazzino, e.numeroPezzi.toString()))
|
||||||
|
}*/
|
||||||
|
var numPezziDisponibili = 0;
|
||||||
|
data.forEach { e ->
|
||||||
|
numPezziDisponibili += e.numeroPezzi
|
||||||
|
}
|
||||||
|
listNumPezziPerMagazzino.add(NumPezziPerMagazzino("", numPezziDisponibili.toString()))
|
||||||
|
|
||||||
|
val result = DisponibilitaArticoli(articoloEcommerce.codice,
|
||||||
|
articoloEcommerce.descrizione,
|
||||||
|
listArticoliCrossQRicambi[0].costruttore,
|
||||||
|
data[0].netto.toString(),
|
||||||
|
data[0].numeroPezzi > 0,
|
||||||
|
listNumPezziPerMagazzino,
|
||||||
|
(dataValoreUsato?.firstOrNull()?.valoreUsato ?: "0.0").toString()
|
||||||
|
)
|
||||||
|
call.respond(result)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo ecommerce non trovato (prezzi sconti e disponibilita)", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo ecommerce non trovato", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo non trovato", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//verificare il cliente collegato all'agente/username
|
||||||
|
val cliente = viewClientiAgentiRepository.clienteByAgente(username)
|
||||||
|
if(cliente != null){
|
||||||
|
val listArticoliCrossQRicambi = articoliCrossQRicambiRepository.articoloByCodArt(codiceArticolo)
|
||||||
|
if(!listArticoliCrossQRicambi.isEmpty()){
|
||||||
|
//call.respond(listArticoliCrossQRicambi)
|
||||||
|
val articoloEcommerce = viewEcommerceArticoliRepository.articoloByCodice(listArticoliCrossQRicambi[0].codiceArticolo)
|
||||||
|
if(articoloEcommerce != null){
|
||||||
|
//call.respond(articoloEcommerce)
|
||||||
|
val dataValoreUsato = viewEcommerceValoreUsatoRepository.getValoreByIdArtIdClie(cliente.idCliente, articoloEcommerce.id)
|
||||||
|
val data = viewEcommercePrezSconDispRepository.disponibilitaByIdArtIdClie(cliente.idCliente, articoloEcommerce.id)
|
||||||
|
if(!data.isNullOrEmpty()){
|
||||||
|
var listNumPezziPerMagazzino = ArrayList<NumPezziPerMagazzino>()
|
||||||
|
data.forEach { e ->
|
||||||
|
listNumPezziPerMagazzino.add(NumPezziPerMagazzino(e.magazzino, e.numeroPezzi.toString()))
|
||||||
|
}
|
||||||
|
//var numPezziDisponibili = 0;
|
||||||
|
/*data.forEach { e ->
|
||||||
|
numPezziDisponibili += e.numeroPezzi
|
||||||
|
}*/
|
||||||
|
//listNumPezziPerMagazzino.add(NumPezziPerMagazzino("", numPezziDisponibili.toString()))
|
||||||
|
|
||||||
|
val result = DisponibilitaArticoli(articoloEcommerce.codice,
|
||||||
|
articoloEcommerce.descrizione,
|
||||||
|
listArticoliCrossQRicambi[0].costruttore,
|
||||||
|
data[0].netto.toString(),
|
||||||
|
data[0].numeroPezzi > 0,
|
||||||
|
listNumPezziPerMagazzino,
|
||||||
|
dataValoreUsato?.get(0)?.valoreUsato.toString()
|
||||||
|
)
|
||||||
|
call.respond(result)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo ecommerce non trovato (prezzi sconti e disponibilita)", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo ecommerce non trovato", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Articolo non trovato", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Cliente collegato all'agente non trovato", status = HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cerca la tessera per codice fiscale
|
||||||
|
//val listaMovimenti = movimentiRepository.movimentiByIdTessera(idTessera.toLong())
|
||||||
|
|
||||||
|
|
||||||
|
/*if (listaMovimenti != null) {
|
||||||
|
call.respond(listaMovimenti)
|
||||||
|
} else {
|
||||||
|
call.respondText("Movimenti non trovati", status = HttpStatusCode.NotFound)
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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