handle prefixes

This commit is contained in:
gowthaman 2024-04-30 12:21:57 +05:30
parent fb4f1a0995
commit f2b05b229d
4 changed files with 44 additions and 8 deletions

View File

@ -128,9 +128,16 @@ fun main(args: Array<String>) {
get("/plants", IncomingInventoryCtrl::plantsForUser,
Roles(
Role.Explicit("ROLE_INVENTORY_CREATE"),
Role.Explicit("ROLE_VENDOR_VIEW"),
Role.Explicit("ROLE_VENDOR_CREATE"),
Role.Explicit("ROLE_INVENTORY_VIEW")
)
)
put("/plants/{id}", IncomingInventoryCtrl::updatePlant,
Roles(
Role.Explicit("ROLE_INVENTORY_CREATE"),
Role.Explicit("ROLE_VENDOR_CREATE")
))
post("", IncomingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE")))
get("/next", IncomingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE")))
get(

View File

@ -810,6 +810,14 @@ object IncomingInventoryCtrl {
Session.currentUserPlants()
)
}
fun updatePlant(ctx: Context) {
val p = ctx.bodyAsClass<Plant>()
val plant = database.find(Plant::class.java, ctx.pathParam("id"))
plant.patch(p)
ctx.json(
Session.currentUserPlants()
)
}
fun create(ctx: Context) {
val ticket = ctx.bodyAsClass<IncomingInventory>()

View File

@ -30,7 +30,6 @@ import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.HashMap
import kotlin.jvm.optionals.getOrDefault
@ -138,14 +137,15 @@ object Session {
}
fun a(){
val a = HashMap<String,String>()
fun a() {
val a = HashMap<String, String>()
a.put("a", "b");
a.put("a", "b");
a.put("a", "b");
a.put("a", "b");
val b = HashMap<String,String>().apply {
val b = HashMap<String, String>().apply {
put("a", "b");
put("a", "b");
put("a", "b");
@ -159,6 +159,7 @@ object Session {
//will work only when c is not null
}
}
private val sc = DatabaseConfig().apply {
loadFromProperties(Properties().apply {
setProperty("datasource.db.username", appConfig.dbUser())
@ -187,6 +188,11 @@ object Session {
.where()
.eq("plantId", it)
.findOne()
?.apply {
if (this.prefixes == null || this.prefixes.isNullOrEmpty()) {
this.prefixes = mutableMapOf("INBOUND" to "MRN/")
}
}
}
fun jwk(): MutableMap<String, Any> = keypair.toParams(JsonWebKey.OutputControlLevel.PUBLIC_ONLY)

View File

@ -254,10 +254,14 @@ class SafeStringDeserializer : JsonDeserializer<String>() {
enum class AddressType {
BILLING, SHIPPING
}
data class ContactPerson(val name: String = "", val email: String = "", val mobile: String = "")
data class Address(val type: AddressType = AddressType.BILLING,
data class Address(
val type: AddressType = AddressType.BILLING,
val address: String = "",
val pincode: String = "")
val pincode: String = ""
)
@Entity
open class Vendor : BaseTenantModel() {
fun patchValues(updatedVendor: Vendor) {
@ -282,6 +286,7 @@ open class Vendor : BaseTenantModel() {
@DbJsonB
var addressList: List<Address>? = mutableListOf()
@DbJsonB
var contacts: List<ContactPerson> = mutableListOf()
@ -659,8 +664,18 @@ open class ReminderLog : BaseTenantModel() {
@Entity
@Index(name = "plantid_idx", columnNames = ["plant_id"], unique = true)
open class Plant : BaseModel() {
fun patch(p: Plant) {
this.plantName = p.plantName
this.prefixes?.apply {
this.clear()
this.putAll(p.prefixes ?: emptyMap())
}
this.save()
}
var plantId: String = ""
var plantName: String = ""
@DbJsonB
var prefixes: Map<String,String>? = emptyMap()
var prefixes: MutableMap<String, String>? = mutableMapOf()
}