add entities and db migrations
This commit is contained in:
@@ -42,6 +42,7 @@ class AppAccessManager : AccessManager {
|
||||
Role.DbOps -> listOf("ROLE_DB_OPS")
|
||||
Role.Entity -> loadEntityActionRole(entity, action)
|
||||
is Role.Standard -> role.action.toList().map { "ROLE_${entity}_${it}" }
|
||||
is Role.Explicit -> role.roles
|
||||
}.map(String::uppercase)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.restapi.config.*
|
||||
import com.restapi.config.AppConfig.Companion.appConfig
|
||||
import com.restapi.config.Auth.validateAuthToken
|
||||
import com.restapi.controllers.Entities
|
||||
import com.restapi.controllers.PurchaseOrder
|
||||
import com.restapi.domain.DataNotFoundException
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.Session.currentTenant
|
||||
@@ -22,6 +23,7 @@ import io.javalin.http.UnauthorizedResponse
|
||||
import io.javalin.http.util.NaiveRateLimit
|
||||
import io.javalin.http.util.RateLimitUtil
|
||||
import io.javalin.json.JavalinJackson
|
||||
import org.checkerframework.dataflow.qual.Pure
|
||||
import org.jose4j.jwt.consumer.InvalidJwtException
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.security.MessageDigest
|
||||
@@ -111,6 +113,12 @@ fun main(args: Array<String>) {
|
||||
it.json(mapOf("status" to true))
|
||||
}
|
||||
|
||||
path("/vendor"){
|
||||
path("/po"){
|
||||
post("", PurchaseOrder::create, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", PurchaseOrder::get, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))))
|
||||
}
|
||||
}
|
||||
post("/script/database/{name}", Entities::executeStoredProcedure, Roles(adminRole, Role.DbOps))
|
||||
post("/script/{file}/{name}", Entities::executeScript, Roles(adminRole, Role.DbOps))
|
||||
|
||||
|
||||
@@ -235,6 +235,7 @@ enum class Action {
|
||||
sealed class Role {
|
||||
open class Standard(vararg val action: Action) : Role()
|
||||
data object Entity : Role()
|
||||
data class Explicit(val roles: List<String>) : Role()
|
||||
data object DbOps : Role()
|
||||
}
|
||||
|
||||
|
||||
@@ -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.PurchaseOrder
|
||||
import com.restapi.domain.Session.currentUser
|
||||
import com.restapi.domain.Session.database
|
||||
import com.restapi.domain.Session.findDataModelByEntityAndUniqId
|
||||
@@ -371,4 +372,17 @@ object Entities {
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
object PurchaseOrder {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
|
||||
ctx.json(po)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val po = ctx.bodyAsClass<PurchaseOrder>()
|
||||
database.save(po)
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,12 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import io.ebean.Model
|
||||
import io.ebean.annotation.*
|
||||
import io.ebean.annotation.Index
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.*
|
||||
|
||||
data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now())
|
||||
|
||||
data class POProducts(val productId: String = "", val unitPrice :Double = 0.0, val quantity: Double = 0.0, val description :String = "")
|
||||
enum class ApprovalStatus {
|
||||
PENDING, APPROVED, REJECTED
|
||||
}
|
||||
@@ -214,6 +215,8 @@ open class DataModel : BaseTenantModel() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
@Index(unique = true, name = "unique_session_id", columnNames = ["session_id"])
|
||||
open class AnonSession : BaseTenantModel() {
|
||||
@@ -238,3 +241,69 @@ class SafeStringDeserializer : JsonDeserializer<String>() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class ContactPerson(val name: String, val email: String, val mobile: String)
|
||||
@Entity
|
||||
open class Vendor :BaseTenantModel() {
|
||||
var name :String = ""
|
||||
var msme :String = ""
|
||||
var gstNumber :String = ""
|
||||
var address :String = ""
|
||||
var rating :Double = 0.0
|
||||
@DbJsonB
|
||||
var contacts :List<ContactPerson> = mutableListOf()
|
||||
}
|
||||
@Entity
|
||||
open class PurchaseOrder :BaseTenantModel() {
|
||||
@DbJsonB
|
||||
var products :MutableList<POProducts> = mutableListOf()
|
||||
@ManyToOne
|
||||
var vendor :Vendor? = null
|
||||
var referenceQuotation :String = ""
|
||||
var totalAmount :Int = 0
|
||||
var poNum: String = ""
|
||||
var poDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
@DbArray
|
||||
var tnc: List<String> = arrayListOf()
|
||||
@DbArray
|
||||
var documents: MutableList<Long> = arrayListOf()
|
||||
}
|
||||
|
||||
enum class UOM {
|
||||
NOS, LTR, MTR
|
||||
}
|
||||
@Entity
|
||||
open class Product :BaseTenantModel() {
|
||||
var name :String = ""
|
||||
var description :String = ""
|
||||
var hsnCode :String = ""
|
||||
@Enumerated(EnumType.STRING)
|
||||
var uom: UOM? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Quotation :BaseTenantModel() {
|
||||
@DbJsonB
|
||||
var products :MutableList<POProducts> = mutableListOf()
|
||||
@ManyToOne
|
||||
var vendor :Vendor? = null
|
||||
var totalAmount :Int = 0
|
||||
|
||||
var quoteNum: String = ""
|
||||
var quoteDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
@DbArray
|
||||
var tnc: List<String> = arrayListOf()
|
||||
|
||||
@DbArray
|
||||
var documents: MutableList<Long> = arrayListOf()
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Document :BaseTenantModel() {
|
||||
var name :String = ""
|
||||
var typeOfDoc :String = ""
|
||||
var description :String = ""
|
||||
var url :String = ""
|
||||
}
|
||||
Reference in New Issue
Block a user