Compare commits
29 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baccf26a56 | ||
|
|
0d6ee73920 | ||
|
|
e3159afdc2 | ||
|
|
ad9a374381 | ||
|
|
9d285805cd | ||
|
|
2faf34d264 | ||
|
|
1de3528b45 | ||
|
|
e399b9d76e | ||
|
|
dd30cd10f8 | ||
|
|
fa724d4c9c | ||
|
|
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:
|
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-week2-unit3
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit3
|
||||||
cd projects/cloud-cap-samples
|
cd projects/cloud-cap-samples
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,11 @@
|
|||||||
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
||||||
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
||||||
"cleanup": "lerna clean -y && rm -fr node_modules",
|
"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": {
|
"dependencies": {
|
||||||
"@sap/cds": "^3",
|
"@sap/cds": "^3",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("admin.Component", {
|
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("admin.Component", {
|
||||||
metadata:{ manifest:'json' }
|
metadata:{ manifest:'json' }
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libs": {
|
"libs": {
|
||||||
"sap.fe": {}
|
"sap.fe.core": {},
|
||||||
|
"sap.fe.macros": {},
|
||||||
|
"sap.fe.templates": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"models": {
|
"models": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("bookshop.Component", {
|
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("bookshop.Component", {
|
||||||
metadata:{ manifest:'json' }
|
metadata:{ manifest:'json' }
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libs": {
|
"libs": {
|
||||||
"sap.fe": {}
|
"sap.fe.core": {},
|
||||||
|
"sap.fe.macros": {},
|
||||||
|
"sap.fe.templates": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"models": {
|
"models": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("orders.Component", {
|
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("orders.Component", {
|
||||||
metadata:{ manifest:'json' }
|
metadata:{ manifest:'json' }
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libs": {
|
"libs": {
|
||||||
"sap.fe": {}
|
"sap.fe.core": {},
|
||||||
|
"sap.fe.macros": {},
|
||||||
|
"sap.fe.templates": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"models": {
|
"models": {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ 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);
|
||||||
|
|||||||
44
packages/bookshop/mta.yaml
Normal file
44
packages/bookshop/mta.yaml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
####### Generated mta.yaml based on template version 0.2.0
|
||||||
|
####### appName = capire-bookshop
|
||||||
|
####### language=nodejs; multiTenant=false
|
||||||
|
####### approuter=
|
||||||
|
|
||||||
|
_schema-version: '3.1'
|
||||||
|
ID: sap.capire-bookshop
|
||||||
|
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."
|
||||||
|
|
||||||
|
build-parameters:
|
||||||
|
before-all:
|
||||||
|
- builder: custom
|
||||||
|
commands:
|
||||||
|
- npm install
|
||||||
|
- cds build/all
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
enable-parallel-deployments: true
|
||||||
|
|
||||||
|
modules:
|
||||||
|
############## SERVER MODULE ##########################
|
||||||
|
- name: capire-bookshop-srv
|
||||||
|
type: nodejs
|
||||||
|
path: gen/srv
|
||||||
|
properties:
|
||||||
|
EXIT: 1 # required by deploy.js task to terminate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
############## SIDECAR MODULE #########################
|
||||||
|
- name: db
|
||||||
|
|
||||||
|
type: hdb
|
||||||
|
path: gen/db
|
||||||
|
parameters:
|
||||||
|
app-name: capire-bookshop-db
|
||||||
|
requires:
|
||||||
|
#### Hana and xsuaa resources extracted from CAP configuration ####
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
|
||||||
2027
packages/bookshop/package-lock.json
generated
Normal file
2027
packages/bookshop/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,8 @@
|
|||||||
"license": "SAP SAMPLE CODE LICENSE",
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^3",
|
"@sap/cds": "^3",
|
||||||
"express": "^4"
|
"express": "^4",
|
||||||
|
"sqlite3": "^5.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cds run --in-memory?",
|
"start": "cds run --in-memory?",
|
||||||
@@ -18,4 +19,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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',path:'/admin') {
|
service AdminService @(_requires:'authenticated-user') {
|
||||||
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;
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ 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 { * } excluding { createdBy, modifiedBy };
|
@readonly entity Books as SELECT from my.Books {*,
|
||||||
|
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;
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ async function _reduceStock (req) {
|
|||||||
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
|
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
### Browse Books
|
### Service Document
|
||||||
GET http://localhost:4004/browse/Books
|
GET http://localhost:4004/browse
|
||||||
|
|
||||||
### Browse Books with expanded Authors
|
### Service $metadata document
|
||||||
GET http://localhost:4004/browse/Books?$expand=author
|
GET http://localhost:4004/browse/$metadata
|
||||||
|
|
||||||
### Try to insert into Books
|
### Browsing Books
|
||||||
POST http://localhost:4004/browse/Books
|
GET http://localhost:4004/browse/Books?
|
||||||
Content-Type: application/json
|
# &$select=title,author
|
||||||
|
# &$expand=currency
|
||||||
|
# &sap-language=de
|
||||||
|
|
||||||
{
|
### Browsing Authors
|
||||||
"title": "Anna Karenina",
|
GET http://localhost:4004/admin/Authors?
|
||||||
"stock": 10
|
# &$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?
|
GET http://localhost:4004/admin/Orders?
|
||||||
&$expand=Items
|
&$expand=Items
|
||||||
|
|
||||||
### Submit Orders - deep insert
|
### Submit Orders
|
||||||
POST http://localhost:4004/browse/Orders
|
POST http://localhost:4004/browse/Orders
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{ "OrderNo":"1234", "Items":[
|
{ "OrderNo":"2019-09...", "Items":[
|
||||||
{ "book_ID":201, "amount":5 },
|
{ "book_ID":201, "amount":5 },
|
||||||
{ "book_ID":207, "amount":3 }
|
{ "book_ID":207, "amount":3 }
|
||||||
]}
|
]}
|
||||||
|
|
||||||
### Try to get the Orders
|
# Sending this three times should result in a 409: 5 exceeds stock for book #201
|
||||||
GET http://localhost:4004/browse/Orders
|
|
||||||
Reference in New Issue
Block a user