This commit is contained in:
2024-01-19 15:04:08 +05:30
4 changed files with 100 additions and 45 deletions

View File

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.restapi.domain.*
import com.restapi.domain.Product
import com.restapi.domain.PurchaseOrder
import com.restapi.domain.Quotation
import com.restapi.domain.Session.currentUser
@@ -411,6 +412,45 @@ object PurchaseOrder {
}
}
data class ProductSearch(
var isSort: String? = null
)
object ProductCtrl {
fun get(ctx :Context){
val hsnCode = ctx.pathParam("hsnCode")
val product = database.find(Product::class.java, hsnCode) ?: throw NotFoundResponse("Product not found for $hsnCode")
ctx.json(product)
}
fun getAll(ctx: Context){
val productList = Session.database.find(Product::class.java)
.findList()
.sortedBy { it.hsnCode }
ctx.json(productList)
}
fun create(ctx :Context){
val product = ctx.bodyAsClass<Product>()
database.save(product)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val product = database.delete(Product::class.java, id)
}
fun patch(ctx: Context) {
}
fun update(ctx: Context) {
val id = ctx.pathParam("id")
}
}
object Quotation {
fun get(ctx :Context){
val id = ctx.pathParam("id")
@@ -451,37 +491,13 @@ object Quotation {
}
fun reqForQuote(ctx :Context){
val reqForQuoteNum = ctx.pathParam(("rfqNum"))
val rfq = database.find(ReqForQuote::class.java)
.where()
.eq("reqForQuoteNum", reqForQuoteNum)
?: throw NotFoundResponse("request for quote not found for this quotation")
val rfq = database.find(RequestForQuote::class.java)
.where()
.eq("reqForQuoteNum", reqForQuoteNum)
?: throw NotFoundResponse("request for quote not found for this quotation")
ctx.json(rfq)
}
}
object Product {
fun get(ctx :Context){
val id = ctx.pathParam("id")
val product = database.find(Product::class.java, id) ?: throw NotFoundResponse("product nor found for id $id")
ctx.json(product)
}
fun create(ctx :Context){
val product = ctx.bodyAsClass<Product>()
database.save(product)
ctx.result("product created")
}
fun update(ctx :Context){
}
fun delete(ctx: Context){
val id = ctx.pathParam(("id"))
val product = database.find(Product::class.java, id) ?:throw NotFoundResponse("product not found for id $id")
//product.delete()
ctx.result("product with id $id deleted")
}
fun getDoc(ctx :Context){
}
}
object Document {
fun get(ctx :Context){
val id = ctx.pathParam("id")
@@ -556,9 +572,9 @@ object Vendor {
ctx.result("rating changed")
}
}
object ReqForQuote {
object RequestForQuote {
fun create(ctx :Context) {
val rfq = ctx.bodyAsClass<com.restapi.domain.ReqForQuote>()
val rfq = ctx.bodyAsClass<ReqForQuote>()
database.save(rfq)
//ctx.result("request for quote created")
//ctx.json(rfq)
@@ -567,7 +583,7 @@ object ReqForQuote {
}
fun get(ctx :Context){
val id = ctx.pathParam("id")
val rfq = database.find(com.restapi.domain.ReqForQuote::class.java, id) ?: throw NotFoundResponse("request for quote not found for id $id")
val rfq = database.find(ReqForQuote::class.java, id) ?: throw NotFoundResponse("request for quote not found for id $id")
ctx.json(rfq)
}
fun update(ctx :Context){