sample-domain-story Pub

Simple products and inventory

listAll | new
class::DTInventory (    products:Array[DTProductUnit],     products:Array[DTProductUnit])
no inventory registered
class::DTProductUnit (
  key,
  qty:Number,
  spec:<>DTProductSpec,
  key,
  qty:Number,
  spec:<>DTProductSpec
)
listAll | new
class::DTProductSpec <spec,spec> (
  key,
  sku,
  descriptionRef:<>DTBlogPost,
  key,
  sku,
  descriptionRef:<>DTBlogPost
)
listAll | new
class::DTBlogPost (
  key,
  content,
  key,
  content
)

send::  msg diesel.inv.register  (inventory="diesel.db.inmem", classNames ="DTInventory, DTProductUnit,DTP"...)

send:: msg  (inventory={products:[]}, blog={key:"blog1.munchies",content:"munchies are cool"}, productSpec={key:"munchies",sku:"munchieseh",descriptionRef:"blog1.munchies"})

send:: msg  (inventory[="products"]=(inventory[="products"] + {key:"a-prod",qty:3,spec:"munchies"}))

send:: msg  (x=([inventory,blog,productSpec] foreach entity=>diesel.inv.upsert(entity)()))

send::  msg ctx.echo  (x)

Simple ordering demo

no inventory registered
class::DTCart (
  key,
  customerRef:<>DTCustomer,
  items:Array[DTItem],
  key,
  customerRef:<>DTCustomer,
  items:Array[DTItem]
)
no inventory registered
class::DTItem (
  key,
  productRef:<>DTProductSpec,
  qty:Number,
  key,
  productRef:<>DTProductSpec,
  qty:Number
)
no inventory registered
class::DTOrder (
  key,
  customerRef:<>DTCustomer,
  items:Array[DTItem],
  key,
  customerRef:<>DTCustomer,
  items:Array[DTItem]
)
no inventory registered
class::DTCustomer (
  key,
  name,
  address,
  key,
  name,
  address
)

send::  msg diesel.inv.register  (inventory="diesel.db.mongo", classNames ="DTCart,DTItem,DTOrder,DTCustom"...)

send:: msg  (customer={key:"123",name:"Jane Doe",address:"123 Phantom Town"}, cart={key:"a-cart",customerRef:"123",items:[{key:"123",productRef:"munchies",qty:2}]})

send:: msg  (x=([customer,cart] foreach entity=>diesel.inv.upsert(entity)()))
// ## Inventory test // ### Domain // Make sure your classes include a key attribute, unique. Otherwise, one random key is assigned for you and all sorts of funny and entertaining side effects may occur... // NOTE that these classes below won't work with persistence until you run this story - which will register and connect the postgress. // First class is annotated for persistance, although annotations are static and we prefer the registration, see below: // $class TestStudent( // key, // age, // courseRef:<>TestCourse, // grades:TestGrade* // ) // This classes are registered, see the register message below - this is the preferred approach, as it's more dynamic: // $class TestCourse( // key // ) // $class TestGrade( // courseRef:<>TestCourse, // grade // ) // $send diesel.inv.register(inventory="diesel.db.inmem", classNames="TestCourse,TestGrade") // We need to establish the default connection for the inventory: // $send diesel.inv.connect(inventory="diesel.db.postgres", env=diesel.env, connection="", super="diesel") // Now we're setup. We can begin playing with these entities... // $val cs = new TestCourse {key: "CS"} // $val jay = new TestStudent { // key: "Jay", // age: 33, // courseRef: "CS", // grades: [new TestGrade{courseRef: "CS", grade:7}] // } // $val mary = new TestStudent { // key: "Mary", // age: 33, // courseRef: "CS", // grades: [new TestGrade {courseRef: "CS", grade: 6}] // } // $ diesel.inv.upsert (entity=cs) // $ diesel.inv.upsert (entity=jay) // $ diesel.inv.upsert (entity=mary) // $ diesel.inv.listAll(className="TestCourse") // $expect (payload.total is 1) // $ diesel.inv.listAll(className="TestStudent") // $expect (payload.total is 2) // ## Test delete with query: // Delete all students taking CS - who needs them anyhow // $send diesel.db.postgres.remove (collection="TestStudent", courseRef="CS") // $ diesel.inv.listAll(className="TestStudent") // $expect (payload.total is 0)


Was this useful?    

By: Razie | 2022-05-18 .. 2022-06-09 | Tags: story , dsl


Viewed 319 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.