forked from maiora/backend-api
Compare commits
No commits in common. "ab56a26f579cf78bc5a406127f18a78719d887a4" and "80aa4afd57aaba3db1680dcda8a8c7537dc487f4" have entirely different histories.
ab56a26f57
...
80aa4afd57
@ -1,6 +1,5 @@
|
||||
package eu.maiora.model
|
||||
|
||||
interface MovimentiRepository {
|
||||
suspend fun movimentiByIdTessera(idTessera : Long, limit : Long, offset : Long, order : String): List<Movimenti>?
|
||||
suspend fun countMovimentiByIdTessera(idTessera : Long): Int
|
||||
suspend fun movimentiByIdTessera(idTessera : Long): List<Movimenti>?
|
||||
}
|
@ -4,32 +4,12 @@ import eu.maiora.db.*
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
|
||||
class MovimentiRepositoryImpl : MovimentiRepository {
|
||||
override suspend fun movimentiByIdTessera(idTessera : Long,
|
||||
limit : Long,
|
||||
offset : Long,
|
||||
order : String): List<Movimenti> = suspendTransaction {
|
||||
|
||||
val sortOrder = when (order) {
|
||||
"asc" -> SortOrder.ASC
|
||||
"desc" -> SortOrder.DESC
|
||||
else -> SortOrder.DESC // Default a DESC in caso di valore invalido
|
||||
}
|
||||
|
||||
override suspend fun movimentiByIdTessera(idTessera : Long): List<Movimenti> = suspendTransaction {
|
||||
// Cerca la lista di movimenti
|
||||
MovimentiDao.find { MovimentiTable.idTessera eq idTessera }
|
||||
.orderBy(MovimentiTable.dataMovimento to sortOrder)
|
||||
.limit(limit.toInt())
|
||||
.offset(offset)
|
||||
.orderBy(MovimentiTable.dataMovimento to SortOrder.DESC)
|
||||
.toList() // Restituisce la lista dei movimenti
|
||||
.map { movimentiDaoToModel(it) } // Converte il DAO in un oggetto Movimenti
|
||||
|
||||
}
|
||||
|
||||
override suspend fun countMovimentiByIdTessera(idTessera : Long): Int = suspendTransaction {
|
||||
// Conta il numero totale di movimenti della tessera
|
||||
MovimentiDao.find { MovimentiTable.idTessera eq idTessera }
|
||||
.toList() // Restituisce la lista dei movimenti
|
||||
.count()
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,5 @@ package eu.maiora.model
|
||||
|
||||
interface ViewPrenotazioniPastiRepository {
|
||||
suspend fun prenotazioniPastiById(id : Long): ViewPrenotazioniPasti
|
||||
suspend fun prenotazioniPastiByIdTessera(idTessera : Long, limit : Long, offset : Long, order : String): List<ViewPrenotazioniPasti>
|
||||
suspend fun countPrenotazioniPastiByIdTessera(idTessera : Long): Int
|
||||
suspend fun prenotazioniPastiByIdTessera(idTessera : Long): List<ViewPrenotazioniPasti>
|
||||
}
|
@ -13,27 +13,12 @@ class ViewPrenotazioniPastiRepositoryImpl : ViewPrenotazioniPastiRepository {
|
||||
.let { viewPrenotazioniPastiDaoToModel(it) } // Converte il DAO in un oggetto ViewPrenotazioniPasti
|
||||
}
|
||||
|
||||
override suspend fun prenotazioniPastiByIdTessera(idTessera : Long, limit : Long, offset : Long, order : String): List<ViewPrenotazioniPasti> = suspendTransaction {
|
||||
val sortOrder = when (order) {
|
||||
"asc" -> SortOrder.ASC
|
||||
"desc" -> SortOrder.DESC
|
||||
else -> SortOrder.DESC // Default a DESC in caso di valore invalido
|
||||
}
|
||||
override suspend fun prenotazioniPastiByIdTessera(idTessera : Long): List<ViewPrenotazioniPasti> = suspendTransaction {
|
||||
// Cerca la lista di prenotazioni
|
||||
ViewPrenotazioniPastiDao.find { ViewPrenotazioniPastiTable.idTessera eq idTessera }
|
||||
.orderBy(ViewPrenotazioniPastiTable.giorno to sortOrder)
|
||||
.limit(limit.toInt())
|
||||
.offset(offset)
|
||||
.orderBy(ViewPrenotazioniPastiTable.giorno to SortOrder.DESC)
|
||||
.toList() // Restituisce la lista delle prenotazioni
|
||||
.map { viewPrenotazioniPastiDaoToModel(it) } // Converte il DAO in un oggetto Movimenti
|
||||
|
||||
}
|
||||
|
||||
override suspend fun countPrenotazioniPastiByIdTessera(idTessera : Long): Int = suspendTransaction {
|
||||
// Conta il numero totale di prenotazioni della tessera
|
||||
ViewPrenotazioniPastiDao.find { ViewPrenotazioniPastiTable.idTessera eq idTessera }
|
||||
.toList() // Restituisce la lista delle prenotazioni
|
||||
.count()
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
package eu.maiora.routes
|
||||
|
||||
import eu.maiora.model.Movimenti
|
||||
import eu.maiora.model.MovimentiRepositoryImpl
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.auth.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
fun Route.movimenti(movimentiRepository: MovimentiRepositoryImpl){
|
||||
@ -16,29 +14,18 @@ fun Route.movimenti(movimentiRepository: MovimentiRepositoryImpl){
|
||||
get("{idTessera}"){
|
||||
// Ottieni l'id della tessera dal percorso
|
||||
val idTessera = call.parameters["idTessera"]
|
||||
var limit = call.parameters["limit"]
|
||||
var offset = call.parameters["offset"]
|
||||
var order = call.parameters["order"]
|
||||
|
||||
if (idTessera == null) {
|
||||
call.respondText("ID tessera non valido", status = HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
if(limit?.toIntOrNull() == null)
|
||||
limit = "20";
|
||||
if(offset?.toIntOrNull() == null)
|
||||
offset = "0";
|
||||
if(order == null)
|
||||
order = "desc"
|
||||
|
||||
// Conta il numero di movimenti della tessera
|
||||
val totalRecords = movimentiRepository.countMovimentiByIdTessera(idTessera.toLong())
|
||||
// Cerca la tessera per codice fiscale
|
||||
val listaMovimenti = movimentiRepository.movimentiByIdTessera(idTessera.toLong(), limit.toLong(), offset.toLong(), order)
|
||||
val listaMovimenti = movimentiRepository.movimentiByIdTessera(idTessera.toLong())
|
||||
|
||||
|
||||
if (listaMovimenti != null) {
|
||||
call.respond(ListaMovimenti(totalRecords, listaMovimenti))
|
||||
call.respond(listaMovimenti)
|
||||
} else {
|
||||
call.respondText("Movimenti non trovati", status = HttpStatusCode.NotFound)
|
||||
}
|
||||
@ -47,6 +34,3 @@ fun Route.movimenti(movimentiRepository: MovimentiRepositoryImpl){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ListaMovimenti (val totalRecords : Int, val listaMovimenti: List<Movimenti>)
|
@ -7,7 +7,6 @@ import io.ktor.server.auth.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
fun Route.prenotazioni(prenotazioniPastiRepository: PrenotazioniPastiRepository,
|
||||
@ -19,30 +18,14 @@ fun Route.prenotazioni(prenotazioniPastiRepository: PrenotazioniPastiRepository,
|
||||
get("{idTessera}"){
|
||||
// Ottieni l'id della tessera dal percorso
|
||||
val idTessera = call.parameters["idTessera"]
|
||||
var limit = call.parameters["limit"]
|
||||
var offset = call.parameters["offset"]
|
||||
var order = call.parameters["order"]
|
||||
|
||||
if (idTessera == null) {
|
||||
call.respondText("ID tessera non valido", status = HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
|
||||
if(limit?.toIntOrNull() == null)
|
||||
limit = "20";
|
||||
if(offset?.toIntOrNull() == null)
|
||||
offset = "0";
|
||||
if(order == null)
|
||||
order = "desc"
|
||||
|
||||
// Conta il numero di prenotazioni per la tessera indicata
|
||||
val totalRecords = viewPrenotazioniPastiRepositoryImpl.countPrenotazioniPastiByIdTessera(idTessera.toLong())
|
||||
|
||||
// Cerca le prenotazioni per la tessera indicata
|
||||
val listaPrenotazioniPasti = viewPrenotazioniPastiRepositoryImpl.prenotazioniPastiByIdTessera(idTessera.toLong(),
|
||||
limit.toLong(),
|
||||
offset.toLong(),
|
||||
order)
|
||||
val listaPrenotazioniPasti = viewPrenotazioniPastiRepositoryImpl.prenotazioniPastiByIdTessera(idTessera.toLong())
|
||||
|
||||
listaPrenotazioniPasti.forEach{ el ->
|
||||
el.listaProdotti =
|
||||
@ -50,7 +33,7 @@ fun Route.prenotazioni(prenotazioniPastiRepository: PrenotazioniPastiRepository,
|
||||
}
|
||||
|
||||
|
||||
call.respond(ListaPrenotazioni(totalRecords, listaPrenotazioniPasti))
|
||||
call.respond(listaPrenotazioniPasti)
|
||||
}
|
||||
post(){
|
||||
try{
|
||||
@ -125,6 +108,3 @@ fun Route.prenotazioni(prenotazioniPastiRepository: PrenotazioniPastiRepository,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ListaPrenotazioni (val totalRecords : Int, val listaPrenotazioni: List<ViewPrenotazioniPasti>)
|
Loading…
Reference in New Issue
Block a user