Compare commits

..

14 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
Daniel
6a9a1bc4d6 cleaned up dot files 2020-01-04 07:27:19 +01:00
Daniel
a0847e603f settings.json restored 2020-01-04 07:24:11 +01:00
Daniel
b1270bc0eb fixed launch scripts 2020-01-04 07:16:05 +01:00
Daniel
3a77707f49 Merge pull request #17 from SAP-samples/cleanup
cleaned up start scripts
2020-01-03 03:03:23 +01:00
Daniel
583c97a494 cleaned up start scripts 2020-01-03 02:59:27 +01:00
Daniel
eb7431afed fixed: dev dependency to sqlite3 2019-12-30 13:32:02 +01:00
Daniel
c0bce5ae5b Merge pull request #14 from SAP-samples/new-fiori-theme
using sap_fiori_3 theme
2019-12-13 20:09:49 +01:00
Daniel
ad05e2b9db using sap_fiori_3 theme 2019-12-13 20:08:41 +01:00
Christian Georgi
b7c2eee961 Fix broken link to VS Code plugin
Fixes #13
2019-12-13 11:55:52 +01:00
19 changed files with 940 additions and 5856 deletions

View File

@@ -6,7 +6,7 @@
"jest": true "jest": true
}, },
"parserOptions": { "parserOptions": {
"ecmaVersion": 2017 "ecmaVersion": 2018
}, },
"globals": { "globals": {
"SELECT": true, "SELECT": true,

27
.vscode/launch.json vendored
View File

@@ -5,19 +5,17 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "cds run", "name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
"request": "launch", "args": [ "--", "cds", "run", "--in-memory" ],
"type": "node", "cwd": "${workspaceFolder}/packages/bookshop",
"runtimeExecutable": "npx", "console": "integratedTerminal",
"runtimeArgs": ["-n"], "skipFiles": ["<node_internals>/**"]
"args": ["--", "cds", "run", "--with-mocks", "--in-memory?"], // the leading "--" arg ensures it works with as well as without debugging },
{
"name": "cds run ...", "request": "launch", "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",
"serverReadyAction": {
"pattern": "server listening on (https?://\\S+|[0-9]+)",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
},
"skipFiles": ["<node_internals>/**"] "skipFiles": ["<node_internals>/**"]
} }
], ],
@@ -31,12 +29,9 @@
"bookstore", "bookstore",
"media-server", "media-server",
"office-supplies", "office-supplies",
"orders-service", "reviews-service"
"products-service",
"reviews-service",
"user-service"
], ],
"default": "bookstore" "default": "bookshop"
} }
] ]
} }

View File

@@ -1,7 +1,6 @@
{ {
"files.exclude": { "files.exclude": {
"**/.gitignore": false, "**/.gitignore": true,
"**/.git": false, "**/.vscode": true
"**/.vscode": false
} }
} }

21
.vscode/tasks.json vendored
View File

@@ -4,23 +4,14 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"type": "shell", "label": "cds run bookshop", "type": "npm", "script": "watch", "path": "packages/bookshop/",
"command": "npx", "args": [ "cds", "watch", "packages/bookshop" ], "options": { "env": { "PORT": "4004" }},
"presentation": { "group": "A" }, "presentation": { "group": "A" }
"problemMatcher": []
}, },
{ {
"type": "shell", "label": "cds run bookshop-enhanced", "type": "npm", "script": "watch", "path": "packages/reviews-service/",
"command": "npx", "args": [ "cds", "watch", "packages/bookshop-enhanced" ], "options": { "env": { "PORT": "5005" }},
"presentation": { "group": "A" }, "presentation": { "group": "A" }
"problemMatcher": []
},
{
"type": "shell", "label": "cds run reviews-service",
"command": "npx", "args": [ "cds", "watch", "packages/reviews-service" ],
"options": {"env": { "PORT":"5005" }},
"presentation": { "group": "A" },
"problemMatcher": []
} }
] ]
} }

View File

@@ -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-week4-unit2-final 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
``` ```

836
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,23 +5,20 @@
"author": "daniel.hutzel@sap.com", "author": "daniel.hutzel@sap.com",
"private": true, "private": true,
"scripts": { "scripts": {
"cleanup": "lerna clean -y && rm -fr node_modules",
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
"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",
"test": "jest", "install": "(npm -s run lerna) && lerna bootstrap --hoist",
"bookshop-enhanced": "cds watch packages/bookshop-enhanced", "cleanup": "lerna clean -y && rm -fr node_modules",
"bookshop": "cds watch packages/bookshop", "bookshop": "cds watch packages/bookshop"
"bookstore": "cds watch packages/bookstore",
"products-service": "cds watch packages/products-service",
"reviews-service": "cds watch packages/reviews-service"
}, },
"dependencies": { "dependencies": {
"@sap/cds": "^3", "@sap/cds": "^3",
"express": "^4" "express": "^4"
}, },
"devDependencies": {
"sqlite3": "*"
},
"--add-these-to-devDependencies-for-tests": { "--add-these-to-devDependencies-for-tests": {
"@types/jest": "*", "@types/jest": "*",
"sqlite3": "*",
"jest": "*" "jest": "*"
}, },
"license": "SAP SAMPLE CODE LICENSE" "license": "SAP SAMPLE CODE LICENSE"

View File

@@ -43,7 +43,7 @@
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout" data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
data-sap-ui-compatVersion="edge" data-sap-ui-compatVersion="edge"
data-sap-ui-theme="sap_belize" data-sap-ui-theme="sap_fiori_3"
data-sap-ui-frameOptions="allow" data-sap-ui-frameOptions="allow"
></script> ></script>
<script> <script>

View File

@@ -1,5 +1,3 @@
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code;status ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
da86efd0-4ba1-4078-b7f0-5c9c530297f7;;2019-01-31;ALICE;;1;EUR;processing 7e2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-01-31;john.doe@test.com;;1;EUR
2f2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-03-25;ALICE;;10;EUR;completed 64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;jane.doe@test.com;;2;EUR
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;BOB;;2;EUR;processing
1af3322d-3cb1-46be-b312-0ae9ec311537;;2019-03-16;BOB;;9;EUR;completed
1 ID modifiedAt createdAt createdBy modifiedBy OrderNo currency_code status
2 da86efd0-4ba1-4078-b7f0-5c9c530297f7 7e2f2640-6866-4dcf-8f4d-3027aa831cad 2019-01-31 ALICE john.doe@test.com 1 EUR processing
3 2f2f2640-6866-4dcf-8f4d-3027aa831cad 64e718c9-ff99-47f1-8ca3-950c850777d4 2019-03-25 2019-01-30 ALICE jane.doe@test.com 10 2 EUR completed
64e718c9-ff99-47f1-8ca3-950c850777d4 2019-01-30 BOB 2 EUR processing
1af3322d-3cb1-46be-b312-0ae9ec311537 2019-03-16 BOB 9 EUR completed

View File

@@ -1,50 +1,36 @@
namespace sap.capire.bookshop; namespace sap.capire.bookshop;
using { Currency, managed, cuid } from '@sap/cds/common';
using {
Currency,
managed,
cuid
} from '@sap/cds/common';
type Status : String enum {
completed;
processing;
blocked;
}
entity Books : managed { entity Books : managed {
key ID : Integer; key ID : Integer;
title : localized String(111); title : localized String(111);
descr : localized String(1111); descr : localized String(1111);
author : Association to Authors; author : Association to Authors;
stock : Integer; stock : Integer;
price : Decimal(9, 2); price : Decimal(9,2);
currency : Currency;
}
entity Authors : managed {
key ID : Integer;
name : String(111);
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books
on books.author = $self;
}
entity Orders : cuid, managed {
OrderNo : String @title : 'Order Number'; //> readable key
status : Status default 'processing';
Items : Composition of many OrderItems
on Items.parent = $self;
total : Decimal(9, 2)@readonly;
currency : Currency; currency : Currency;
} }
@cds.autoexpose
entity Authors : managed {
key ID : Integer;
name : String(111);
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;
}
entity Orders : cuid, managed {
OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many OrderItems on Items.parent = $self;
total : Decimal(9,2) @readonly;
currency : Currency;
}
entity OrderItems : cuid { entity OrderItems : cuid {
parent : Association to Orders; parent : Association to Orders;
book : Association to Books; book : Association to Books;
amount : Integer; amount : Integer;
netAmount : Decimal(9, 2); netAmount : Decimal(9,2);
} }

View File

@@ -5,24 +5,17 @@
"license": "SAP SAMPLE CODE LICENSE", "license": "SAP SAMPLE CODE LICENSE",
"dependencies": { "dependencies": {
"@sap/cds": "^3", "@sap/cds": "^3",
"express": "^4", "express": "^4"
"@sap/xb-msg-amqp-v100": "^0.9.35"
},
"devDependencies": {
"sqlite3": "^4.1.1"
}, },
"scripts": { "scripts": {
"start": "npx cds run" "start": "cds run --in-memory?",
"watch": "cds watch"
}, },
"cds": { "cds": {
"requires": { "requires": {
"API_BUSINESS_PARTNER": { "db": {
"kind": "odata", "kind": "sql"
"model": "srv/external/API_BUSINESS_PARTNER",
"--credentials": {
"destination": "cap-api098"
}
} }
} }
} }
} }

View File

@@ -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;
} }

View File

@@ -1,20 +1,9 @@
using { sap.capire.bookshop as my } from '../db/schema'; using { sap.capire.bookshop as my } from '../db/schema';
using { API_BUSINESS_PARTNER as external } from './external/API_BUSINESS_PARTNER.csn';
@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 };
@readonly entity BusinessPartners as projection on external.A_BusinessPartner {
key BusinessPartner as ID,
FirstName,
MiddleName,
LastName,
BusinessPartnerIsBlocked
};
@requires_: 'authenticated-user' @requires_: 'authenticated-user'
@insertonly entity Orders as projection on my.Orders; @insertonly entity Orders as projection on my.Orders;

View File

@@ -1,28 +1,26 @@
const cds = require('@sap/cds') const cds = require('@sap/cds')
const { Books } = cds.entities
/** Service implementation for CatalogService */ /** Service implementation for CatalogService */
module.exports = cds.service.impl(async function () { module.exports = cds.service.impl(function() {
const { Books, Orders, BusinessPartners } = this.entities this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
const bupaSrv = await cds.connect.to('API_BUSINESS_PARTNER') this.before ('CREATE', 'Orders', _reduceStock)
this.after('READ', Books, each => each.stock > 111 && _addDiscount2(each, 11))
this.before('CREATE', Orders, _reduceStock)
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
/** Add some discount for overstocked books */
function _addDiscount2(each, discount) {
each.title += ` -- ${discount}% discount!`
}
/** Reduce stock of ordered books if available stock suffices */
async function _reduceStock(req) {
const { Items: OrderItems } = req.data
return cds.transaction(req).run(() => OrderItems.map(order =>
UPDATE(Books).set('stock -=', order.amount)
.where('ID =', order.book_ID).and('stock >=', order.amount)
)).then(all => all.forEach((affectedRows, i) => {
if (affectedRows === 0) req.error(409,
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
)
}))
}
}) })
/** Add some discount for overstocked books */
function _addDiscount2 (each,discount) {
each.title += ` -- ${discount}% discount!`
}
/** Reduce stock of ordered books if available stock suffices */
async function _reduceStock (req) {
const { Items: OrderItems } = req.data
return cds.transaction(req) .run (()=> OrderItems.map (order =>
UPDATE (Books) .set ('stock -=', order.amount)
.where ('ID =', order.book_ID) .and ('stock >=', order.amount)
)) .then (all => all.forEach ((affectedRows,i) => {
if (affectedRows === 0) req.error (409,
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
)
}))
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +0,0 @@
BusinessPartner;FirstName;MiddleName;LastName;BusinessPartnerIsBlocked
ALICE;Alice;In;Wonderland;false
BOB;Bob;The;Builder;false
JABBA;Jabba;The;Hutt;true
1 BusinessPartner FirstName MiddleName LastName BusinessPartnerIsBlocked
2 ALICE Alice In Wonderland false
3 BOB Bob The Builder false
4 JABBA Jabba The Hutt true

View File

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

View File

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