product
This commit is contained in:
@@ -6,6 +6,7 @@ import com.restapi.config.AppConfig.Companion.appConfig
|
||||
import com.restapi.config.Auth.validateAuthToken
|
||||
import com.restapi.controllers.*
|
||||
import com.restapi.domain.DataNotFoundException
|
||||
import com.restapi.domain.Product
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.Session.currentTenant
|
||||
import com.restapi.domain.Session.currentUser
|
||||
@@ -135,10 +136,12 @@ fun main(args: Array<String>) {
|
||||
delete("/{id}", Quotation::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||
}
|
||||
path("/product"){
|
||||
post("", Product::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", Product::get, Roles(Role.Explicit(listOf("ROLE_DOC_VIEW", "ROLE_ADMIN", "ROLE_PRODUCT_CREATE"))))
|
||||
delete("{id}", Product::delete, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||
get("/doc/{id}", Product::getDoc, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_VIEW_DOC"))))
|
||||
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
||||
put("/{id}", ProductCtrl::update, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
||||
patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
||||
delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN"))))
|
||||
get("") {ctx -> ctx.json(Session.database.find(Product::class.java).findList())}
|
||||
}
|
||||
path("/doc"){
|
||||
post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN"))))
|
||||
|
||||
@@ -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,33 @@ object PurchaseOrder {
|
||||
}
|
||||
}
|
||||
|
||||
object ProductCtrl {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val product = database.find(Product::class.java, id) ?: throw NotFoundResponse("Product not found for $id")
|
||||
|
||||
ctx.json(product)
|
||||
}
|
||||
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")
|
||||
@@ -452,36 +480,12 @@ 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")
|
||||
.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")
|
||||
|
||||
@@ -275,6 +275,7 @@ enum class UOM {
|
||||
}
|
||||
@Entity
|
||||
open class Product :BaseTenantModel() {
|
||||
var id: Int? = null
|
||||
var name :String = ""
|
||||
var description :String = ""
|
||||
var hsnCode :String = ""
|
||||
|
||||
Reference in New Issue
Block a user