add endpoints
This commit is contained in:
@@ -7,16 +7,15 @@ import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.restapi.domain.*
|
||||
import com.restapi.domain.PurchaseOrder
|
||||
import com.restapi.domain.Quotation
|
||||
import com.restapi.domain.Session.currentUser
|
||||
import com.restapi.domain.Session.database
|
||||
import com.restapi.domain.Session.findDataModelByEntityAndUniqId
|
||||
import com.restapi.domain.Vendor
|
||||
import com.restapi.integ.Scripting
|
||||
import io.ebean.CallableSql
|
||||
import io.ebean.RawSqlBuilder
|
||||
import io.javalin.http.BadRequestResponse
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.NotFoundResponse
|
||||
import io.javalin.http.bodyAsClass
|
||||
import io.javalin.http.*
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.sql.Types
|
||||
import java.time.LocalDate
|
||||
@@ -384,5 +383,196 @@ object PurchaseOrder {
|
||||
fun create(ctx :Context){
|
||||
val po = ctx.bodyAsClass<PurchaseOrder>()
|
||||
database.save(po)
|
||||
ctx.result("po created")
|
||||
}
|
||||
fun approve(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.APPROVED
|
||||
po.save()
|
||||
ctx.result("po with id $id approved")
|
||||
//reject all other pos pertaining to the same tx ??
|
||||
}
|
||||
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()
|
||||
ctx.result("po with id $id rejected")
|
||||
}
|
||||
fun quoteReference(ctx :Context){
|
||||
//gets the quote reference on which this po is based on
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java)
|
||||
.where()
|
||||
.eq("referenceQuotation", id)
|
||||
?: throw NotFoundResponse("reference quotation not found for po $id")
|
||||
ctx.json(quote)
|
||||
}
|
||||
}
|
||||
|
||||
object Quotation {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
ctx.json(quote)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val quote = ctx.bodyAsClass<Quotation>()
|
||||
//we have to check if the quotation created date is below the expiry of rfq
|
||||
val rfq = database.find(com.restapi.domain.ReqForQuote::class.java)
|
||||
.where()
|
||||
.eq("reqForQuoteNum", quote.reqForQuoteNum)
|
||||
.findOne()
|
||||
if(rfq != null){
|
||||
//compare dates
|
||||
if(quote.quoteDate!! <= rfq.openTill) {
|
||||
//valid
|
||||
database.save(quote)
|
||||
ctx.result("quote created")
|
||||
}else {
|
||||
ctx.result("request for quote closed")
|
||||
}
|
||||
}else {
|
||||
throw NotFoundResponse("request for quote not found for this quotation")
|
||||
}
|
||||
|
||||
}
|
||||
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()
|
||||
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(ReqForQuote::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")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
ctx.json(doc)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val doc = ctx.bodyAsClass<Document>()
|
||||
database.save(doc)
|
||||
ctx.result("doc created")
|
||||
}
|
||||
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()
|
||||
ctx.result("document deleted")
|
||||
}
|
||||
fun getWithRefId(ctx :Context){
|
||||
//fetches a particular doc (po, quote) with ref id
|
||||
val refId = ctx.pathParam("refId")
|
||||
val doc = database.find(Document::class.java)
|
||||
.where()
|
||||
.eq("refId", refId)
|
||||
?: throw NotFoundResponse("no doc found for refId $refId")
|
||||
ctx.json(doc)
|
||||
}
|
||||
|
||||
}
|
||||
object 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")
|
||||
ctx.json(vendor)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val vendor = ctx.bodyAsClass<Vendor>()
|
||||
database.save(vendor)
|
||||
ctx.result("vendor created")
|
||||
}
|
||||
fun update(ctx :Context){
|
||||
|
||||
}
|
||||
fun delete(ctx :Context){
|
||||
|
||||
}
|
||||
fun getQuotes(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val quotes = database.find(Quotation::class.java)
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.findList()
|
||||
ctx.json(quotes)
|
||||
}
|
||||
fun getPos(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val pos = database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.findList()
|
||||
ctx.json(pos)
|
||||
}
|
||||
fun rate(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val rating = ctx.pathParam("rating").toDouble()
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for id $id")
|
||||
//could place some rating validation checks
|
||||
vendor.rating = rating
|
||||
vendor.save()
|
||||
ctx.result("rating changed")
|
||||
}
|
||||
}
|
||||
object ReqForQuote {
|
||||
fun create(ctx :Context) {
|
||||
val rfq = ctx.bodyAsClass<com.restapi.domain.ReqForQuote>()
|
||||
database.save(rfq)
|
||||
//ctx.result("request for quote created")
|
||||
//ctx.json(rfq)
|
||||
//ctx.status(HttpStatus.CREATED)
|
||||
//ctx.json("asss")
|
||||
}
|
||||
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")
|
||||
ctx.json(rfq)
|
||||
}
|
||||
fun update(ctx :Context){
|
||||
//shuld we compare the new body fields with preexisting ones and prepare a sql query to update those fields??
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user