writeonce/docs/examples/shop/main.wo
shoney.arickathil 89df517613 feat(shop): the program template — MVC on disk; story 37 redirected
- docs/examples/shop: types.wo model, per-feature view modules
  (render() classes), root controller files, layout shell/header/
  footer, static assets controller + real style.css, README with
  Angular file map + run + DX referendum notes
- buy flow proven by hand: stock check/decrement, 409s, traversal
  404, css typed, WAL-durable; builds on the UNPATCHED toolchain
- two language gaps recorded, not fixed (per directive): pub+@table
  cannot combine (controllers forced into root module); @view
  projection classes absent
- story 37 REDIRECTED per Vue-SFC review: view.html compiled by woc
  ({{}} auto-escaped, w:if/w:for, typed against view class, no
  runtime engine); render()-as-concatenation failed the referendum;
  forks revised; shop named the acceptance consumer

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 23:57:44 +02:00

49 lines
1.6 KiB
Text

-- shop/main.wo — the bootstrap (app-routing.module's analog): seed the
-- store on first boot, wire routes to the feature controllers, serve.
-- No rendering and no queries here beyond the seed.
--
-- WO_DATA=./data ./target/shop 8080 (run from the shop directory:
-- /assets/* serves from ./assets)
use framework
use framework/router
use product_list
use product_page
use orders
use static_files
fn seed_if_empty() {
let n = 0;
for p in from x in Product take 1 select x {
n = n + 1;
}
if n > 0 {
return;
}
insert Product { sku: "keyb-75", name: "75% mechanical keyboard", price: 89.0, stock: 12 };
insert Product { sku: "mug-wal", name: "WAL-backed coffee mug", price: 14.5, stock: 40 };
insert Product { sku: "tee-own", name: "Ownership-checked t-shirt", price: 24.9, stock: 25 };
insert Product { sku: "desk-pad", name: "Deskmat (one binary edition)", price: 19.0, stock: 0 };
}
fn main(args: multi Text) -> Int {
if len(args) < 1 {
print_err("usage: shop <port> (WO_DATA=<dir> makes the store durable)");
return 2;
}
let port = parse_int(args[0]);
if port == nil {
print_err("shop: <port> must be a number");
return 2;
}
seed_if_empty();
let app = App { middleware: [], routes: [] };
app.use_mw(Mw { m: Logging { pad: 0 } });
app.get("/", ListProducts { pad: 0 });
app.get("/p/:sku", ShowProduct { pad: 0 });
app.post("/orders/:sku", CreateOrder { pad: 0 });
app.get("/orders", ListOrders { pad: 0 });
app.get("/assets/*path", StaticFiles { dir: "assets" });
return app.serve("127.0.0.1", port);
}