add fleet
This commit is contained in:
@@ -1040,3 +1040,84 @@ object InvoiceCtrl {
|
||||
ctx.json(seq).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
object FleetCtrl {
|
||||
fun create(ctx: Context) {
|
||||
val fleet = ctx.bodyAsClass<Fleet>()
|
||||
database.save(fleet)
|
||||
ctx.json(fleet).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val fleet = database.find(Fleet::class.java, id)
|
||||
?: throw NotFoundResponse("No fleet found with id $id")
|
||||
ctx.json(fleet).status(HttpStatus.OK)
|
||||
}
|
||||
data class FLTF(val common: CommonFilters, val fleetFilters: FleetFilters)
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<FLTF>()
|
||||
val fleets = searchFleets(filters.common, filters.fleetFilters)
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel !== null) {
|
||||
// exportFleets(fleets)
|
||||
val inputStream = FileInputStream("./excel/Fleets.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
} else {
|
||||
ctx.json(fleets).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
}
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val fleet =
|
||||
database.find(Fleet::class.java, id) ?: throw NotFoundResponse("fleet not found for $id")
|
||||
val updatedFleet= ctx.bodyAsClass<Fleet>()
|
||||
fleet.patchValues(updatedFleet)
|
||||
fleet.update()
|
||||
ctx.json(fleet).status(HttpStatus.OK)
|
||||
}
|
||||
fun delete(ctx: Context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
object RenewalCtrl{
|
||||
fun create(ctx: Context) {
|
||||
val renewal = ctx.bodyAsClass<Renewal>()
|
||||
database.save(renewal)
|
||||
ctx.json(renewal).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val renewal = database.find(Renewal::class.java, id)
|
||||
?: throw NotFoundResponse("No renewal found with id $id")
|
||||
ctx.json(renewal).status(HttpStatus.OK)
|
||||
}
|
||||
//data class RNLF(val common: CommonFilters, val renewalFilters: RenewalFilters)
|
||||
fun getAll(ctx: Context) {
|
||||
// val filters = ctx.bodyAsClass<FLTF>()
|
||||
// val renewals = searchRenewals(filters.common, filters.renewalFilters)
|
||||
val renewals = database.find(Renewal::class.java).findList()
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel !== null) {
|
||||
// exportRenewals(renewals)
|
||||
val inputStream = FileInputStream("./excel/Renewals.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
} else {
|
||||
ctx.json(renewals).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
}
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val renewal =
|
||||
database.find(Renewal::class.java, id) ?: throw NotFoundResponse("renewal not found for $id")
|
||||
val updatedRenewal= ctx.bodyAsClass<Renewal>()
|
||||
renewal.patchValues(updatedRenewal)
|
||||
renewal.update()
|
||||
ctx.json(renewal).status(HttpStatus.OK)
|
||||
}
|
||||
fun delete(ctx: Context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user