Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 19083d1

Browse files
danjoachgeo
authored andcommitted
Rename amount -> quantity
1 parent 48d547e commit 19083d1

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

bookshop/app/vue/app.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const books = new Vue ({
1010
data: {
1111
list: [],
1212
book: undefined,
13-
order: { amount:1, succeeded:'', failed:'' }
13+
order: { quantity:1, succeeded:'', failed:'' }
1414
},
1515

1616
methods: {
@@ -26,18 +26,18 @@ const books = new Vue ({
2626
const book = books.book = books.list [eve.currentTarget.rowIndex-1]
2727
const res = await GET(`/Books/${book.ID}?$select=descr,stock,image`)
2828
Object.assign (book, res.data)
29-
books.order = { amount:1 }
29+
books.order = { quantity:1 }
3030
setTimeout (()=> $('form > input').focus(), 111)
3131
},
3232

3333
async submitOrder () {
34-
const {book,order} = books, amount = parseInt (order.amount) || 1 // REVISIT: Okra should be less strict
34+
const {book,order} = books, quantity = parseInt (order.quantity) || 1 // REVISIT: Okra should be less strict
3535
try {
36-
const res = await POST(`/submitOrder`, { amount, book: book.ID })
36+
const res = await POST(`/submitOrder`, { quantity, book: book.ID })
3737
book.stock = res.data.stock
38-
books.order = { amount, succeeded: `Successfully ordered ${amount} item(s).` }
38+
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
3939
} catch (e) {
40-
books.order = { amount, failed: e.response.data.error.message }
40+
books.order = { quantity, failed: e.response.data.error.message }
4141
}
4242
}
4343

bookshop/app/vue/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1> {{ document.title }} </h1>
4848
&nbsp;&nbsp; {{ book.stock }} in stock
4949
</label>
5050
<form @submit.prevent="submitOrder" style="float:right; display:flex; flex-direction:row-reverse">
51-
<input type="number" v-model="order.amount" v-bind:class="{ failed: order.failed }" style="width:5em">
51+
<input type="number" v-model="order.quantity" v-bind:class="{ failed: order.failed }" style="width:5em">
5252
<input type="submit" value="Order:" class="muted-button">
5353
</form>
5454
<h4> {{ book.title }} </h4>

bookshop/srv/cat-service.cds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ service CatalogService @(path:'/browse') {
1111
} excluding { createdBy, modifiedBy };
1212

1313
@requires: 'authenticated-user'
14-
action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer };
15-
event OrderedBook : { book: Books:ID; amount: Integer; buyer: String };
14+
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
15+
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
1616
}

bookshop/srv/cat-service.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class CatalogService extends cds.ApplicationService { init(){
55

66
// Reduce stock of ordered books if available stock suffices
77
this.on ('submitOrder', async req => {
8-
const {book,amount} = req.data
8+
const {book,quantity} = req.data
99
let {stock} = await SELECT `stock` .from (Books,book)
10-
if (stock >= amount) {
11-
await UPDATE (Books,book) .with (`stock -=`, amount)
12-
await this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
10+
if (stock >= quantity) {
11+
await UPDATE (Books,book) .with (`stock -=`, quantity)
12+
await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id })
1313
return { stock }
1414
}
15-
else return req.error (409,`${amount} exceeds stock for book #${book}`)
15+
else return req.error (409,`${quantity} exceeds stock for book #${book}`)
1616
})
1717

1818
// Add some discount for overstocked books

bookshop/test/requests.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ POST {{server}}/browse/submitOrder
7171
Content-Type: application/json
7272
{{me}}
7373

74-
{ "book":201, "amount":5 }
74+
{ "book":201, "quantity":5 }
7575

7676

7777
### ------------------------------------------------------------------------

fiori/srv/mashup.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ module.exports = async()=>{ // called by server.js
2727
// Create an order with the OrdersService when CatalogService signals a new order
2828
//
2929
CatalogService.on ('OrderedBook', async (msg) => {
30-
const { book, amount, buyer } = msg.data
30+
const { book, quantity, buyer } = msg.data
3131
const { title, price } = await db.tx(msg).read (Books, book, b => { b.title, b.price })
3232
return OrdersService.tx(msg).create ('Orders').entries({
3333
OrderNo: 'Order at '+ (new Date).toLocaleString(),
34-
Items: [{ product:{ID:`${book}`}, title, price, amount }],
34+
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
3535
buyer, createdBy: buyer
3636
})
3737
})
@@ -51,9 +51,9 @@ module.exports = async()=>{ // called by server.js
5151
//
5252
OrdersService.on ('OrderChanged', (msg) => {
5353
console.debug ('> received:', msg.event, msg.data)
54-
const { product, deltaAmount } = msg.data
54+
const { product, deltaQuantity } = msg.data
5555
return UPDATE (Books) .where ('ID =', product)
56-
.and ('stock >=', deltaAmount)
57-
.set ('stock -=', deltaAmount)
56+
.and ('stock >=', deltaQuantity)
57+
.set ('stock -=', deltaQuantity)
5858
})
5959
}

orders/app/orders/fiori-service.cds

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ annotate OrdersService.Orders_Items with @(
7474
{Value: product_ID, Label:'Product ID'},
7575
{Value: title, Label:'Product Title'},
7676
{Value: price, Label:'Unit Price'},
77-
{Value: amount, Label:'Quantity'},
77+
{Value: quantity, Label:'Quantity'},
7878
],
7979
Identification: [ //Is the main field group
80-
{Value: amount, Label:'Amount'},
80+
{Value: quantity, Label:'Quantity'},
8181
{Value: title, Label:'Product'},
8282
{Value: price, Label:'Unit Price'},
8383
],
@@ -86,7 +86,7 @@ annotate OrdersService.Orders_Items with @(
8686
],
8787
},
8888
) {
89-
amount @(
89+
quantity @(
9090
Common.FieldControl: #Mandatory
9191
);
9292
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ID;up__ID;amount;product_ID;title;price
1+
ID;up__ID;quantity;product_ID;title;price
22
58040e66-1dcd-4ffb-ab10-fdce32028b79;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;201;Wuthering Heights;11.11
33
64e718c9-ff99-47f1-8ca3-950c850777d4;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;271;Catweazle;15
44
e9641166-e050-4261-bfee-d1e797e6cb7f;64e718c9-ff99-47f1-8ca3-950c850777d4;2;252;Eleonora;28

orders/db/schema.cds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ entity Orders_Items {
1212
key ID : UUID;
1313
up_ : Association to Orders;
1414
product : Association to Products @assert.integrity:false; // REVISIT: this is a temporary workaround for a glitch in cds-runtime
15-
amount : Integer;
15+
quantity : Integer;
1616
title : String; //> intentionally replicated as snapshot from product.title
1717
price : Double;
1818
}

orders/srv/orders-service.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ class OrdersService extends cds.ApplicationService {
77

88
this.before ('UPDATE', 'Orders', async function(req) {
99
const { ID, Items } = req.data
10-
if (Items) for (let { product_ID, amount } of Items) {
11-
const { amount:before } = await cds.tx(req).run (
12-
SELECT.one.from (OrderItems, oi => oi.amount) .where ({up__ID:ID, product_ID})
10+
if (Items) for (let { product_ID, quantity } of Items) {
11+
const { quantity:before } = await cds.tx(req).run (
12+
SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})
1313
)
14-
if (amount != before) await this.orderChanged (product_ID, amount-before)
14+
if (quantity != before) await this.orderChanged (product_ID, quantity-before)
1515
}
1616
})
1717

1818
this.before ('DELETE', 'Orders', async function(req) {
1919
const { ID } = req.data
2020
const Items = await cds.tx(req).run (
21-
SELECT.from (OrderItems, oi => { oi.product_ID, oi.amount }) .where ({up__ID:ID})
21+
SELECT.from (OrderItems, oi => { oi.product_ID, oi.quantity }) .where ({up__ID:ID})
2222
)
23-
if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.amount)))
23+
if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.quantity)))
2424
})
2525

2626
return super.init()
2727
}
2828

2929
/** order changed -> broadcast event */
30-
orderChanged (product, deltaAmount) {
30+
orderChanged (product, deltaQuantity) {
3131
// Emit events to inform subscribers about changes in orders
32-
console.log ('> emitting:', 'OrderChanged', { product, deltaAmount })
33-
return this.emit ('OrderChanged', { product, deltaAmount })
32+
console.log ('> emitting:', 'OrderChanged', { product, deltaQuantity })
33+
return this.emit ('OrderChanged', { product, deltaQuantity })
3434
}
3535

3636
}

0 commit comments

Comments
 (0)