forked from maiora/backend-api
Merge pull request '0002441-endpoint-residenze' (#12) from 0002441-endpoint-residenze into dev
Reviewed-on: #12
This commit is contained in:
commit
4c3ea7fbf0
@ -111,6 +111,12 @@ object ProdottiPrenotabiliTable : IdTable<Long>("view_prodotti_prenotabili"){
|
|||||||
val modalitaPrenotazione = varchar("modalita_prenotazione", 255)
|
val modalitaPrenotazione = varchar("modalita_prenotazione", 255)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object ResidenzeTable : IdTable<Long>("residenze"){
|
||||||
|
override val id = long("id").entityId()
|
||||||
|
val idPuntoDistribuzione = long("id_punto_distribuzione")
|
||||||
|
val nome = varchar("nome", 255)
|
||||||
|
}
|
||||||
|
|
||||||
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
||||||
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
||||||
|
|
||||||
@ -208,6 +214,13 @@ class ProdottiPrenotabiliDao(id: EntityID<Long>) :LongEntity(id) {
|
|||||||
var modalitaPrenotazione by ProdottiPrenotabiliTable.modalitaPrenotazione
|
var modalitaPrenotazione by ProdottiPrenotabiliTable.modalitaPrenotazione
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ResidenzeDao(id: EntityID<Long>) :LongEntity(id){
|
||||||
|
companion object : LongEntityClass<ResidenzeDao>(ResidenzeTable)
|
||||||
|
|
||||||
|
val idPuntoDistribuzione by ResidenzeTable.idPuntoDistribuzione
|
||||||
|
val nome by ResidenzeTable.nome
|
||||||
|
}
|
||||||
|
|
||||||
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
||||||
dao.id.value,
|
dao.id.value,
|
||||||
dao.username,
|
dao.username,
|
||||||
@ -319,6 +332,14 @@ fun prodottiPrenotabiliDaoToModel(dao: ProdottiPrenotabiliDao) :ProdottiPrenotab
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun residenzeDaoToModel(dao: ResidenzeDao) :Residenze{
|
||||||
|
return Residenze(
|
||||||
|
dao.id.value,
|
||||||
|
dao.idPuntoDistribuzione,
|
||||||
|
dao.nome
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
||||||
newSuspendedTransaction(Dispatchers.IO, statement = block)
|
newSuspendedTransaction(Dispatchers.IO, statement = block)
|
10
src/main/kotlin/eu/maiora/model/Residenze.kt
Normal file
10
src/main/kotlin/eu/maiora/model/Residenze.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Residenze(
|
||||||
|
val id: Long,
|
||||||
|
val idPuntoDistribuzione : Long,
|
||||||
|
val nome : String
|
||||||
|
)
|
5
src/main/kotlin/eu/maiora/model/ResidenzeRepository.kt
Normal file
5
src/main/kotlin/eu/maiora/model/ResidenzeRepository.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
interface ResidenzeRepository {
|
||||||
|
suspend fun listaResidenze(): List<Residenze>
|
||||||
|
}
|
13
src/main/kotlin/eu/maiora/model/ResidenzeRepositoryImpl.kt
Normal file
13
src/main/kotlin/eu/maiora/model/ResidenzeRepositoryImpl.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package eu.maiora.model
|
||||||
|
|
||||||
|
import eu.maiora.db.*
|
||||||
|
|
||||||
|
class ResidenzeRepositoryImpl : ResidenzeRepository {
|
||||||
|
override suspend fun listaResidenze(): List<Residenze> = suspendTransaction {
|
||||||
|
// Cerca la lista di composizioni
|
||||||
|
ResidenzeDao.all()
|
||||||
|
.toList()
|
||||||
|
.map { residenzeDaoToModel(it) } // Converte il DAO in un oggetto Residenze
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -21,5 +21,6 @@ fun Application.configureRouting() {
|
|||||||
puntiDistribuzione(PuntiDistribuzioneRepositoryImpl())
|
puntiDistribuzione(PuntiDistribuzioneRepositoryImpl())
|
||||||
slotOrari(SlotOrariRepositoryImpl())
|
slotOrari(SlotOrariRepositoryImpl())
|
||||||
prodottiPrenotabili(ProdottiPrenotabiliRepositoryImpl())
|
prodottiPrenotabili(ProdottiPrenotabiliRepositoryImpl())
|
||||||
|
residenze(ResidenzeRepositoryImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
src/main/kotlin/eu/maiora/routes/Residenze.kt
Normal file
20
src/main/kotlin/eu/maiora/routes/Residenze.kt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package eu.maiora.routes
|
||||||
|
|
||||||
|
import eu.maiora.model.ResidenzeRepositoryImpl
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
|
||||||
|
fun Route.residenze(residenzeRepository: ResidenzeRepositoryImpl){
|
||||||
|
route("/api/residenze"){
|
||||||
|
authenticate("auth-jwt") {
|
||||||
|
get(){
|
||||||
|
val listaResidenze = residenzeRepository.listaResidenze()
|
||||||
|
call.respond(listaResidenze)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user