diff --git a/excel/VendorList.xls b/excel/VendorList.xls index 98fc001..254a07c 100644 Binary files a/excel/VendorList.xls and b/excel/VendorList.xls differ diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index e1262b0..49b072d 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -409,6 +409,11 @@ object PurchaseOrderCtrl { fun create(ctx: Context) { val po = ctx.bodyAsClass() + val prods = po.products + if(prods.isEmpty()){ + ctx.json(mapOf("error" to "empty product list")).status(HttpStatus.BAD_REQUEST) + return + } database.save(po) ctx.json(po).status(HttpStatus.CREATED) } @@ -489,13 +494,11 @@ object ProductCtrl { .eq("sys_pk", id.toLong()) .findOne() ?: throw NotFoundResponse("Product not found for $id") - println("Product found") - println(product) ctx.json(product).status(HttpStatus.OK) } fun getAll(ctx: Context) { - val productList = Session.database.find(Product::class.java) + val productList = database.find(Product::class.java) .findList() .sortedBy { it.name } val excel = ctx.queryParam("excel") @@ -505,7 +508,7 @@ object ProductCtrl { ctx.result(inputStream).status(HttpStatus.OK) }else{ - ctx.json(productList) + ctx.json(productList).status(HttpStatus.OK) } } @@ -607,6 +610,12 @@ object QuotationCtrl { fun create(ctx: Context) { val quote = ctx.bodyAsClass() + //validation + val prods = quote.products + if(prods.isEmpty()){ + ctx.json(mapOf("error" to "empty product list")).status(HttpStatus.BAD_REQUEST) + return + } database.save(quote) ctx.json(quote).status(HttpStatus.CREATED) }