Compare commits

..

34 Commits

Author SHA1 Message Date
Christian Georgi
0e894313c3 Update README.md 2020-04-20 17:11:43 +02:00
Christian Georgi
83ea6a363d Add package-lock.json, fix readme 2020-04-02 16:12:08 +02:00
Christian Georgi
98cf14101a Update readme 2020-03-23 17:10:22 +01:00
D065023
401ff039ff rm other packages 2020-03-20 10:52:10 +01:00
D065023
4d8b887389 Merge branch 'OpenSAP-week4-unit1' of https://github.com/SAP-samples/cloud-cap-samples into OpenSAP-week4-unit1 2020-03-16 09:25:38 +01:00
D065023
8ab6a7ebf6 added package-lock 2020-03-16 09:25:32 +01:00
Dr. David Kunz
09eb51fa32 Update package.json 2020-02-11 11:49:25 +01:00
D065023
7a6a6a0257 rm req 2020-01-29 15:21:47 +01:00
D065023
f17c5bfa57 rm amqp 2020-01-29 15:20:23 +01:00
D065023
85498a9875 added default 2020-01-29 15:18:20 +01:00
D065023
19b09645db rm imported 2020-01-29 15:04:51 +01:00
D065023
9861b05f2d imported 2020-01-29 14:57:38 +01:00
D065023
c58bcf905f rm eventing 2020-01-29 14:51:42 +01:00
D065023
50ab059c13 comment 2020-01-29 14:46:31 +01:00
D065023
46960159d1 cleaner 2020-01-29 14:35:22 +01:00
D065023
02228e5a96 easier 2020-01-29 14:16:34 +01:00
D065023
d4793177fc rm 2020-01-29 14:13:42 +01:00
D065023
2787284aad blocked 2020-01-29 14:13:15 +01:00
D065023
61a318b250 fixed bug 2020-01-29 13:02:23 +01:00
D065023
6e42e5a173 address -> bupa 2020-01-29 12:59:59 +01:00
D065023
bf162c23cc cleaner 2020-01-29 09:55:21 +01:00
D065023
9b41615ac8 file-based not needed 2020-01-29 08:34:49 +01:00
D065023
29840afc0b data 2020-01-28 18:14:24 +01:00
D065023
fa880e2987 rm lock 2020-01-28 18:02:09 +01:00
D065023
90881558dc working 2020-01-28 18:01:53 +01:00
D065023
6d3e9a211a rm bug 2020-01-28 16:04:32 +01:00
D065023
e694fbaf13 messaging 2020-01-28 16:00:01 +01:00
D065023
43d0373d70 rm complexity 2020-01-28 15:21:46 +01:00
D065023
b632013b16 old way 2020-01-28 13:08:20 +01:00
D065023
a6deddf022 added postalcode 2020-01-28 10:41:14 +01:00
D065023
513bf9711f changed data 2020-01-28 10:40:15 +01:00
D065023
00c99c0e0b devdep 2020-01-28 10:27:23 +01:00
D065023
e042317f82 sync API 2020-01-28 09:07:23 +01:00
D065023
04ab69c48f imported 2020-01-28 08:32:37 +01:00
15 changed files with 115 additions and 949 deletions

View File

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

27
.vscode/launch.json vendored
View File

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

View File

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

21
.vscode/tasks.json vendored
View File

@@ -4,14 +4,23 @@
"version": "2.0.0",
"tasks": [
{
"type": "npm", "script": "watch", "path": "packages/bookshop/",
"options": { "env": { "PORT": "4004" }},
"presentation": { "group": "A" }
"type": "shell", "label": "cds run bookshop",
"command": "npx", "args": [ "cds", "watch", "packages/bookshop" ],
"presentation": { "group": "A" },
"problemMatcher": []
},
{
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
"options": { "env": { "PORT": "5005" }},
"presentation": { "group": "A" }
"type": "shell", "label": "cds run bookshop-enhanced",
"command": "npx", "args": [ "cds", "watch", "packages/bookshop-enhanced" ],
"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:
```sh
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit1
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit1
cd projects/cloud-cap-samples
```

836
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,24 +5,23 @@
"author": "daniel.hutzel@sap.com",
"private": true,
"scripts": {
"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",
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
"test": "jest",
"bookshop-enhanced": "cds watch packages/bookshop-enhanced",
"reviews-service": "cds watch packages/reviews-service",
"bookshop": "cds watch packages/bookshop",
"bookstore": "cds watch packages/bookstore",
"media-server": "cds watch packages/media-server"
"products-service": "cds watch packages/products-service",
"reviews-service": "cds watch packages/reviews-service"
},
"dependencies": {
"@sap/cds": "^3",
"express": "^4"
},
"devDependencies": {
"sqlite3": "*"
},
"--add-these-to-devDependencies-for-tests": {
"@types/jest": "*",
"sqlite3": "*",
"jest": "*"
},
"license": "SAP SAMPLE CODE LICENSE"

View File

@@ -43,7 +43,7 @@
<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-compatVersion="edge"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-theme="sap_belize"
data-sap-ui-frameOptions="allow"
></script>
<script>

View File

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

View File

@@ -1,35 +1,50 @@
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 {
key ID : Integer;
title : localized String(111);
descr : localized String(1111);
author : Association to Authors;
stock : Integer;
price : Decimal(9,2);
currency : Currency;
key ID : Integer;
title : localized String(111);
descr : localized String(1111);
author : Association to Authors;
stock : Integer;
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;
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;
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;
}
entity OrderItems : cuid {
parent : Association to Orders;
book : Association to Books;
amount : Integer;
netAmount : Decimal(9,2);
}
netAmount : Decimal(9, 2);
}

View File

@@ -5,17 +5,13 @@
"license": "SAP SAMPLE CODE LICENSE",
"dependencies": {
"@sap/cds": "^3",
"express": "^4"
"express": "^4",
"@sap/xb-msg-amqp-v100": "^0.9.35"
},
"devDependencies": {
"sqlite3": "^4.1.1"
},
"scripts": {
"start": "cds run --in-memory?",
"watch": "cds watch"
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
}
"start": "npx cds run"
}
}

View File

@@ -1,6 +1,6 @@
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 Authors as projection on my.Authors;
entity Orders as select from my.Orders;
@@ -10,7 +10,7 @@ service AdminService @(_requires:'authenticated-user',path:'/admin') {
annotate AdminService.Orders with @odata.draft.enabled;
// annotate AdminService.Books with @odata.draft.enabled;
// Temporary workaround -> cap/issues#3121
// Temporary workaround -> https://github.wdf.sap.corp/cap/issues/issues/3121
extend service AdminService with {
entity OrderItems as select from my.OrderItems;
}

View File

@@ -10,4 +10,4 @@ service CatalogService {
@requires_: 'authenticated-user'
@insertonly entity Orders as projection on my.Orders;
}
}

View File

@@ -1,26 +1,26 @@
const cds = require('@sap/cds')
const { Books } = cds.entities
/** Service implementation for CatalogService */
module.exports = cds.service.impl(function() {
this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
this.before ('CREATE', 'Orders', _reduceStock)
module.exports = cds.service.impl(function () {
const { Books, Orders } = this.entities
this.after('READ', Books, each => each.stock > 111 && _addDiscount2(each, 11))
this.before('CREATE', Orders, _reduceStock)
/** 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}`
)
}))
}

View File

@@ -1,25 +0,0 @@
### 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