Compare commits
7 Commits
main
...
0002700-sp
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b3d5aa322 | |||
| 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)
|
||||
|
||||
@ -3,9 +3,12 @@ package eu.maiora.db
|
||||
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
||||
import eu.maiora.model.Accounts
|
||||
import eu.maiora.model.Parametri
|
||||
import eu.maiora.model.ViewEcommerceArticoli
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.LongEntity
|
||||
import org.jetbrains.exposed.dao.LongEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.dao.id.IdTable
|
||||
import org.jetbrains.exposed.sql.Transaction
|
||||
@ -27,6 +30,12 @@ object ParametriTable : IdTable<Int>("parametri"){
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
object ViewEcommerceArticoliTable : IdTable<Long>("view_ecommerce_articoli"){
|
||||
override val id = long("id").entityId()
|
||||
val codice = varchar("codice", 20)
|
||||
val descrizione = varchar("descrizione", 255)
|
||||
}
|
||||
|
||||
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
||||
|
||||
@ -41,6 +50,13 @@ class ParametriDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||
var valore by ParametriTable.valore
|
||||
}
|
||||
|
||||
class ViewEcommerceArticoliDAO(id:EntityID<Long>) : LongEntity(id){
|
||||
companion object : LongEntityClass<ViewEcommerceArticoliDAO>(ViewEcommerceArticoliTable)
|
||||
|
||||
var codice by ViewEcommerceArticoliTable.codice
|
||||
var descrizione by ViewEcommerceArticoliTable.descrizione
|
||||
}
|
||||
|
||||
|
||||
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
||||
dao.id.value,
|
||||
@ -54,6 +70,12 @@ fun parametriDaoToModel(dao: ParametriDAO) = Parametri(
|
||||
dao.valore
|
||||
)
|
||||
|
||||
fun viewEcommerceArticoliDaoToModel(dao: ViewEcommerceArticoliDAO) = ViewEcommerceArticoli(
|
||||
dao.id.value,
|
||||
dao.codice,
|
||||
dao.descrizione
|
||||
)
|
||||
|
||||
|
||||
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
||||
newSuspendedTransaction(Dispatchers.IO, statement = block)
|
||||
10
src/main/kotlin/eu/maiora/model/ViewEcommerceArticoli.kt
Normal file
10
src/main/kotlin/eu/maiora/model/ViewEcommerceArticoli.kt
Normal file
@ -0,0 +1,10 @@
|
||||
package eu.maiora.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ViewEcommerceArticoli(
|
||||
val id : Long,
|
||||
val codice : String,
|
||||
val descrizione : String
|
||||
)
|
||||
@ -0,0 +1,6 @@
|
||||
package eu.maiora.model
|
||||
|
||||
interface ViewEcommerceArticoliRepository {
|
||||
suspend fun getListaArticoli(): List<ViewEcommerceArticoli>
|
||||
suspend fun getArticoloById(idArticolo : Long): ViewEcommerceArticoli?
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package eu.maiora.model
|
||||
|
||||
import eu.maiora.db.*
|
||||
import eu.maiora.loadConfig
|
||||
import org.jetbrains.exposed.sql.LongColumnType
|
||||
|
||||
class ViewEcommerceArticoliRepositoryImpl : ViewEcommerceArticoliRepository {
|
||||
override suspend fun getListaArticoli(): List<ViewEcommerceArticoli> = suspendTransaction {
|
||||
// Cerca la lista di articoli
|
||||
ViewEcommerceArticoliDAO.all()
|
||||
.toList()
|
||||
.map { viewEcommerceArticoliDaoToModel(it) } // Converte il DAO in un oggetto ViewEcommerceArticoli
|
||||
|
||||
}
|
||||
|
||||
override suspend fun getArticoloById(idArticolo : Long): ViewEcommerceArticoli? = suspendTransaction {
|
||||
// Cerca un articolo dato il suo id
|
||||
ViewEcommerceArticoliDAO.find{ ViewEcommerceArticoliTable.id eq idArticolo }
|
||||
.singleOrNull() // Restituisce un singolo risultato o null se non trovato
|
||||
?.let { viewEcommerceArticoliDaoToModel(it) } // Converte il DAO in un oggetto ViewEcommerceArticoli
|
||||
}
|
||||
}
|
||||
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,9 @@
|
||||
package eu.maiora.plugins
|
||||
|
||||
import eu.maiora.model.AccountsRepositoryImpl
|
||||
import eu.maiora.model.*
|
||||
import eu.maiora.routes.auth
|
||||
import eu.maiora.routes.prezziScontiMagazzino
|
||||
import eu.maiora.routes.viewEcommerceArticoli
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
@ -13,5 +15,7 @@ fun Application.configureRouting() {
|
||||
}
|
||||
|
||||
auth(AccountsRepositoryImpl())
|
||||
prezziScontiMagazzino(ViewEcommerceValoreUsatoRepositoryImpl(), ViewEcommercePrezSconDispRepositoryImpl())
|
||||
viewEcommerceArticoli(ViewEcommerceArticoliRepositoryImpl())
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/main/kotlin/eu/maiora/routes/ViewEcommerceArticoli.kt
Normal file
42
src/main/kotlin/eu/maiora/routes/ViewEcommerceArticoli.kt
Normal file
@ -0,0 +1,42 @@
|
||||
package eu.maiora.routes
|
||||
|
||||
import eu.maiora.model.ViewEcommerceArticoliRepository
|
||||
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.viewEcommerceArticoli(viewEcommerceArticoliRepository: ViewEcommerceArticoliRepository){
|
||||
route("/api/articoli"){
|
||||
authenticate("auth-jwt") {
|
||||
get("{id?}"){
|
||||
// Ottieni l'id articolo dal percorso
|
||||
val idArticolo = call.parameters["id"]
|
||||
|
||||
if(idArticolo != null){
|
||||
val id = idArticolo.toLongOrNull()
|
||||
if(id == null) {
|
||||
call.respondText("ID articolo non valido", status = HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
//restituisco il singolo articolo se disponibile
|
||||
val articolo = viewEcommerceArticoliRepository.getArticoloById(idArticolo.toLong())
|
||||
if(articolo == null){
|
||||
call.respondText("Articolo non esistente", status = HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
call.respond(articolo)
|
||||
}
|
||||
else {
|
||||
//restituisco la lista articoli completa
|
||||
val articoli = viewEcommerceArticoliRepository.getListaArticoli()
|
||||
call.respond(articoli)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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