fix updates
This commit is contained in:
@@ -143,7 +143,7 @@ fun main(args: Array<String>) {
|
||||
put("/{id}", ProductCtrl::update, Roles(Role.Explicit("ROLE_PRODUCT_CREATE")))
|
||||
delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit("ROLE_PRODUCT_CREATE")))
|
||||
patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit("ROLE_PRODUCT_CREATE")))
|
||||
get("", ProductCtrl::getAll, Roles(Role.Explicit("ROLE_PRODUCT_VIEW")))
|
||||
post("/getAll", ProductCtrl::getAll, Roles(Role.Explicit("ROLE_PRODUCT_VIEW")))
|
||||
get("/{id}", ProductCtrl::get, Roles(Role.Explicit("ROLE_PRODUCT_VIEW")))
|
||||
}
|
||||
path("/doc") {
|
||||
|
||||
@@ -434,8 +434,10 @@ object PurchaseOrderCtrl {
|
||||
fun reject(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
po.approvalStatus = ApprovalStatus.REJECTED
|
||||
po.save()
|
||||
po.apply {
|
||||
approvalStatus = ApprovalStatus.REJECTED
|
||||
save()
|
||||
}
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
@@ -448,6 +450,19 @@ object PurchaseOrderCtrl {
|
||||
?: throw NotFoundResponse("reference quotation not found for po $id")
|
||||
ctx.json(quote)
|
||||
}
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
val updatedPo = ctx.bodyAsClass<PurchaseOrder>()
|
||||
po.patchValues(updatedPo)
|
||||
po.update()
|
||||
}
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("no po found with id $id")
|
||||
database.delete(po)
|
||||
ctx.status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
data class ProductSearch(
|
||||
@@ -481,15 +496,14 @@ object ProductCtrl {
|
||||
database.save(product)
|
||||
ctx.json(product).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
database.delete(Product::class.java, id)
|
||||
val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id")
|
||||
database.delete(prod)
|
||||
ctx.status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun patch(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
|
||||
val patchValues = ctx.bodyAsClass<Map<String, Any>>()
|
||||
database.beginTransaction().use {
|
||||
patchValues.entries.forEach { en ->
|
||||
@@ -511,7 +525,6 @@ object ProductCtrl {
|
||||
val updatedProduct = ctx.bodyAsClass<Product>()
|
||||
product.patchValues(updatedProduct)
|
||||
product.update()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -586,28 +599,18 @@ object QuotationCtrl {
|
||||
}
|
||||
ctx.result("Quotes batch created").status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for id $id")
|
||||
quote.delete()
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("no quote found with id $id")
|
||||
database.delete(quote)
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("quote with $id deleted")
|
||||
}
|
||||
|
||||
fun generatePO(ctx: Context) {
|
||||
//user should be redirected to a po form submission with prefilled values
|
||||
//create a PO object with values from the quote and then send it as body to vendor/po/create ??
|
||||
}
|
||||
|
||||
fun reqForQuote(ctx: Context) {
|
||||
val reqForQuoteNum = ctx.pathParam(("rfqNum"))
|
||||
val rfq = database.find(RequestForQuote::class.java)
|
||||
.where()
|
||||
.eq("reqForQuoteNum", reqForQuoteNum)
|
||||
?: throw NotFoundResponse("request for quote not found for this quotation")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(rfq)
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
val updatedQuote = ctx.bodyAsClass<Quotation>()
|
||||
quote.patchValues(updatedQuote)
|
||||
quote.update()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,15 +632,12 @@ object DocumentCtrl {
|
||||
fun print(ctx: Context) {
|
||||
//would be handled in the frontend ??
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
//doc.delete()
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id")
|
||||
database.delete(doc)
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("document deleted with id $id")
|
||||
}
|
||||
|
||||
fun getWithRefId(ctx: Context) {
|
||||
//fetches a particular doc (po, quote) with ref id
|
||||
val refId = ctx.pathParam("refId")
|
||||
@@ -656,7 +656,7 @@ object VendorCtrl {
|
||||
val logger = LoggerFactory.getLogger("Vendor")
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
|
||||
val vendor =database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
@@ -684,9 +684,12 @@ object VendorCtrl {
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
|
||||
val id = ctx.pathParam("id")
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id")
|
||||
val updatedVendor = ctx.bodyAsClass<Vendor>()
|
||||
vendor.patchValues(updatedVendor)
|
||||
vendor.update()
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
|
||||
|
||||
@@ -246,6 +246,9 @@ data class ContactPerson(val name: String = "", val email: String = "", val mobi
|
||||
|
||||
@Entity
|
||||
open class Vendor : BaseTenantModel() {
|
||||
fun patchValues(updatedVendor : Vendor) {
|
||||
|
||||
}
|
||||
var name: String = ""
|
||||
var msme: String = ""
|
||||
var gstNumber: String = ""
|
||||
@@ -258,6 +261,9 @@ open class Vendor : BaseTenantModel() {
|
||||
|
||||
@Entity
|
||||
open class PurchaseOrder : BaseTenantModel() {
|
||||
fun patchValues(updatedPo : PurchaseOrder){
|
||||
|
||||
}
|
||||
@DbJsonB
|
||||
var products: MutableList<POProducts> = mutableListOf()
|
||||
|
||||
@@ -300,6 +306,10 @@ open class Product : BaseTenantModel() {
|
||||
|
||||
@Entity
|
||||
open class Quotation : BaseTenantModel() {
|
||||
fun patchValues(updatedQuote : Quotation) {
|
||||
|
||||
}
|
||||
|
||||
@DbJsonB
|
||||
var products: MutableList<POProducts> = mutableListOf()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user