Compare commits

..

5 Commits

Author SHA1 Message Date
Heiko Witteborg
62f32abf74 Prepare for serve_on_root false 2023-06-16 10:09:40 +02:00
Christian Georgi
536282388c Better clone path 2020-04-20 17:08:04 +02:00
Christian Georgi
75e767ed5c Add package-lock.json, fix readme 2020-04-02 15:47:34 +02:00
Christian Georgi
ba1eead6db Update readme 2020-03-23 17:06:45 +01:00
Elena Oresharova
8233703815 Add unit 3 content 2020-03-22 11:55:22 +01:00
8 changed files with 47 additions and 86 deletions

39
.vscode/launch.json vendored
View File

@@ -5,45 +5,18 @@
"version": "0.2.0",
"configurations": [
{
"name": "bookshop",
"request": "launch",
"type": "node",
"runtimeExecutable": "npx",
"runtimeArgs": [
"-n"
],
"args": [
"--",
"cds",
"run",
"--in-memory"
],
"name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
"args": [ "--", "cds", "run", "--in-memory" ],
"cwd": "${workspaceFolder}/packages/bookshop",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
},
{
"name": "cds run ...",
"request": "launch",
"type": "node",
"runtimeExecutable": "npx",
"runtimeArgs": [
"-n"
],
"args": [
"--",
"cds",
"run",
"--with-mocks",
"--in-memory?"
],
"name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
"args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ],
"cwd": "${workspaceFolder}/packages/${input:service}",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
}
],
"inputs": [

View File

@@ -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-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
```

View File

@@ -11,6 +11,7 @@ entity Books : managed {
currency : Currency;
}
@cds.autoexpose
entity Authors : managed {
key ID : Integer;
name : String(111);

View File

@@ -1,25 +1,21 @@
{
"name": "@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.",
"license": "SAP SAMPLE CODE LICENSE",
"dependencies": {
"@sap/cds": "^3",
"express": "^4"
},
"scripts": {
"start": "cds run --in-memory?",
"watch": "cds watch"
},
"cds": {
"requires": {
"db": {
"model": [
"db",
"srv"
],
"kind": "sqlite"
}
}
"name": "@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.",
"license": "SAP SAMPLE CODE LICENSE",
"dependencies": {
"@sap/cds": "^3",
"express": "^4"
},
"scripts": {
"start": "cds run --in-memory?",
"watch": "cds watch"
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
}
}
}

View File

@@ -1,6 +1,6 @@
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 Authors as projection on my.Authors;
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.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 {
entity OrderItems as select from my.OrderItems;
}

View File

@@ -3,9 +3,7 @@ using { sap.capire.bookshop as my } from '../db/schema';
@path:'/browse'
service CatalogService {
@readonly entity Books as SELECT from my.Books {*,
author.name as author
} excluding { createdBy, modifiedBy };
@readonly entity Books as SELECT from my.Books { * } excluding { createdBy, modifiedBy };
@requires_: 'authenticated-user'
@insertonly entity Orders as projection on my.Orders;

View File

@@ -1,18 +1,14 @@
### Service Document
GET http://localhost:4004/browse
### Browse Books
GET http://localhost:4004/browse/Books
### Service $metadata document
GET http://localhost:4004/browse/$metadata
### Browse Books with expanded Authors
GET http://localhost:4004/browse/Books?$expand=author
### Browsing Books
GET http://localhost:4004/browse/Books?
# &$select=title,author
# &$expand=currency
# &sap-language=de
### Try to insert into Books
POST http://localhost:4004/browse/Books
Content-Type: application/json
### 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
{
"title": "Anna Karenina",
"stock": 10
}

View File

@@ -1,18 +1,15 @@
### List Books with their current stocks
GET http://localhost:4004/admin/Books?$select=ID,stock
### List all Orders
### List all Orders - deep read
GET http://localhost:4004/admin/Orders?
&$expand=Items
### Submit Orders
### Submit Orders - deep insert
POST http://localhost:4004/browse/Orders
Content-Type: application/json
{ "OrderNo":"2019-09...", "Items":[
{ "OrderNo":"1234", "Items":[
{ "book_ID":201, "amount":5 },
{ "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