Compare commits
5 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62f32abf74 | ||
|
|
536282388c | ||
|
|
75e767ed5c | ||
|
|
ba1eead6db | ||
|
|
8233703815 |
39
.vscode/launch.json
vendored
39
.vscode/launch.json
vendored
@@ -5,45 +5,18 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "bookshop",
|
"name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
"request": "launch",
|
"args": [ "--", "cds", "run", "--in-memory" ],
|
||||||
"type": "node",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-n"
|
|
||||||
],
|
|
||||||
"args": [
|
|
||||||
"--",
|
|
||||||
"cds",
|
|
||||||
"run",
|
|
||||||
"--in-memory"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/packages/bookshop",
|
"cwd": "${workspaceFolder}/packages/bookshop",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"]
|
||||||
"<node_internals>/**"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "cds run ...",
|
"name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
"request": "launch",
|
"args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ],
|
||||||
"type": "node",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-n"
|
|
||||||
],
|
|
||||||
"args": [
|
|
||||||
"--",
|
|
||||||
"cds",
|
|
||||||
"run",
|
|
||||||
"--with-mocks",
|
|
||||||
"--in-memory?"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/packages/${input:service}",
|
"cwd": "${workspaceFolder}/packages/${input:service}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"]
|
||||||
"<node_internals>/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ In SAP Business Application Studio, open a terminal.
|
|||||||
Then clone the repo with this specific branch:
|
Then clone the repo with this specific branch:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit4
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week2-unit3
|
||||||
cd projects/cloud-cap-samples
|
cd projects/cloud-cap-samples
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ entity Books : managed {
|
|||||||
currency : Currency;
|
currency : Currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@cds.autoexpose
|
||||||
entity Authors : managed {
|
entity Authors : managed {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
name : String(111);
|
name : String(111);
|
||||||
|
|||||||
@@ -1,25 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "@sap/capire-bookshop",
|
"name": "@sap/capire-bookshop",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
|
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
|
||||||
"license": "SAP SAMPLE CODE LICENSE",
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^3",
|
"@sap/cds": "^3",
|
||||||
"express": "^4"
|
"express": "^4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cds run --in-memory?",
|
"start": "cds run --in-memory?",
|
||||||
"watch": "cds watch"
|
"watch": "cds watch"
|
||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
"db": {
|
"db": {
|
||||||
"model": [
|
"kind": "sql"
|
||||||
"db",
|
}
|
||||||
"srv"
|
|
||||||
],
|
|
||||||
"kind": "sqlite"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
|
|
||||||
service AdminService @(_requires:'authenticated-user') {
|
service AdminService @(_requires:'authenticated-user',path:'/admin') {
|
||||||
entity Books as projection on my.Books;
|
entity Books as projection on my.Books;
|
||||||
entity Authors as projection on my.Authors;
|
entity Authors as projection on my.Authors;
|
||||||
entity Orders as select from my.Orders;
|
entity Orders as select from my.Orders;
|
||||||
@@ -10,7 +10,7 @@ service AdminService @(_requires:'authenticated-user') {
|
|||||||
annotate AdminService.Orders with @odata.draft.enabled;
|
annotate AdminService.Orders with @odata.draft.enabled;
|
||||||
// annotate AdminService.Books with @odata.draft.enabled;
|
// annotate AdminService.Books with @odata.draft.enabled;
|
||||||
|
|
||||||
// Temporary workaround -> https://github.wdf.sap.corp/cap/issues/issues/3121
|
// Temporary workaround -> cap/issues#3121
|
||||||
extend service AdminService with {
|
extend service AdminService with {
|
||||||
entity OrderItems as select from my.OrderItems;
|
entity OrderItems as select from my.OrderItems;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ using { sap.capire.bookshop as my } from '../db/schema';
|
|||||||
@path:'/browse'
|
@path:'/browse'
|
||||||
service CatalogService {
|
service CatalogService {
|
||||||
|
|
||||||
@readonly entity Books as SELECT from my.Books {*,
|
@readonly entity Books as SELECT from my.Books { * } excluding { createdBy, modifiedBy };
|
||||||
author.name as author
|
|
||||||
} excluding { createdBy, modifiedBy };
|
|
||||||
|
|
||||||
@requires_: 'authenticated-user'
|
@requires_: 'authenticated-user'
|
||||||
@insertonly entity Orders as projection on my.Orders;
|
@insertonly entity Orders as projection on my.Orders;
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
### Service Document
|
### Browse Books
|
||||||
GET http://localhost:4004/browse
|
GET http://localhost:4004/browse/Books
|
||||||
|
|
||||||
### Service $metadata document
|
### Browse Books with expanded Authors
|
||||||
GET http://localhost:4004/browse/$metadata
|
GET http://localhost:4004/browse/Books?$expand=author
|
||||||
|
|
||||||
### Browsing Books
|
### Try to insert into Books
|
||||||
GET http://localhost:4004/browse/Books?
|
POST http://localhost:4004/browse/Books
|
||||||
# &$select=title,author
|
Content-Type: application/json
|
||||||
# &$expand=currency
|
|
||||||
# &sap-language=de
|
|
||||||
|
|
||||||
### Browsing Authors
|
{
|
||||||
GET http://localhost:4004/admin/Authors?
|
"title": "Anna Karenina",
|
||||||
# &$select=name,dateOfBirth,placeOfBirth
|
"stock": 10
|
||||||
# &$expand=books($select=title;$expand=currency)
|
}
|
||||||
# &$filter=ID eq 101
|
|
||||||
# &sap-language=de
|
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
|
### 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?
|
GET http://localhost:4004/admin/Orders?
|
||||||
&$expand=Items
|
&$expand=Items
|
||||||
|
|
||||||
### Submit Orders
|
### Submit Orders - deep insert
|
||||||
POST http://localhost:4004/browse/Orders
|
POST http://localhost:4004/browse/Orders
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{ "OrderNo":"2019-09...", "Items":[
|
{ "OrderNo":"1234", "Items":[
|
||||||
{ "book_ID":201, "amount":5 },
|
{ "book_ID":201, "amount":5 },
|
||||||
{ "book_ID":207, "amount":3 }
|
{ "book_ID":207, "amount":3 }
|
||||||
]}
|
]}
|
||||||
|
|
||||||
# Sending this three times should result in a 409: 5 exceeds stock for book #201
|
### Try to get the Orders
|
||||||
|
GET http://localhost:4004/browse/Orders
|
||||||
Reference in New Issue
Block a user