Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cdsrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ cds:
requires:
"[production]":
auth: mocked # as a sample app run with mocked auth also in production
features:
legacy_db_results: false
10 changes: 5 additions & 5 deletions srv/cat-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class CatalogService extends cds.ApplicationService { init() {
this.on ('submitOrder', async req => {
let { book:id, quantity } = req.data
if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
let succeeded = await UPDATE (Books,id)
.with `stock = stock - ${quantity}`
.where `stock >= ${quantity}`
if (succeeded.affected ?? succeeded) return
else if (!this.exists(Books,id)) req.error (404, `Book #${id} doesn't exist`)
let {affected} = await UPDATE (Books,id)
.with `stock = stock - ${quantity}`
.where `stock >= ${quantity}`
if (affected) return //> update was successful, so we are done
else if (!cds.db.exists(Books,id)) req.error (404, `Book #${id} doesn't exist`)
else req.error (409, `${quantity} exceeds stock for book #${id}`)
})

Expand Down
21 changes: 14 additions & 7 deletions test/requests.http
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@

### CatalogService.read Books
GET http://localhost:4004/browse/Books?
GET http://localhost:4004/odata/v4/browse/Books?
&$select=ID,title,author
&$filter=contains(author,'Bro')

### CatalogService.read Books/201
GET http://localhost:4004/odata/v4/browse/Books/201

### AdmingService.read Authors

### AdmingService.read Books/201
GET http://localhost:4004/admin/Books/201

### AdmingService.read Authors
GET http://localhost:4004/admin/Authors?
&$select=ID,name
&$expand=books($select=ID,title;$expand=genre($select=name))
Authorization: Basic alice:


### Same with inofficial genre/name syntax
GET http://localhost:4004/admin/Authors?
&$select=ID,name
&$expand=books($select=ID,title,genre/name)
Authorization: Basic alice:


### CatalogService.submitOrder()
POST http://localhost:4004/browse/submitOrder
POST http://localhost:4004/odata/v4/browse/submitOrder
Content-Type: application/json
Authorization: Basic bob:

### CatalogService.submitOrder(/201
POST http://localhost:4004/odata/v4/browse/submitOrder
Content-Type: application/json
Authorization: Basic bob:

Expand Down