Compare commits
24 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b97da977e5 | ||
|
|
50085fe7be | ||
|
|
8c3733c9cd | ||
|
|
a412c41970 | ||
|
|
e49e9ae823 | ||
|
|
6cc2741c3e | ||
|
|
06755978b2 | ||
|
|
02469acebb | ||
|
|
e2b47228db | ||
|
|
13480ad99e | ||
|
|
8071faa62d | ||
|
|
9ea294586a | ||
|
|
a56a11ff3e | ||
|
|
b4084b45cb | ||
|
|
26e3c0d753 | ||
|
|
6d0194acc0 | ||
|
|
db75a99808 | ||
|
|
a04755efed | ||
|
|
ba72d7f478 | ||
|
|
cd808c76dd | ||
|
|
630bb2b19c | ||
|
|
f9a7aa59de | ||
|
|
9205e0893a | ||
|
|
7137bf227e |
@@ -11,7 +11,7 @@ In SAP Business Application Studio, open a terminal.
|
||||
Then clone the repo with this specific branch:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week2-unit3
|
||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit1
|
||||
cd projects/cloud-cap-samples
|
||||
```
|
||||
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
||||
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
||||
"cleanup": "lerna clean -y && rm -fr node_modules",
|
||||
"bookshop": "cds watch packages/bookshop"
|
||||
"bookshop": "cds watch packages/bookshop",
|
||||
"bookshop-enhanced": "cds watch packages/bookshop-enhanced",
|
||||
"reviews-service": "cds watch packages/reviews-service",
|
||||
"bookstore": "cds watch packages/bookstore",
|
||||
"media-server": "cds watch packages/media-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sap/cds": "^3",
|
||||
|
||||
@@ -11,7 +11,6 @@ entity Books : managed {
|
||||
currency : Currency;
|
||||
}
|
||||
|
||||
@cds.autoexpose
|
||||
entity Authors : managed {
|
||||
key ID : Integer;
|
||||
name : String(111);
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ using { sap.capire.bookshop as my } from '../db/schema';
|
||||
@path:'/browse'
|
||||
service CatalogService {
|
||||
|
||||
@readonly entity Books as SELECT from my.Books { * } excluding { createdBy, modifiedBy };
|
||||
@readonly entity Books as SELECT from my.Books {*,
|
||||
author.name as author
|
||||
} excluding { createdBy, modifiedBy };
|
||||
|
||||
@requires_: 'authenticated-user'
|
||||
@insertonly entity Orders as projection on my.Orders;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,4 @@ async function _reduceStock (req) {
|
||||
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
|
||||
)
|
||||
}))
|
||||
}
|
||||
}
|
||||
25
packages/bookshop/tests/authors.http
Normal file
25
packages/bookshop/tests/authors.http
Normal file
@@ -0,0 +1,25 @@
|
||||
### Service Document
|
||||
GET http://localhost:4004/admin/Authors
|
||||
|
||||
### Create Author
|
||||
POST http://localhost:4004/admin/Authors HTTP/1.1
|
||||
content-Type: application/json
|
||||
|
||||
{
|
||||
"ID": 105,
|
||||
"name": "J.K. Rowling",
|
||||
"dateOfBirth": null,
|
||||
"dateOfDeath": null,
|
||||
"placeOfBirth": "",
|
||||
"placeOfDeath": ""
|
||||
}
|
||||
### Update Author
|
||||
PATCH http://localhost:4004/admin/Authors/105 HTTP/1.1
|
||||
content-Type: application/json
|
||||
|
||||
{
|
||||
"placeOfBirth": "United Kingdom"
|
||||
}
|
||||
|
||||
### Delete Author
|
||||
DELETE http://localhost:4004/admin/Authors/105 HTTP/1.1
|
||||
@@ -1,14 +1,18 @@
|
||||
### Browse Books
|
||||
GET http://localhost:4004/browse/Books
|
||||
### Service Document
|
||||
GET http://localhost:4004/browse
|
||||
|
||||
### Browse Books with expanded Authors
|
||||
GET http://localhost:4004/browse/Books?$expand=author
|
||||
### Service $metadata document
|
||||
GET http://localhost:4004/browse/$metadata
|
||||
|
||||
### Try to insert into Books
|
||||
POST http://localhost:4004/browse/Books
|
||||
Content-Type: application/json
|
||||
### Browsing Books
|
||||
GET http://localhost:4004/browse/Books?
|
||||
# &$select=title,author
|
||||
# &$expand=currency
|
||||
# &sap-language=de
|
||||
|
||||
{
|
||||
"title": "Anna Karenina",
|
||||
"stock": 10
|
||||
}
|
||||
### Browsing Authors
|
||||
GET http://localhost:4004/admin/Authors?
|
||||
# &$select=name,dateOfBirth,placeOfBirth
|
||||
# &$expand=books($select=title;$expand=currency)
|
||||
# &$filter=ID eq 101
|
||||
# &sap-language=de
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
### List all Orders - deep read
|
||||
|
||||
### List Books with their current stocks
|
||||
GET http://localhost:4004/admin/Books?$select=ID,stock
|
||||
|
||||
### List all Orders
|
||||
GET http://localhost:4004/admin/Orders?
|
||||
&$expand=Items
|
||||
|
||||
### Submit Orders - deep insert
|
||||
### Submit Orders
|
||||
POST http://localhost:4004/browse/Orders
|
||||
Content-Type: application/json
|
||||
|
||||
{ "OrderNo":"1234", "Items":[
|
||||
{ "OrderNo":"2019-09...", "Items":[
|
||||
{ "book_ID":201, "amount":5 },
|
||||
{ "book_ID":207, "amount":3 }
|
||||
]}
|
||||
|
||||
### Try to get the Orders
|
||||
GET http://localhost:4004/browse/Orders
|
||||
# Sending this three times should result in a 409: 5 exceeds stock for book #201
|
||||
Reference in New Issue
Block a user