Compare commits
156 Commits
openSAP-we
...
dkom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2febd57db | ||
|
|
5073af37d3 | ||
|
|
e8cda443ba | ||
|
|
da63d6c287 | ||
|
|
009dfc53c5 | ||
|
|
d760516e3e | ||
|
|
261d238738 | ||
|
|
136eae69eb | ||
|
|
e0306850b4 | ||
|
|
b7f9b78988 | ||
|
|
4e5f31a29d | ||
|
|
2d7efafd30 | ||
|
|
cf0b9c2a52 | ||
|
|
2053450404 | ||
|
|
920600a5ff | ||
|
|
dc1ea91d9e | ||
|
|
9ba5aae999 | ||
|
|
29aee15cf3 | ||
|
|
2ca5a79c7e | ||
|
|
857b28aad0 | ||
|
|
91d1a9bcb2 | ||
|
|
a33dbff74e | ||
|
|
7f65729dc9 | ||
|
|
6a9a1bc4d6 | ||
|
|
a0847e603f | ||
|
|
b1270bc0eb | ||
|
|
3c4aa7427e | ||
|
|
3a77707f49 | ||
|
|
583c97a494 | ||
|
|
28859993ba | ||
|
|
e503f157f6 | ||
|
|
4eebfb5df4 | ||
|
|
28362cc835 | ||
|
|
78e6138718 | ||
|
|
7db2c6e781 | ||
|
|
afc5be2610 | ||
|
|
5bc8d4dde0 | ||
|
|
60563dc816 | ||
|
|
eb7431afed | ||
|
|
4a1887f424 | ||
|
|
c28287f9e4 | ||
|
|
8cadac0051 | ||
|
|
034c3b84f7 | ||
|
|
b155754a72 | ||
|
|
782e8a6696 | ||
|
|
f3c14a0625 | ||
|
|
4cffa85079 | ||
|
|
837e6bf1c8 | ||
|
|
b394dbd234 | ||
|
|
fdd0a256c4 | ||
|
|
5b5d9da82e | ||
|
|
2af54a520c | ||
|
|
128213aba7 | ||
|
|
4bc2257cea | ||
|
|
e16a343ce3 | ||
|
|
1f01bdf202 | ||
|
|
45843ab7bd | ||
|
|
421cea9f2b | ||
|
|
aa919f9d62 | ||
|
|
ed814a1f75 | ||
|
|
c04c93cca6 | ||
|
|
2cde812edd | ||
|
|
2f576dbb1b | ||
|
|
7f7cd43bff | ||
|
|
294f9feb36 | ||
|
|
2ebfcd8871 | ||
|
|
963d0fbb6c | ||
|
|
eebdd74bfe | ||
|
|
37810c9027 | ||
|
|
48a086e9a1 | ||
|
|
659c347c71 | ||
|
|
0bbb8e3d3b | ||
|
|
b3abcbcaae | ||
|
|
3716d4d5e3 | ||
|
|
226094e85c | ||
|
|
de149ea9b3 | ||
|
|
b6c1610817 | ||
|
|
3df0981992 | ||
|
|
8c8c5f3f9d | ||
|
|
2c0f69a161 | ||
|
|
54d0c8b35d | ||
|
|
3027a7a1e5 | ||
|
|
8eaf34f5d3 | ||
|
|
0b0a22d126 | ||
|
|
c0e1fb38ac | ||
|
|
74c155ca62 | ||
|
|
db16577235 | ||
|
|
53989cf609 | ||
|
|
d678b51320 | ||
|
|
5720d73b76 | ||
|
|
06a6ac2201 | ||
|
|
125edc34e2 | ||
|
|
dc8e8c55df | ||
|
|
f89acc00dd | ||
|
|
3e725bcc26 | ||
|
|
dfea19334d | ||
|
|
8f11de5430 | ||
|
|
38ce94d5cd | ||
|
|
ffe633a493 | ||
|
|
e081182a7c | ||
|
|
e4f8f13dbf | ||
|
|
cc698ec23f | ||
|
|
382a4c562d | ||
|
|
811694cdf1 | ||
|
|
83653bd095 | ||
|
|
e27275d29a | ||
|
|
b9330d7f77 | ||
|
|
c0bce5ae5b | ||
|
|
ad05e2b9db | ||
|
|
f413b45e24 | ||
|
|
4a21b9edc3 | ||
|
|
b7c2eee961 | ||
|
|
4bfd4430e1 | ||
|
|
0bb3144aea | ||
|
|
c1d2c4caef | ||
|
|
59f68c0f28 | ||
|
|
5ba3458b27 | ||
|
|
199b2c8045 | ||
|
|
3b4abf5600 | ||
|
|
f69c0ae190 | ||
|
|
f48cd1cc2f | ||
|
|
6bded9df98 | ||
|
|
5a659774b5 | ||
|
|
17d6dc8cf8 | ||
|
|
1a1686e340 | ||
|
|
b298c9b708 | ||
|
|
348a7b191e | ||
|
|
f56d4fe093 | ||
|
|
02942f5e1a | ||
|
|
1aa9237d20 | ||
|
|
7a760cfaf8 | ||
|
|
6c0d8fa444 | ||
|
|
3b06003328 | ||
|
|
e686b1819b | ||
|
|
d36c2a97fa | ||
|
|
f4e119342b | ||
|
|
ddd02b52f2 | ||
|
|
e6d5183cce | ||
|
|
a191ecf88d | ||
|
|
140db39cd4 | ||
|
|
68ee29598a | ||
|
|
7deae997bb | ||
|
|
12aee3e38c | ||
|
|
dfe876e2cf | ||
|
|
9e2c7a0974 | ||
|
|
30b2854fac | ||
|
|
4ca7e425ec | ||
|
|
28a51f4837 | ||
|
|
692a360065 | ||
|
|
b3d9fdb8b3 | ||
|
|
e9d10986ff | ||
|
|
7191f61806 | ||
|
|
e688e7ecee | ||
|
|
4a2139a5f2 | ||
|
|
ed3ecd502f | ||
|
|
8f3d112558 |
@@ -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
27
.vscode/launch.json
vendored
@@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/.gitignore": false,
|
"**/.gitignore": true,
|
||||||
"**/.git": false,
|
"**/.vscode": true
|
||||||
"**/.vscode": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
.vscode/tasks.json
vendored
21
.vscode/tasks.json
vendored
@@ -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": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
79
README.md
79
README.md
@@ -1,42 +1,73 @@
|
|||||||
# Welcome to SAP Cloud Application Programming model samples
|
# cloud-cap-samples
|
||||||
|
|
||||||
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
|
This is a monorepository for sample projects on [SAP Cloud Application Programming Model](https://cap.cloud.sap).
|
||||||
|
|
||||||
## Get Access to SAP Business Application Studio
|
## Description
|
||||||
The recommended environment for the course is SAP Business Application Studio. Watch [unit 2 of week 1](https://open.sap.com/courses/cp7/items/51pzQUzbXHr2kdbOmVs6jI) for how to get access.
|
|
||||||
|
|
||||||
## Setup
|
This repository provides a list of samples and reusable packages created based on SAP Cloud Application Programming Model.
|
||||||
|
The SAP Cloud Application Programming Model enables you to quickly create business applications by allowing you to focus on your domain logic. It offers a consistent end-to-end programming model that includes languages, libraries and APIs tailored for full-stack development on SAP Cloud Platform.
|
||||||
|
|
||||||
In SAP Business Application Studio, open a terminal.
|
The samples provided can be run in a local setup on SQLite Database.
|
||||||
Then clone the repo with this specific branch:
|
|
||||||
|
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
* [Node.js](https://nodejs.org/en/) v8 or higher
|
||||||
|
* [Git](https://git-scm.com)
|
||||||
|
* [SQLite DB](https://www.sqlite.org/download.html) (Windows only; pre-installed on Mac/Linux)
|
||||||
|
|
||||||
|
#### Optional (if you want to import the code into an editor)
|
||||||
|
* [VS Code](https://code.visualstudio.com)
|
||||||
|
* [Add CDS extension to VS](https://cap.cloud.sap/docs/get-started/in-vscode#add-cds-editor)
|
||||||
|
|
||||||
|
## Download and Installation
|
||||||
|
|
||||||
|
#### Install `cds` development kit
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit1
|
# sets the registry for `@sap` packages
|
||||||
cd projects/cloud-cap-samples
|
npm set @sap:registry=https://npm.sap.com
|
||||||
|
|
||||||
|
npm install -g @sap/cds-dk
|
||||||
|
cds #> test-run it
|
||||||
```
|
```
|
||||||
|
Got issues? Check out the [documentation](https://cap.cloud.sap/docs/get-started/).
|
||||||
|
|
||||||
In the `cloud-cap-samples` folder run:
|
#### Clone and build the application
|
||||||
```sh
|
`git clone https://github.com/SAP-samples/cloud-cap-samples samples && cd samples && npm i`
|
||||||
npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Run
|
#### Run the samples
|
||||||
|
|
||||||
Now you're ready to run the samples, for example:
|
With that you're ready to run the samples, e.g. start the [_bookshop_](./packages/bookshop) sample as follows:
|
||||||
```sh
|
|
||||||
cd packages/bookshop
|
|
||||||
cds watch
|
|
||||||
```
|
|
||||||
|
|
||||||
After that, watch out for the little popup in the lower right corner of SAP Business Application Studio that asks you to open the application in your browser.
|
`npm run bookshop`
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
For example, try these links in your browser:
|
||||||
|
- <http://localhost:4004> to test with generic index page.
|
||||||
|
- <http://localhost:4004/fiori.html> to test with Fiori sandbox.
|
||||||
|
|
||||||
|
|
||||||
## Get Support
|
## Debug
|
||||||
|
|
||||||
Check out the cap docs at https://cap.cloud.sap. <br>
|
For example, in [VS Code](https://code.visualstudio.com) switch to _Debug_ view and launch one of the prepared _cds run_ launch configurations.
|
||||||
In case you find a bug or need support, please [open an issue in here](https://github.com/SAP-samples/cloud-cap-samples/issues/new).
|
|
||||||
|
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
## Known Issues
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
## How to obtain support
|
||||||
|
|
||||||
|
Check out the documentation on https://cap.cloud.sap. In case you find a bug, or you need additional support, please open an issue [here](https://github.com/SAP-samples/cloud-cap-samples/issues/new) in GitHub.
|
||||||
|
|
||||||
|
## To-Do (upcoming changes)
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.
|
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.
|
||||||
|
|||||||
1228
package-lock.json
generated
1228
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -5,23 +5,23 @@
|
|||||||
"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",
|
"bookshop-enhanced": "cds watch packages/bookshop-enhanced",
|
||||||
"products-service": "cds watch packages/products-service",
|
"reviews-service": "cds watch packages/reviews-service",
|
||||||
"reviews-service": "cds watch packages/reviews-service"
|
"bookstore": "cds watch packages/bookstore"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^3",
|
"@sap/cds": "latest",
|
||||||
"express": "^4"
|
"express": "*"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
|||||||
1
packages/bookshop-enhanced/app/index.cds
Normal file
1
packages/bookshop-enhanced/app/index.cds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
using from '@sap/capire-bookshop/app';
|
||||||
25
packages/bookshop-enhanced/db/schema.cds
Normal file
25
packages/bookshop-enhanced/db/schema.cds
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
In this model we demonstrate how to add Genres to Books in
|
||||||
|
as if it was an external extension. For example we use
|
||||||
|
CDS Aspects' to extend the core domain model's Books entity
|
||||||
|
as well as the AdminService.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace sap.capire.bookshop;
|
||||||
|
using { sap.capire.reviews.ReviewsService as external } from '@sap/capire-reviews';
|
||||||
|
using { sap.capire.bookshop.Books } from '@sap/capire-bookshop/db/schema';
|
||||||
|
using { sap.common.CodeList } from '@sap/cds/common';
|
||||||
|
|
||||||
|
// Extending Books by Reviews and Genres
|
||||||
|
extend Books with {
|
||||||
|
reviews : Composition of many external.Reviews on reviews.subject = ID;
|
||||||
|
rating : external.Reviews.rating;
|
||||||
|
genre : Association to Genres;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hierarchical Code List for Genres
|
||||||
|
entity Genres : CodeList {
|
||||||
|
key ID : Integer;
|
||||||
|
children : Composition of many Genres on children.parent = $self;
|
||||||
|
parent : Association to Genres;
|
||||||
|
}
|
||||||
29
packages/bookshop-enhanced/package.json
Normal file
29
packages/bookshop-enhanced/package.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-bookshop-enhanced",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A sample for extending a base application package, in this case bookshop, e.g. in context of verticalization or customization.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/capire-bookshop": "^1.0.0",
|
||||||
|
"@sap/capire-reviews": "^1.0.0",
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"reviews-service": "PORT=5005 cds run ../reviews-service --bind --in-memory?",
|
||||||
|
"start": "cds run --in-memory?",
|
||||||
|
"watch": "cds watch"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"sap.capire.reviews.ReviewsService": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "@sap/capire-reviews"
|
||||||
|
},
|
||||||
|
"messaging": {
|
||||||
|
"kind": "file-based-messaging"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
packages/bookshop-enhanced/srv/services.cds
Normal file
9
packages/bookshop-enhanced/srv/services.cds
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace sap.capire.bookshop;
|
||||||
|
|
||||||
|
using { AdminService } from '@sap/capire-bookshop/srv/admin-service';
|
||||||
|
using { sap.capire.bookshop } from '../db/schema';
|
||||||
|
|
||||||
|
@impl:'srv/services'
|
||||||
|
extend service AdminService with {
|
||||||
|
entity Genres as projection on bookshop.Genres;
|
||||||
|
}
|
||||||
30
packages/bookshop-enhanced/srv/services.js
Normal file
30
packages/bookshop-enhanced/srv/services.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
module.exports = cds.service.impl (async()=>{
|
||||||
|
|
||||||
|
const ReviewsService = await cds.connect.to ('sap.capire.reviews.ReviewsService')
|
||||||
|
const CatalogService = await cds.connect.to ('CatalogService')
|
||||||
|
const db = await cds.connect.to ('db')
|
||||||
|
// import model definitions from connected services to work with subsequently
|
||||||
|
const { Books } = db.entities
|
||||||
|
const { Reviews } = ReviewsService.entities
|
||||||
|
|
||||||
|
CatalogService.impl (srv => {
|
||||||
|
// delegate requests to read reviews to ReviewsService
|
||||||
|
srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
|
const [ subject ] = req.params
|
||||||
|
const tx = ReviewsService.transaction (req)
|
||||||
|
return tx.run (SELECT.from (Reviews) .where ({subject}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// react on event messages from reviews service
|
||||||
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
|
const { subject, rating } = msg.data
|
||||||
|
const tx = db // TODO: db.transaction (msg)
|
||||||
|
return tx.run (UPDATE (Books, subject) .with ({rating}))
|
||||||
|
// return tx.update (Books, subject) .with ({rating})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
33
packages/bookshop-enhanced/tests/genres.http
Normal file
33
packages/bookshop-enhanced/tests/genres.http
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#################################################
|
||||||
|
#
|
||||||
|
# Genres
|
||||||
|
#
|
||||||
|
|
||||||
|
GET http://localhost:4004/admin/Genres?
|
||||||
|
###
|
||||||
|
|
||||||
|
POST http://localhost:4004/admin/Genres?
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{ "ID":100, "name":"Some Sample Genres...", "children":[
|
||||||
|
{ "ID":101, "name":"Cat", "children":[
|
||||||
|
{ "ID":102, "name":"Kitty", "children":[
|
||||||
|
{ "ID":103, "name":"Kitty Cat", "children":[
|
||||||
|
{ "ID":104, "name":"Aristocat" } ]},
|
||||||
|
{ "ID":105, "name":"Kitty Bat" } ]},
|
||||||
|
{ "ID":106, "name":"Catwoman", "children":[
|
||||||
|
{ "ID":107, "name":"Catalina" } ]} ]},
|
||||||
|
{ "ID":108, "name":"Catweazle" }
|
||||||
|
]}
|
||||||
|
###
|
||||||
|
|
||||||
|
GET http://localhost:4004/admin/Genres(100)?
|
||||||
|
# &$expand=children
|
||||||
|
# &$expand=children($expand=children($expand=children($expand=children)))
|
||||||
|
###
|
||||||
|
|
||||||
|
DELETE http://localhost:4004/admin/Genres(103)
|
||||||
|
###
|
||||||
|
|
||||||
|
DELETE http://localhost:4004/admin/Genres(100)
|
||||||
|
###
|
||||||
32
packages/bookshop-enhanced/tests/reviews.http
Normal file
32
packages/bookshop-enhanced/tests/reviews.http
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#################################################
|
||||||
|
#
|
||||||
|
# Reviews Service
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
### Use this one for ReviewsService running as a separate process
|
||||||
|
# Note: use 5005 instead of 4004 in case of separate service
|
||||||
|
POST http://localhost:5005/reviews/Reviews
|
||||||
|
# POST http://localhost:4004/reviews/Reviews
|
||||||
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
|
|
||||||
|
{"subject":"201", "rating":"5", "title":"boo"}
|
||||||
|
|
||||||
|
### Direct Request to ReviewsService
|
||||||
|
# Note: use 5005 instead of 4004 in case of separate service
|
||||||
|
GET http://localhost:5005/reviews/Reviews?
|
||||||
|
# GET http://localhost:4004/reviews/Reviews?
|
||||||
|
# &$filter=subject eq '201'
|
||||||
|
|
||||||
|
|
||||||
|
### Request to CatalogService > delegated to ReviewsService
|
||||||
|
GET http://localhost:4004/browse/Books(201)/reviews
|
||||||
|
|
||||||
|
### Alternative OData URL
|
||||||
|
GET http://localhost:4004/browse/Books/201/reviews
|
||||||
|
|
||||||
|
###
|
||||||
|
GET http://localhost:4004/browse/Books(201)?
|
||||||
|
&$select=ID,title,rating
|
||||||
|
# &$expand=reviews
|
||||||
|
# Note: the latter only works in case of ReviewsService in same process
|
||||||
3
packages/bookshop/.prettierrc
Normal file
3
packages/bookshop/.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 120
|
||||||
|
}
|
||||||
65
packages/bookshop/README.md
Normal file
65
packages/bookshop/README.md
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# Bookshop With Address Data From SAP S/4HANA
|
||||||
|
|
||||||
|
This is an extended bookshop with business-partner address data from SAP S/4HANA.
|
||||||
|
When the user creates an order and uses the value help of the shipping address,
|
||||||
|
a synchronous request to SAP S/4HANA is triggered yielding all possible addresses
|
||||||
|
belonging to this business partner. Once an address is selected, its data
|
||||||
|
is replicated into a local database. To keep data in sync, an event handler
|
||||||
|
is registered which listens to all changes of business partners and updates the
|
||||||
|
local database table.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
`@sap/cds` >= 1.30
|
||||||
|
|
||||||
|
|
||||||
|
## Running With Mocks
|
||||||
|
Just execute the following command in the `bookshop` folder.
|
||||||
|
```
|
||||||
|
cds run --in-memory --with-mocks
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Running With an S/4HANA Backend
|
||||||
|
|
||||||
|
To run your app in non-mock mode you need an SAP S/4HANA Cloud system and connect it to your SAP Cloud Platform. You can use the
|
||||||
|
[SAP Cloud Platform Extension Factory](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/346864df64f24011b49abee07bbd79af.html) to automate parts of this task. You need to enable synchronous APIs as well as events that are sent whenever business partners are changed.
|
||||||
|
|
||||||
|
To run the app locally, you need to create a `default-env.json` file in the `bookshop` folder containing the binding information (credentials of Enterprise Messaging as well as the destination to the business-partner service).
|
||||||
|
|
||||||
|
Provide the credentials in the `cds.requires` section of the `package.json` file in the `bookshop` folder, e.g.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"API_BUSINESS_PARTNER": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "srv/external",
|
||||||
|
"credentials": {
|
||||||
|
"destination": "cap-api098"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"messaging": {
|
||||||
|
"kind": "enterprise-messaging",
|
||||||
|
"credentials": {
|
||||||
|
"prefix": "sap/S4HANAOD/c098/BO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Here, `destination` is the destination of your business-partner service and `prefix` is the prefix
|
||||||
|
of the topic of the events.
|
||||||
|
|
||||||
|
Then simply run the following command in the `bookshop` folder.
|
||||||
|
```
|
||||||
|
cds run --in-memory
|
||||||
|
```
|
||||||
|
|
||||||
|
## User Flow
|
||||||
|
After starting the app, go to http://localhost:4004/fiori.html#Shell-home and open the app `Manage Orders` to create an order.
|
||||||
|
Use the value help of the shipping address to select an address. Create an order item and save the order.
|
||||||
|
Then change the address of your business partner (in the mocked case you can trigger the PATCH request in `req.http` ). Refresh
|
||||||
|
the object page of your order and see the change.
|
||||||
@@ -9,5 +9,14 @@ Name = Name
|
|||||||
AuthorName = Author's Name
|
AuthorName = Author's Name
|
||||||
Authors = Authors
|
Authors = Authors
|
||||||
Order = Order
|
Order = Order
|
||||||
|
OrderItems = Order Items
|
||||||
Orders = Orders
|
Orders = Orders
|
||||||
Price = Price
|
Price = Price
|
||||||
|
shippingAddress = Shipping Address
|
||||||
|
cityName = City Name
|
||||||
|
houseNumber = House Number
|
||||||
|
streetName = Street Name
|
||||||
|
postalCode = Postal Code
|
||||||
|
country = Country
|
||||||
|
AddressID = Address ID
|
||||||
|
contact = Contact
|
||||||
|
|||||||
@@ -72,3 +72,13 @@ annotate my.Authors with {
|
|||||||
ID @title:'{i18n>ID}' @UI.HiddenFilter;
|
ID @title:'{i18n>ID}' @UI.HiddenFilter;
|
||||||
name @title:'{i18n>AuthorName}';
|
name @title:'{i18n>AuthorName}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
annotate my.Addresses with {
|
||||||
|
ID @title:'{i18n>AddressID}';
|
||||||
|
contact @title:'{i18n>contact}';
|
||||||
|
@readonly cityName @title:'{i18n>cityName}';
|
||||||
|
@readonly streetName @title:'{i18n>streetName}';
|
||||||
|
@readonly postalCode @title:'{i18n>postalCode}';
|
||||||
|
@readonly country @title:'{i18n>country}';
|
||||||
|
@readonly houseNumber @title:'{i18n>houseNumber}';
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -1,117 +1,243 @@
|
|||||||
using AdminService from '../../srv/admin-service';
|
using AdminService from '../../srv/admin-service';
|
||||||
|
|
||||||
annotate AdminService.Books with {
|
annotate AdminService.Books with {
|
||||||
price @Common.FieldControl: #ReadOnly;
|
price @Common.FieldControl : #ReadOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Common
|
// Common
|
||||||
//
|
//
|
||||||
annotate AdminService.OrderItems with {
|
annotate AdminService.OrderItems with {
|
||||||
book @(
|
book @(
|
||||||
Common: {
|
Common : {
|
||||||
Text: book.title,
|
Text : book.title,
|
||||||
FieldControl: #Mandatory
|
FieldControl : #Mandatory
|
||||||
},
|
},
|
||||||
ValueList.entity:'Books',
|
ValueList.entity : 'Books',
|
||||||
);
|
);
|
||||||
amount @(
|
amount @(Common.FieldControl : #Mandatory);
|
||||||
Common.FieldControl: #Mandatory
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
annotate AdminService.Orders with {
|
||||||
|
shippingAddress @(Common : {
|
||||||
|
FieldControl : #Mandatory,
|
||||||
|
ValueList : {
|
||||||
|
CollectionPath : 'Addresses',
|
||||||
|
Label : 'Addresses',
|
||||||
|
SearchSupported : 'true',
|
||||||
|
Parameters : [
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterOut',
|
||||||
|
LocalDataProperty : 'shippingAddress_ID',
|
||||||
|
ValueListProperty : 'ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterOut',
|
||||||
|
LocalDataProperty : 'shippingAddress_contact',
|
||||||
|
ValueListProperty : 'contact'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||||
|
ValueListProperty : 'postalCode'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||||
|
ValueListProperty : 'cityName'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||||
|
ValueListProperty : 'country'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||||
|
ValueListProperty : 'streetName'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||||
|
ValueListProperty : 'houseNumber'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
annotate AdminService.Orders with @(
|
////////////////////////////////////////////////////////////////////////////
|
||||||
UI: {
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////
|
// UI
|
||||||
//
|
//
|
||||||
// Lists of Orders
|
annotate AdminService.Orders with @(UI : {
|
||||||
//
|
////////////////////////////////////////////////////////////////////////////
|
||||||
SelectionFields: [ createdAt, createdBy ],
|
//
|
||||||
LineItem: [
|
// Lists of Orders
|
||||||
{Value: createdBy, Label:'Customer'},
|
//
|
||||||
{Value: createdAt, Label:'Date'}
|
SelectionFields : [
|
||||||
],
|
createdAt,
|
||||||
////////////////////////////////////////////////////////////////////////////
|
createdBy
|
||||||
//
|
],
|
||||||
// Order Details
|
LineItem : [
|
||||||
//
|
{
|
||||||
HeaderInfo: {
|
Value : createdBy,
|
||||||
TypeName: 'Order', TypeNamePlural: 'Orders',
|
Label : 'Customer'
|
||||||
Title: {
|
},
|
||||||
Label: 'Order number ', //A label is possible but it is not considered on the ObjectPage yet
|
{
|
||||||
Value: OrderNo
|
Value : createdAt,
|
||||||
},
|
Label : 'Date'
|
||||||
Description: {Value: createdBy}
|
}
|
||||||
},
|
],
|
||||||
Identification: [ //Is the main field group
|
////////////////////////////////////////////////////////////////////////////
|
||||||
{Value: createdBy, Label:'Customer'},
|
//
|
||||||
{Value: createdAt, Label:'Date'},
|
// Order Details
|
||||||
{Value: OrderNo },
|
//
|
||||||
],
|
HeaderInfo : {
|
||||||
HeaderFacets: [
|
TypeName : 'Order',
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Created}', Target: '@UI.FieldGroup#Created'},
|
TypeNamePlural : 'Orders',
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Modified}', Target: '@UI.FieldGroup#Modified'},
|
Title : {
|
||||||
],
|
Label : 'Order number ', //A label is possible but it is not considered on the ObjectPage yet
|
||||||
Facets: [
|
Value : OrderNo
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
|
},
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: 'Items/@UI.LineItem'},
|
Description : {Value : createdBy}
|
||||||
],
|
},
|
||||||
FieldGroup#Details: {
|
Identification : [ //Is the main field group
|
||||||
Data: [
|
// labels not considered
|
||||||
{Value: currency_code, Label:'Currency'}
|
{
|
||||||
]
|
Value : createdBy,
|
||||||
},
|
Label : 'Customer'
|
||||||
FieldGroup#Created: {
|
},
|
||||||
Data: [
|
{
|
||||||
{Value: createdBy},
|
Value : createdAt,
|
||||||
{Value: createdAt},
|
Label : 'Date'
|
||||||
]
|
},
|
||||||
},
|
{Value : OrderNo},
|
||||||
FieldGroup#Modified: {
|
{
|
||||||
Data: [
|
Value : 'shippingAddress_ID',
|
||||||
{Value: modifiedBy},
|
Label : 'Address ID'
|
||||||
{Value: modifiedAt},
|
}
|
||||||
]
|
],
|
||||||
},
|
HeaderFacets : [
|
||||||
},
|
{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>Created}',
|
||||||
|
Target : '@UI.FieldGroup#Created'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>Modified}',
|
||||||
|
Target : '@UI.FieldGroup#Modified'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Facets : [
|
||||||
|
{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>shippingAddress}',
|
||||||
|
Target : '@UI.FieldGroup#ShippingAddress'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>Details}',
|
||||||
|
Target : '@UI.FieldGroup#Details'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>OrderItems}',
|
||||||
|
Target : 'Items/@UI.LineItem'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
FieldGroup #Details : {Data : [{
|
||||||
|
Value : currency_code,
|
||||||
|
Label : 'Currency'
|
||||||
|
}]},
|
||||||
|
FieldGroup #Created : {Data : [
|
||||||
|
{Value : createdBy},
|
||||||
|
{Value : createdAt},
|
||||||
|
]},
|
||||||
|
FieldGroup #Modified : {Data : [
|
||||||
|
{Value : modifiedBy},
|
||||||
|
{Value : modifiedAt},
|
||||||
|
]},
|
||||||
|
FieldGroup #ShippingAddress : {Data : [
|
||||||
|
{
|
||||||
|
Value : shippingAddress_ID,
|
||||||
|
Label : '{i18n>shippingAddress}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value : shippingAddress.houseNumber,
|
||||||
|
Label : '{i18n>houseNumber}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value : shippingAddress.streetName,
|
||||||
|
Label : '{i18n>streetName}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value : shippingAddress.cityName,
|
||||||
|
Label : '{i18n>cityName}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value : shippingAddress.postalCode,
|
||||||
|
Label : '{i18n>postalCode}'
|
||||||
|
},
|
||||||
|
]},
|
||||||
|
},
|
||||||
|
Common.SideEffects : {
|
||||||
|
EffectTypes : #ValueChange,
|
||||||
|
SourceProperties : [shippingAddress_ID],
|
||||||
|
TargetProperties : [
|
||||||
|
shippingAddress.country,
|
||||||
|
shippingAddress.houseNumber,
|
||||||
|
shippingAddress.streetName,
|
||||||
|
shippingAddress.cityName,
|
||||||
|
shippingAddress.postalCode
|
||||||
|
]
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
createdAt @UI.HiddenFilter:false;
|
createdAt @UI.HiddenFilter : false;
|
||||||
createdBy @UI.HiddenFilter:false;
|
createdBy @UI.HiddenFilter : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//The enity types name is AdminService.my_bookshop_OrderItems
|
//The enity types name is AdminService.my_bookshop_OrderItems
|
||||||
//The annotations below are not generated in edmx WHY?
|
//The annotations below are not generated in edmx WHY?
|
||||||
annotate AdminService.OrderItems with @(
|
annotate AdminService.OrderItems with @(UI : {
|
||||||
UI: {
|
HeaderInfo : {
|
||||||
HeaderInfo: {
|
TypeName : 'Order Item',
|
||||||
TypeName: 'Order Item', TypeNamePlural: ' ',
|
TypeNamePlural : ' ',
|
||||||
Title: {
|
Title : {Value : book.title},
|
||||||
Value: book.title
|
Description : {Value : book.descr}
|
||||||
},
|
},
|
||||||
Description: {Value: book.descr}
|
// There is no filterbar for items so the selctionfileds is not needed
|
||||||
},
|
SelectionFields : [book_ID],
|
||||||
// There is no filterbar for items so the selctionfileds is not needed
|
////////////////////////////////////////////////////////////////////////////
|
||||||
SelectionFields: [ book_ID ],
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////
|
// Lists of OrderItems
|
||||||
//
|
//
|
||||||
// Lists of OrderItems
|
LineItem : [
|
||||||
//
|
{
|
||||||
LineItem: [
|
Value : book_ID,
|
||||||
{Value: book_ID, Label:'Book'},
|
Label : 'Book'
|
||||||
//The following entry is only used to have the assoication followed in the read event
|
},
|
||||||
{Value: book.price, Label:'Book Price'},
|
//The following entry is only used to have the assoication followed in the read event
|
||||||
{Value: amount, Label:'Quantity'},
|
{
|
||||||
],
|
Value : book.price,
|
||||||
Identification: [ //Is the main field group
|
Label : 'Book Price'
|
||||||
//{Value: ID, Label:'ID'}, //A guid shouldn't be on the UI
|
},
|
||||||
{Value: book_ID, Label:'Book'},
|
{
|
||||||
{Value: amount, Label:'Amount'},
|
Value : amount,
|
||||||
],
|
Label : 'Quantity'
|
||||||
Facets: [
|
},
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: '@UI.Identification'},
|
],
|
||||||
],
|
Identification : [ //Is the main field group
|
||||||
},
|
//{Value: ID, Label:'ID'}, //A guid shouldn't be on the UI
|
||||||
);
|
{
|
||||||
|
Value : book_ID,
|
||||||
|
Label : 'Book'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value : amount,
|
||||||
|
Label : 'Amount'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Facets : [{
|
||||||
|
$Type : 'UI.ReferenceFacet',
|
||||||
|
Label : '{i18n>OrderItems}',
|
||||||
|
Target : '@UI.Identification'
|
||||||
|
}, ],
|
||||||
|
}, );
|
||||||
@@ -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,50 +1,35 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,44 @@
|
|||||||
"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": "latest",
|
||||||
"express": "^4",
|
"@sap/xb-msg-amqp-v100": "^0.9.31-SNAPSHOT",
|
||||||
"@sap/xb-msg-amqp-v100": "^0.9.35"
|
"express": "*",
|
||||||
},
|
"passport": "^0.4.0",
|
||||||
"devDependencies": {
|
"sqlite3": "^4.1.0"
|
||||||
"sqlite3": "^4.1.1"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npx cds run"
|
"start": "cds run --in-memory?",
|
||||||
|
"watch": "cds watch"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"API_BUSINESS_PARTNER": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "srv/external",
|
||||||
|
"--credentials": {
|
||||||
|
"destination": "cap-api098"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"--messaging": {
|
||||||
|
"kind": "enterprise-messaging",
|
||||||
|
"credentials": {
|
||||||
|
"prefix": "sap/S4HANAOD/c098/BO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"passport": {
|
||||||
|
"strategy": "mock",
|
||||||
|
"users": {
|
||||||
|
"alice": {
|
||||||
|
"roles": [
|
||||||
|
"admin"
|
||||||
|
],
|
||||||
|
"ID": "ALICE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
packages/bookshop/req.http
Normal file
19
packages/bookshop/req.http
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
PATCH http://localhost:4004/api-business-partner/A_BusinessPartnerAddress(BusinessPartner='ALICE',AddressID='62640')
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Basic QUxJQ0Utc2VjcmV0
|
||||||
|
|
||||||
|
{
|
||||||
|
"PostalCode": "123456",
|
||||||
|
"CityName": "AlteredTown"
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
GET http://localhost:4004/admin/Orders(ID=7e2f2640-6866-4dcf-8f4d-3027aa831cad,IsActiveEntity=false)?
|
||||||
|
&$expand=shippingAddress($select=cityName,houseNumber,postalCode,streetName)
|
||||||
|
Authorization: Basic QUxJQ0U6c2VjcmV0
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
DELETE http://localhost:4004/api-business-partner/A_BusinessPartnerAddress(BusinessPartner='ALICE',AddressID='62640')
|
||||||
@@ -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:'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;
|
||||||
|
|||||||
77
packages/bookshop/srv/admin-service.js
Normal file
77
packages/bookshop/srv/admin-service.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
module.exports = cds.service.impl(async () => {
|
||||||
|
// We are mashing up three services...
|
||||||
|
const bupa = await cds.connect.to('API_BUSINESS_PARTNER')
|
||||||
|
const admin = await cds.connect.to('AdminService')
|
||||||
|
const db = await cds.connect.to('db')
|
||||||
|
|
||||||
|
// Using reflected definitions from connected services/database
|
||||||
|
const { Addresses: externalAddresses } = bupa.entities // projection on external addresses
|
||||||
|
const { Books, Addresses } = db.entities('sap.capire.bookshop') // entities in local database
|
||||||
|
|
||||||
|
// Delegate ValueHelp requests to S/4 backend, fetching current user's addresses from there
|
||||||
|
admin.on('READ', 'Addresses', req => {
|
||||||
|
console.log('Delegating to S/4 bupa service...')
|
||||||
|
const UsersAddresses = SELECT.from(externalAddresses)
|
||||||
|
.where({ contact: req.user.id })
|
||||||
|
.and(req.query.SELECT.where)
|
||||||
|
return bupa.tx(req).run(UsersAddresses)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Replicate chosen addresses from S/4 when filling orders.
|
||||||
|
admin.before('PATCH', 'Orders', async req => {
|
||||||
|
const assigned = { ID: req.data.shippingAddress_ID, contact: req.user.id }
|
||||||
|
if (!assigned.ID) return //> something else
|
||||||
|
const local = db.transaction(req)
|
||||||
|
const [replica] = await local.read(Addresses).where(assigned)
|
||||||
|
if (replica) return //> already replicated
|
||||||
|
const [address] = await bupa.tx(req).run(SELECT.from(externalAddresses).where(assigned))
|
||||||
|
if (address) return local.create(Addresses).entries(address)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Subscribe to S/4 event to update local replicas when sources change in S/4.
|
||||||
|
bupa.on('BusinessPartner/Changed', async msg => {
|
||||||
|
console.log('>> received:', msg.data)
|
||||||
|
|
||||||
|
const BuPaID = msg.data.KEY[0].BUSINESSPARTNER //> S/4HANA's weird payload format
|
||||||
|
const { SELECT, UPDATE } = cds.ql(msg) //> convenient alternative to <srv>.transaction(req).run(SELECT...)
|
||||||
|
|
||||||
|
// fetch affected entries from local replicas
|
||||||
|
const replicas = await SELECT.from(Addresses).where({ contact: BuPaID })
|
||||||
|
if (replicas.length === 0) return //> not affected
|
||||||
|
|
||||||
|
// fetch changed data from S/4 -> might be less than local due to deletes
|
||||||
|
const changed = await SELECT.from(externalAddresses).where({
|
||||||
|
contact: BuPaID,
|
||||||
|
ID: replicas.map(({ ID }) => ID)
|
||||||
|
})
|
||||||
|
|
||||||
|
// update local replicas with changes from S/4
|
||||||
|
const local = db.transaction(msg) //> using that variant to benefit from bulk runs
|
||||||
|
return local.run(changed.map(a => UPDATE(Addresses, a.ID).with(a)))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Validate incoming orders and reduce books' stocks.
|
||||||
|
admin.before('CREATE', 'Orders', async req => {
|
||||||
|
const { Items } = req.data
|
||||||
|
|
||||||
|
// validate input...
|
||||||
|
if (!Items || Items.length === 0) return req.reject('Please order at least one item.')
|
||||||
|
if (!req.data.shippingAddress_ID) return req.reject('Please enter a valid shipping address.', 'shippingAddress_ID')
|
||||||
|
|
||||||
|
// reduce stock on ordered books...
|
||||||
|
const all = await db.tx(req).run(
|
||||||
|
Items.map(each =>
|
||||||
|
UPDATE(Books)
|
||||||
|
.where('ID =', each.book_ID)
|
||||||
|
.and('stock >=', each.amount)
|
||||||
|
.set('stock -=', each.amount)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
all.forEach(
|
||||||
|
(affectedRows, i) =>
|
||||||
|
affectedRows > 0 || req.error(409, `${Items[i].amount} exceeds stock for book #${Items[i].book_ID}`)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
require('./utils')
|
||||||
@@ -1,26 +1,29 @@
|
|||||||
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(function () {
|
module.exports = cds.service.impl(function () {
|
||||||
const { Books, Orders } = this.entities
|
this.after('READ', 'Books', each => each.stock > 111 && _addDiscount2(each, 11))
|
||||||
this.after('READ', Books, each => each.stock > 111 && _addDiscount2(each, 11))
|
this.before('CREATE', 'Orders', _reduceStock)
|
||||||
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
|
||||||
|
const all = await cds.transaction(req).run(() =>
|
||||||
|
OrderItems.map(order =>
|
||||||
|
UPDATE(Books)
|
||||||
|
.set('stock -=', order.amount)
|
||||||
|
.where('ID =', order.book_ID)
|
||||||
|
.and('stock >=', order.amount)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
all.forEach((affectedRows, i) => {
|
||||||
|
if (affectedRows === 0) req.error(409, `${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
39
packages/bookshop/srv/external.cds
Normal file
39
packages/bookshop/srv/external.cds
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using { API_BUSINESS_PARTNER as external } from './external/API_BUSINESS_PARTNER.csn';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tailor the imported API to our needs...
|
||||||
|
*/
|
||||||
|
extend service external with {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simplified view on external addresses
|
||||||
|
*/
|
||||||
|
// @cds.persistence.skip: false
|
||||||
|
@mashup entity Addresses as projection on external.A_BusinessPartnerAddress {
|
||||||
|
key AddressID as ID,
|
||||||
|
key BusinessPartner as contact,
|
||||||
|
Country as country,
|
||||||
|
CityName as cityName,
|
||||||
|
PostalCode as postalCode,
|
||||||
|
StreetName as streetName,
|
||||||
|
HouseNumber as houseNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an entity to replicate external address data for quick access,
|
||||||
|
* e.g. when displaying lists of orders.
|
||||||
|
*/
|
||||||
|
@cds.persistence:{table,skip:false} //> create a table with the view's inferred signature
|
||||||
|
@cds.autoexpose //> auto-expose in services as targets for ValueHelps and joins
|
||||||
|
entity sap.capire.bookshop.Addresses as projection on external.Addresses;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend Orders with references to replicated external Addresses
|
||||||
|
*/
|
||||||
|
using { sap.capire.bookshop } from '../db/schema';
|
||||||
|
extend bookshop.Orders with {
|
||||||
|
shippingAddress : Association to bookshop.Addresses;
|
||||||
|
}
|
||||||
2426
packages/bookshop/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
2426
packages/bookshop/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3261
packages/bookshop/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
3261
packages/bookshop/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
packages/bookshop/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
11
packages/bookshop/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
module.exports = srv => {
|
||||||
|
srv.on(['CREATE', 'UPDATE', 'DELETE'], req => {
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
KEY: [{ BUSINESSPARTNER: req.data.BusinessPartner }]
|
||||||
|
}
|
||||||
|
console.log('<< emitting:', payload)
|
||||||
|
srv.emit('BusinessPartner/Changed', payload)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
5
packages/bookshop/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartnerAddress.csv
vendored
Normal file
5
packages/bookshop/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartnerAddress.csv
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
BusinessPartner;AddressID;CityName;PostalCode;Country;StreetName;HouseNumber
|
||||||
|
ALICE;62640;Walldorf;69190;GER;Dietmer-Hopp-Allee;16
|
||||||
|
ALICE;62641;Berlin;69390;GER;Berlin-Street;19
|
||||||
|
BOB;62341;Karlsruhe;61390;GER;Karlsruhe-Street;19
|
||||||
|
anonymous;61321;Sometown;61290;GER;Sometown-Street;19
|
||||||
|
27
packages/bookshop/srv/utils.js
Normal file
27
packages/bookshop/srv/utils.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Hack for SAP Application Studio
|
||||||
|
process.env['http_proxy'] = ''
|
||||||
|
process.env['https_proxy'] = ''
|
||||||
|
process.env['HTTP_PROXY'] = ''
|
||||||
|
process.env['HTTPS_PROXY'] = ''
|
||||||
|
|
||||||
|
const diff = (obj1, obj2) =>
|
||||||
|
Object.keys(obj1).reduce((res, curr) => (obj1[curr] === obj2[curr] ? res : (res[curr] = obj2[curr]) && res), {})
|
||||||
|
|
||||||
|
const queriesToUpdateDifferences = (entity, ownEntries, otherEntries) =>
|
||||||
|
ownEntries
|
||||||
|
.map(ownEntry => {
|
||||||
|
const otherEntry = otherEntries.find(otherEntry =>
|
||||||
|
Object.keys(entity.keys).reduce((res, curr) => res && otherEntry[curr] === ownEntry[curr], true)
|
||||||
|
)
|
||||||
|
if (otherEntry) {
|
||||||
|
const differences = diff(ownEntry, otherEntry)
|
||||||
|
if (Object.keys(differences).length) {
|
||||||
|
return UPDATE(entity)
|
||||||
|
.set(differences)
|
||||||
|
.where(Object.keys(entity.keys).reduce((res, curr) => (res[curr] = ownEntry[curr]) && res, {}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(el => el)
|
||||||
|
|
||||||
|
module.exports = { diff, queriesToUpdateDifferences }
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ID;firstname;lastname;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath
|
||||||
|
101;Emily;Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire
|
||||||
|
107;Charlotte;Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire
|
||||||
|
150;Edgar Allen;Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland
|
||||||
|
170;Richard;Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
ID;parent_ID;name
|
||||||
|
1;;Poetry
|
||||||
|
2;;Biography
|
||||||
|
3;;Fantasy
|
||||||
|
4;;Science Fiction
|
||||||
|
5;;Romance
|
||||||
|
6;;Mystery
|
||||||
|
7;;Thriller
|
||||||
|
8;;Dystopia
|
||||||
|
9;;Tragedy
|
||||||
|
10;;Novel
|
||||||
|
@@ -0,0 +1,6 @@
|
|||||||
|
ID;title;descr;author_ID;stock;price;currency_code;category_ID
|
||||||
|
201;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;12;11.11;GBP;9
|
||||||
|
207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP;10
|
||||||
|
251;The Raven;"“The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD;1
|
||||||
|
252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD;5
|
||||||
|
271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;15;EUR;3
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
ID;locale;title;descr
|
||||||
|
201;de;Sturmhöhe;Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (1818–1848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts.
|
||||||
|
207;de;Jane Eyre;Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte
|
||||||
|
252;de;Eleonora;“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit.
|
||||||
|
18
packages/bookstore/db/schema.cds
Normal file
18
packages/bookstore/db/schema.cds
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace sap.capire.bookstore;
|
||||||
|
|
||||||
|
// We reuse Products, which are Books in our domain
|
||||||
|
using { sap.capire.products.Products as Books } from '@sap/capire-products';
|
||||||
|
extend Books with {
|
||||||
|
author : Association to Authors;
|
||||||
|
rating : Decimal(2,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We reuse aspect Person to define Authors
|
||||||
|
using { sap.capire.contacts.Person } from '@sap/capire-contacts';
|
||||||
|
entity Authors : Person {
|
||||||
|
key ID : UUID;
|
||||||
|
books : Association to many Books on books.author = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we use enhanced currencies code lists
|
||||||
|
using from '@sap/capire-currencies';
|
||||||
48
packages/bookstore/package.json
Normal file
48
packages/bookstore/package.json
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-bookstore",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A variant of the bookshop application, built on top of products-service and common reuse packages.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/capire-products": "^1.0.0",
|
||||||
|
"@sap/capire-reviews": "^1.0.0",
|
||||||
|
"@sap/capire-orders": "^1.0.0",
|
||||||
|
"@sap/capire-media": "^1.0.0",
|
||||||
|
"@sap/capire-users": "^1.0.0",
|
||||||
|
"@sap/capire-contacts": "^1.0.0",
|
||||||
|
"@sap/capire-currencies": "^1.0.0",
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
},
|
||||||
|
"bundledDependencies": [
|
||||||
|
"@sap/capire-products",
|
||||||
|
"@sap/capire-reviews",
|
||||||
|
"@sap/capire-orders",
|
||||||
|
"@sap/capire-media",
|
||||||
|
"@sap/capire-users",
|
||||||
|
"@sap/capire-contacts",
|
||||||
|
"@sap/capire-currencies"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"app", "srv", "db"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"start": "cds run --in-memory?",
|
||||||
|
"watch": "cds watch"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sql"
|
||||||
|
},
|
||||||
|
"sap.capire.media.MediaServer": {
|
||||||
|
"kind": "rest"
|
||||||
|
},
|
||||||
|
"sap.capire.reviews.ReviewsService": {
|
||||||
|
"model": "@sap/capire-reviews",
|
||||||
|
"kind": "odata"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
packages/bookstore/srv/_workarounds.cds
Normal file
12
packages/bookstore/srv/_workarounds.cds
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//----------------------
|
||||||
|
// workarounds -> should be done by @cds-compiler
|
||||||
|
|
||||||
|
annotate cds.UUID with @odata.Type: 'Edm.String';
|
||||||
|
|
||||||
|
using from '@sap/capire-products';
|
||||||
|
annotate sap.capire.products.Products with { texts @odata.contained }
|
||||||
|
annotate sap.capire.products.Categories with { texts @odata.contained }
|
||||||
|
|
||||||
|
annotate sap.capire.reviews.ReviewsService with @imported;
|
||||||
|
annotate sap.capire.reviews.Reviews with @cds.persistence.skip;
|
||||||
|
annotate sap.capire.reviews.Likes with @cds.persistence.skip;
|
||||||
35
packages/bookstore/srv/services.cds
Normal file
35
packages/bookstore/srv/services.cds
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
namespace sap.capire.bookstore;
|
||||||
|
|
||||||
|
// Service for all users to browse books
|
||||||
|
using { sap.capire.products } from '../db/schema';
|
||||||
|
|
||||||
|
service CatalogService @(path:'browse'){
|
||||||
|
|
||||||
|
@readonly entity Books as select from products.Products { *,
|
||||||
|
author.firstname ||' '|| author.lastname as author : String,
|
||||||
|
category.name as genre,
|
||||||
|
} excluding { createdBy, modifiedBy };
|
||||||
|
|
||||||
|
@readonly entity Genres as projection on products.Categories;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reuse AdminService from @sap/capire-products...
|
||||||
|
using { sap.capire.products.AdminService } from '@sap/capire-products';
|
||||||
|
using { sap.capire.bookstore as my } from '../db/schema';
|
||||||
|
|
||||||
|
extend service AdminService with @(impl:'srv/services.js') {
|
||||||
|
entity Authors as projection on my.Authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding reviews via @sap/capire-reviews service
|
||||||
|
using { sap.capire.reviews.ReviewsService as external } from '@sap/capire-reviews';
|
||||||
|
extend service CatalogService with {
|
||||||
|
@readonly entity Reviews as projection on external.Reviews;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adding images via @sap/capire-media service
|
||||||
|
using from '@sap/capire-media';
|
||||||
|
// using from '@sap/capire-orders';
|
||||||
|
// using from '@sap/capire-users';
|
||||||
38
packages/bookstore/srv/services.js
Normal file
38
packages/bookstore/srv/services.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
module.exports['sap.capire.bookstore.CatalogService'] = cds.service.impl (async (srv) => {
|
||||||
|
|
||||||
|
const ReviewsService = await cds.connect.to ('sap.capire.reviews.ReviewsService')
|
||||||
|
const { Reviews } = ReviewsService.entities
|
||||||
|
const { Books } = srv.entities
|
||||||
|
|
||||||
|
// delegate requests to reviews service
|
||||||
|
srv.on('READ', 'Reviews', async (req) => {
|
||||||
|
const { SELECT } = cds.ql(req)
|
||||||
|
const results = await SELECT.from (Reviews)
|
||||||
|
|
||||||
|
// TODO: Should actually be using .where of fluent query API
|
||||||
|
if (req.query.SELECT.where) {
|
||||||
|
return results.filter (row => row.subject === req.query.SELECT.where[2].val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
})
|
||||||
|
|
||||||
|
// react on event messages from reviews service
|
||||||
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
|
console.debug ('> received message:', msg.event, msg.data)
|
||||||
|
const {subject,rating} = msg.data
|
||||||
|
const tx = cds // cds.transaction(msg) // TODO: how to add multi-tenancy?
|
||||||
|
return tx.run (UPDATE(Books).set({rating}) .where ({ID:subject})) //.then (console.log)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME: pls remove this...
|
||||||
|
process.env.destinations = JSON.stringify([{
|
||||||
|
name: 'reviewsDest',
|
||||||
|
url: 'http://localhost:4005/reviews',
|
||||||
|
username: 'dummy',
|
||||||
|
password: 'dummy'
|
||||||
|
}])
|
||||||
7
packages/bookstore/tests/books.cds
Normal file
7
packages/bookstore/tests/books.cds
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using { sap.capire.products as my } from '../db/schema';
|
||||||
|
|
||||||
|
service BooksService {
|
||||||
|
entity Books as SELECT from my.Products;
|
||||||
|
}
|
||||||
|
|
||||||
|
annotate cds.UUID with @odata.Type: 'Edm.String';
|
||||||
190
packages/bookstore/tests/localized-data.test.js
Normal file
190
packages/bookstore/tests/localized-data.test.js
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
describe('Localized data on db level', ()=>{
|
||||||
|
|
||||||
|
let db, Books
|
||||||
|
|
||||||
|
it ('should deploy the db schema to sqlite in-memory', async()=>{
|
||||||
|
db = await cds.deploy (__dirname+'/books') .to ('sqlite::memory:')
|
||||||
|
expect (db.model) .toBeDefined()
|
||||||
|
Books = db.entities('sap.capire.products').Products
|
||||||
|
expect (Books) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should list all books with default language', async ()=>{
|
||||||
|
const books = await SELECT.from (Books, b=>b.title)
|
||||||
|
expect (books) .toMatchObject([
|
||||||
|
{ title: 'Wuthering Heights' },
|
||||||
|
{ title: 'Jane Eyre' },
|
||||||
|
{ title: 'The Raven' },
|
||||||
|
{ title: 'Eleonora' },
|
||||||
|
{ title: 'Catweazle' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it ('should read translated texts from Books_texts', async ()=>{
|
||||||
|
const texts = await SELECT ('locale','title').from (Books+'_texts')
|
||||||
|
expect (texts) .toMatchObject ([
|
||||||
|
{ locale: 'de', title: 'Sturmhöhe' },
|
||||||
|
{ locale: 'de', title: 'Jane Eyre' },
|
||||||
|
{ locale: 'de', title: 'Eleonora' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read translated texts from Books.texts', async ()=>{
|
||||||
|
const book = await SELECT.one.from (Books, b=>{
|
||||||
|
b.ID, b.title, b.texts(t=> {
|
||||||
|
t.locale, t.title
|
||||||
|
})
|
||||||
|
}) .where ({title:'Wuthering Heights'})
|
||||||
|
expect (book) .toMatchObject ({
|
||||||
|
title: 'Wuthering Heights', texts:[
|
||||||
|
{locale:'de',title:'Sturmhöhe'}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should insert books with translated texts', async ()=>{
|
||||||
|
const n = await INSERT.into (Books) .entries ({ ID:444, title:'A New Book', texts:[
|
||||||
|
{locale:'de', title:'Ein Neues Buch'},
|
||||||
|
{locale:'fr', title:'Un Nouveau Livre'},
|
||||||
|
]})
|
||||||
|
expect(n).toBe(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should delete books w/ cascaded delete to texts', async()=>{
|
||||||
|
const n = await DELETE.from(Books) .where ({ID:444})
|
||||||
|
expect(n).toBe(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe('Localized data on service level', ()=>{
|
||||||
|
|
||||||
|
let srv, Books
|
||||||
|
|
||||||
|
it ('should serve BooksService', async()=>{
|
||||||
|
srv = await cds.serve('BooksService').from(__dirname+'/books')
|
||||||
|
expect (srv.model) .toBeDefined()
|
||||||
|
Books = srv.entities.Books
|
||||||
|
expect (Books) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should list all books with default language', async ()=>{
|
||||||
|
const books = await srv.read (Books, b=>b.title)
|
||||||
|
expect (books) .toMatchObject([
|
||||||
|
{ title: 'Wuthering Heights' },
|
||||||
|
{ title: 'Jane Eyre' },
|
||||||
|
{ title: 'The Raven' },
|
||||||
|
{ title: 'Eleonora' },
|
||||||
|
{ title: 'Catweazle' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read Books with translated texts', async ()=>{
|
||||||
|
const book = await srv.run (
|
||||||
|
SELECT.from (Books, b=>{ b.ID, b.title, b.texts(t=> {
|
||||||
|
t.locale, t.title
|
||||||
|
})}) .where ({title:'Wuthering Heights'})
|
||||||
|
)
|
||||||
|
expect (book) .toMatchObject ([{
|
||||||
|
title: 'Wuthering Heights', texts:[
|
||||||
|
{locale:'de',title:'Sturmhöhe'}
|
||||||
|
]
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should do the same with convenient method', async ()=>{
|
||||||
|
const book = await srv.read (Books, b=>{ b.ID, b.title, b.texts(t=> {
|
||||||
|
t.locale, t.title
|
||||||
|
})}) .where ({title:'Wuthering Heights'})
|
||||||
|
expect (book) .toMatchObject ([{
|
||||||
|
title: 'Wuthering Heights', texts:[
|
||||||
|
{locale:'de',title:'Sturmhöhe'}
|
||||||
|
]
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read single Book with translated texts', async ()=>{
|
||||||
|
const book = await srv.run (
|
||||||
|
SELECT.one.from (Books, b=>{ b.ID, b.title, b.texts(t=> {
|
||||||
|
t.locale, t.title
|
||||||
|
})}) .where ({title:'Wuthering Heights'})
|
||||||
|
)
|
||||||
|
expect (book) .toMatchObject ({
|
||||||
|
title: 'Wuthering Heights', texts:[
|
||||||
|
{locale:'de',title:'Sturmhöhe'}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should insert books with translated texts', async ()=>{
|
||||||
|
const book = { ID:444, title:'A New Book', texts:[
|
||||||
|
{locale:'de', title:'Ein Neues Buch'},
|
||||||
|
{locale:'fr', title:'Un Nouveau Livre'},
|
||||||
|
]}
|
||||||
|
const response = await srv.create (Books) .entries (book)
|
||||||
|
expect(response).toMatchObject(book)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should delete books w/ cascaded delete to texts', async()=>{
|
||||||
|
await srv.delete('Books') .where ({ID:444})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe('Localized data on OData level', () => {
|
||||||
|
|
||||||
|
const app = require('express')()
|
||||||
|
const srv = require('supertest')(app)
|
||||||
|
|
||||||
|
it ('should serve BooksService', async ()=>{
|
||||||
|
await cds.serve('BooksService').from(__dirname+'/books') .in (app)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should list all books with default language', async () => {
|
||||||
|
const books = await srv.get('/books/Books/201/title')
|
||||||
|
expect(books.body).toMatchObject({'value': 'Wuthering Heights'})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should read books with translated texts', async () => {
|
||||||
|
const books = await srv.get('/books/Books/201/title'). set('Accept-Language', 'de')
|
||||||
|
expect(books.body).toMatchObject({value: 'Sturmhöhe'})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should expand translated texts in Book', async () => {
|
||||||
|
const books = await srv. get('/books/Books/201?$select=title&$expand=texts($select=locale,title)')
|
||||||
|
expect(books.body).toMatchObject({
|
||||||
|
title: 'Wuthering Heights',
|
||||||
|
texts: [
|
||||||
|
{ locale: 'de', title: 'Sturmhöhe', },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const book = {
|
||||||
|
title: 'New Book', descr: 'Lorem Ipsum',
|
||||||
|
texts: [
|
||||||
|
{ locale: 'de', title: 'Neues Buch', descr: 'Dolor sit amet' },
|
||||||
|
{ locale: 'fr', title: 'Nouveau Livre', descr: 'consetetur sadipscing elitr' }
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should insert books with translated texts', async () => {
|
||||||
|
const {body} = await srv.post('/books/Books').send(book)
|
||||||
|
expect(body).toMatchObject(book)
|
||||||
|
book.ID = body.ID
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read the newly created book', async()=>{
|
||||||
|
const {body} = await srv.get('/books/Books/'+book.ID+'?$expand=texts').send(book)
|
||||||
|
expect(body).toMatchObject(book)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should delete books w/ cascaded delete to texts', async()=>{
|
||||||
|
await srv.delete('/books/Books/'+book.ID)
|
||||||
|
.expect(204)
|
||||||
|
})
|
||||||
|
})
|
||||||
37
packages/common-contacts/db/code-lists.cds
Normal file
37
packages/common-contacts/db/code-lists.cds
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using { sap.capire.contacts.PostalAddress } from './schema';
|
||||||
|
using { sap } from '@sap/cds/common';
|
||||||
|
namespace sap.capire.contacts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Code Lists below are designed as optional extensions to
|
||||||
|
* the base schema. Switch them on by adding an Association to
|
||||||
|
* one of the code list entities in your models or by:
|
||||||
|
* annotate sap.common.Countries with @cds.persistence.skip:false;
|
||||||
|
*/
|
||||||
|
|
||||||
|
entity Countries as select from sap.common.Countries;
|
||||||
|
extend sap.common.Countries {
|
||||||
|
regions : Composition of many Regions on regions._parent = $self.code;
|
||||||
|
}
|
||||||
|
entity Regions : sap.common.CodeList {
|
||||||
|
key code : String(5); // ISO 3166-2 alpha5 codes, e.g. DE-BW
|
||||||
|
children : Composition of many Regions on children._parent = $self.code;
|
||||||
|
cities : Composition of many Cities on cities.region = $self;
|
||||||
|
_parent : String(11);
|
||||||
|
}
|
||||||
|
entity Cities : sap.common.CodeList {
|
||||||
|
key code : String(11);
|
||||||
|
region : Association to Regions;
|
||||||
|
districts : Composition of many Districts on districts.city = $self;
|
||||||
|
}
|
||||||
|
entity Districts : sap.common.CodeList {
|
||||||
|
key code : String(11);
|
||||||
|
city : Association to Cities;
|
||||||
|
}
|
||||||
|
|
||||||
|
annotate PostalAddress with {
|
||||||
|
district @ref: sap.capire.contacts.Districts;
|
||||||
|
city @ref: sap.capire.contacts.Cities;
|
||||||
|
region @ref: sap.capire.contacts.Regions;
|
||||||
|
country @ref: sap.capire.contacts.Countries;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
code;name;descr
|
||||||
|
AU;Australia;Commonwealth of Australia
|
||||||
|
CA;Canada;Canada
|
||||||
|
CN;China;People's Republic of China (PRC)
|
||||||
|
FR;France;French Republic
|
||||||
|
DE;Germany;Federal Republic of Germany
|
||||||
|
IN;India;Republic of India
|
||||||
|
IL;Israel;State of Israel
|
||||||
|
MM;Myanmar;Republic of the Union of Myanmar
|
||||||
|
GB;United Kingdom;United Kingdom of Great Britain and Northern Ireland
|
||||||
|
US;United States;United States of America (USA)
|
||||||
|
EU;European Union;European Union
|
||||||
|
@@ -0,0 +1,12 @@
|
|||||||
|
code;locale;name;descr
|
||||||
|
AU;de;Australien;Commonwealth Australien
|
||||||
|
CA;de;Kanada;Canada
|
||||||
|
CN;de;China;Volksrepublik China
|
||||||
|
FR;de;Frankreich;Republik Frankreich
|
||||||
|
DE;de;Deutschland;Bundesrepublik Deutschland
|
||||||
|
IN;de;Indien;Republik Indien
|
||||||
|
IL;de;Israel;Staat Israel
|
||||||
|
MM;de;Myanmar;Republik der Union Myanmar
|
||||||
|
GB;de;Vereinigtes Königreich;Vereinigtes Königreich Großbritannien und Nordirland
|
||||||
|
US;de;Vereinigte Staaten;Vereinigte Staaten von Amerika
|
||||||
|
EU;de;Europäische Union;Europäische Union
|
||||||
|
58
packages/common-contacts/db/schema.cds
Normal file
58
packages/common-contacts/db/schema.cds
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
namespace sap.capire.contacts;
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// Aspects
|
||||||
|
|
||||||
|
|
||||||
|
aspect Organization {
|
||||||
|
orgname : String(111);
|
||||||
|
}
|
||||||
|
|
||||||
|
aspect Person {
|
||||||
|
firstname : String(111);
|
||||||
|
lastname : String(111);
|
||||||
|
prefix : String(11);
|
||||||
|
suffix : String(11);
|
||||||
|
middle : String(11);
|
||||||
|
dateOfBirth : Date; placeOfBirth : String;
|
||||||
|
dateOfDeath : Date; placeOfDeath : String;
|
||||||
|
}
|
||||||
|
|
||||||
|
aspect PostalAddress {
|
||||||
|
street : String(222) @multiline;
|
||||||
|
postCode : String(11);
|
||||||
|
district : String(111);
|
||||||
|
city : String(111);
|
||||||
|
region : String(111);
|
||||||
|
country : String(111);
|
||||||
|
}
|
||||||
|
|
||||||
|
aspect ContactOptions {
|
||||||
|
email : String @JSON:[{ kind:String, address: EmailAddress }];
|
||||||
|
phone : String @JSON:[{ kind:String, number: PhoneNumber }];
|
||||||
|
// phone : array of { kind:String; number: PhoneNumber };
|
||||||
|
// addresses : Composition of many PostalAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailAddress : String;
|
||||||
|
type PhoneNumber : String;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// Entities
|
||||||
|
|
||||||
|
@cds.persistence.skip:'if-unused'
|
||||||
|
entity Contacts : Person, Organization, ContactOptions {
|
||||||
|
key ID : UUID;
|
||||||
|
isOrg : Boolean;
|
||||||
|
addresses : Composition of many PostalAddresses on addresses.contact = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@cds.persistence.skip:'if-unused'
|
||||||
|
entity PostalAddresses : PostalAddress {
|
||||||
|
contact : Association to Contacts;
|
||||||
|
kind : String;
|
||||||
|
key ID : UUID;
|
||||||
|
}
|
||||||
2
packages/common-contacts/index.cds
Normal file
2
packages/common-contacts/index.cds
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
using from './db/code-lists';
|
||||||
|
using from './db/schema';
|
||||||
10
packages/common-contacts/package.json
Normal file
10
packages/common-contacts/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-contacts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse package providing common domain models and services for contacts-related data.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
67
packages/common-contacts/readme.md
Normal file
67
packages/common-contacts/readme.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Common Contacts Sample
|
||||||
|
|
||||||
|
This sample provides a reuse package with common domain models and services for contacts-related data.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
#### Import to your project
|
||||||
|
|
||||||
|
npm install @sap/capire-contacts
|
||||||
|
|
||||||
|
> e.g. see: [bookstore](../bookstore/package.json)
|
||||||
|
|
||||||
|
#### Reusing aspects
|
||||||
|
|
||||||
|
Define own entities derived from the pre-defined aspects as in [_bookstore_](../bookstore/db/schema.cds):
|
||||||
|
|
||||||
|
```swift
|
||||||
|
using { sap.capire.contacts.Person } from '@sap/capire-contacts';
|
||||||
|
entity Authors : contacts.Person { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** All entities in this package are annotated with _`@cds.persistence.skip`:'if-unused'_, so they will be ignored if not referred to from other entities in your models.
|
||||||
|
|
||||||
|
|
||||||
|
#### Reusing entities
|
||||||
|
|
||||||
|
Reuse the entities as in this example from [_users-service_](../users-service/srv/services.cds):
|
||||||
|
```swift
|
||||||
|
using { sap.capire.contacts.Contacts } from '@sap/capire-contacts';
|
||||||
|
service UsersService @(requires:'authenticated-user') {
|
||||||
|
entity MyProfile as select from Contacts where ID=$user;
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Reusing code lists
|
||||||
|
|
||||||
|
Reuse the code lists as in [_./tests/index.cds_](./tests/index.cds):
|
||||||
|
|
||||||
|
```swift
|
||||||
|
service Sue { ...
|
||||||
|
// expose Countries to activate provided code lists
|
||||||
|
@readonly entity Countries as projection on sap.capire.contacts.Countries;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Reuse code list service
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { intercept } = require ('@sap/capire-contacts/srv/code-lists')
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Concepts
|
||||||
|
|
||||||
|
* [Reuse of packages](https://cap.cloud.sap/docs/get-started/projects#reuse)
|
||||||
|
* Code Lists, `@sap/cds/common` and `@cds.persistence.skip`: 'if-unused'
|
||||||
|
* Using `aspects` vs `entities`
|
||||||
70
packages/common-contacts/srv/code-lists.js
Normal file
70
packages/common-contacts/srv/code-lists.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
const READ='READ', WRITE = ['CREATE','UPDATE']
|
||||||
|
|
||||||
|
const intercept = exports.intercept = cds.service.impl (async (srv) => {
|
||||||
|
|
||||||
|
for (let each in srv.entities) {
|
||||||
|
|
||||||
|
// intercept JSON-encoded elements
|
||||||
|
const jsons = await jsonsIn (srv.entities[each].elements)
|
||||||
|
if (jsons) {
|
||||||
|
srv.before (WRITE, each, ({data:row})=>{
|
||||||
|
for (let e of jsons) if (row[e]) row[e] = JSON.stringify (row[e])
|
||||||
|
})
|
||||||
|
srv.after (READ, each, (row)=>{
|
||||||
|
for (let e of jsons) if (row[e]) row[e] = JSON.parse (row[e])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// intercept references
|
||||||
|
const refs = await refsIn (srv.entities[each].elements, srv.model)
|
||||||
|
if (refs) srv.after (READ, each, (rows, req)=>{
|
||||||
|
for (let row of rows) {
|
||||||
|
for (let {element,codelist} of refs) {
|
||||||
|
const entry = codelist [row[element]]
|
||||||
|
if (entry) {
|
||||||
|
const localized = entry.texts [req.user.locale || intercept.locale]
|
||||||
|
row[element] = localized ? localized.name : entry.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
function jsonsIn (elements) {
|
||||||
|
const jsons=[]; for (let e in elements) {
|
||||||
|
if (elements[e]['@JSON']) jsons.push(e)
|
||||||
|
}
|
||||||
|
return jsons.length && jsons
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refsIn (elements, model) {
|
||||||
|
const refs=[]; for (let e in elements) {
|
||||||
|
const $ref = elements[e]['@ref']
|
||||||
|
if ($ref) {
|
||||||
|
const d = model.definitions [$ref['=']]
|
||||||
|
refs.push({
|
||||||
|
element:e,
|
||||||
|
codelist: CodeLists[d.name] || (CodeLists[d.name] = await load(d))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return refs.length && refs
|
||||||
|
}
|
||||||
|
|
||||||
|
const load = exports.load = async (codelist) => {
|
||||||
|
const all = {}
|
||||||
|
const [entries,texts] = await Promise.all ([
|
||||||
|
SELECT.from (codelist),
|
||||||
|
SELECT.from (codelist.elements.texts.target)
|
||||||
|
])
|
||||||
|
for (let {code,name,descr} of entries) all[code] = {name,descr}
|
||||||
|
for (let {code,locale,name,descr} of texts) (all[code].texts || (all[code].texts={})) [locale] = {name,descr}
|
||||||
|
return all
|
||||||
|
}
|
||||||
|
|
||||||
|
const CodeLists = {}
|
||||||
68
packages/common-contacts/tests/code-lists.test.js
Normal file
68
packages/common-contacts/tests/code-lists.test.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
const {load,intercept} = require ('../srv/code-lists')
|
||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
// patch-enhance cds.ql
|
||||||
|
const select = SELECT.from('.').__proto__.__proto__, query = select.__proto__
|
||||||
|
query.then = function (r,e) { return db.run(this) .then (r,e || ((e)=>{throw e})) }
|
||||||
|
|
||||||
|
let db, Countries, Australia = {
|
||||||
|
name: 'Australia', descr: 'Commonwealth of Australia', texts: {
|
||||||
|
de: { name: 'Australien', descr: 'Commonwealth Australien' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe ('code list tests', ()=>{
|
||||||
|
|
||||||
|
it ('should deploy the db schema to sqlite in-memory', async()=>{
|
||||||
|
db = await cds.deploy (__dirname) .to ('sqlite::memory:', {silent:true,primary:true})
|
||||||
|
Countries = db.model.entities ['sap.common.Countries']
|
||||||
|
expect (Countries) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read Countries', async()=>{
|
||||||
|
const countries = await SELECT ('code','name') .from (Countries)
|
||||||
|
expect (countries) .toContainEqual ({ code: 'AU', name: 'Australia' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read Countries_texts', async()=>{
|
||||||
|
const countries = await SELECT ('locale','code','name') .from ('sap.common.Countries_texts')
|
||||||
|
expect (countries) .toContainEqual ({ locale: 'de', code: 'AU', name: 'Australien' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read code lists with translated texts', async()=>{
|
||||||
|
const {AU} = await load (Countries)
|
||||||
|
expect (AU) .toEqual (Australia)
|
||||||
|
})
|
||||||
|
|
||||||
|
cds.env.singletenant = true
|
||||||
|
|
||||||
|
it ('should serve services with localized data', async()=>{
|
||||||
|
const { Sue:sue } = await cds.serve (__dirname)
|
||||||
|
const { Foos } = sue.entities
|
||||||
|
await sue.create (Foos) .entries ({country:'Avalon'})
|
||||||
|
await sue.create (Foos) .entries ({country:'AU'})
|
||||||
|
expect (await sue.read('Foos')) .toEqual ([ { ID: 1, country: 'Avalon' }, { ID: 2, country: 'AU' } ])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should resolve countries', async()=>{
|
||||||
|
const sue = await cds.connect.to ('Sue')
|
||||||
|
await intercept (sue)
|
||||||
|
expect (await sue.read('Foos')) .toEqual ([ { ID: 1, country: 'Avalon' }, { ID: 2, country: 'Australia' } ])
|
||||||
|
intercept.locale = 'de'
|
||||||
|
expect (await sue.read('Foos')) .toEqual ([ { ID: 1, country: 'Avalon' }, { ID: 2, country: 'Australien' } ])
|
||||||
|
console.log (await sue.read('Foos'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read countries with expand to translated texts', async()=>{
|
||||||
|
const countries = await cds.read (Countries, c=>{
|
||||||
|
c.name, c.texts (t => {
|
||||||
|
t.locale, t.name
|
||||||
|
})
|
||||||
|
})
|
||||||
|
console.log (countries)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should disconnect from db', ()=> db.disconnect())
|
||||||
|
//> FIXME: that should not be required!
|
||||||
|
|
||||||
|
})
|
||||||
11
packages/common-contacts/tests/index.cds
Normal file
11
packages/common-contacts/tests/index.cds
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using { sap } from '..';
|
||||||
|
|
||||||
|
entity Foo {
|
||||||
|
key ID : Integer;
|
||||||
|
country : String @ref: sap.capire.contacts.Countries;
|
||||||
|
}
|
||||||
|
service Sue {
|
||||||
|
entity Foos as projection on Foo;
|
||||||
|
// expose Countries to activate provided code lists
|
||||||
|
@readonly entity Countries as projection on sap.capire.contacts.Countries;
|
||||||
|
}
|
||||||
12
packages/common-currencies/data/sap.common-Currencies.csv
Normal file
12
packages/common-currencies/data/sap.common-Currencies.csv
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
code;symbol;name;descr;numcode;minor;exponent
|
||||||
|
EUR;€;Euro;European Euro;978;Cent;2
|
||||||
|
USD;$;US Dollar;United States Dollar;840;Cent;2
|
||||||
|
CAD;$;Canadian Dollar;Canadian Dollar;124;Cent;2
|
||||||
|
AUD;$;Australian Dollar;Canadian Dollar;036;Cent;2
|
||||||
|
GBP;£;British Pound;Great Britain Pound;826;Penny;2
|
||||||
|
ILS;₪;Shekel;Israeli New Shekel;376;Agorat;2
|
||||||
|
INR;₹;Rupee;Indian Rupee;356;Paise;2
|
||||||
|
QAR;﷼;Riyal;Katar Riyal;356;Dirham;2
|
||||||
|
SAR;﷼;Riyal;Saudi Riyal;682;Halala;2
|
||||||
|
JPY;¥;Yen;Japanese Yen;392;Sen;2
|
||||||
|
CNY;¥;Yuan;Chinese Yuan Renminbi;156;Jiao;1
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
code;locale;name;descr
|
||||||
|
EUR;de;Euro;European Euro
|
||||||
|
USD;de;US-Dollar;United States Dollar
|
||||||
|
CAD;de;Kanadischer Dollar;Kanadischer Dollar
|
||||||
|
AUD;de;Australischer Dollar;Australischer Dollar
|
||||||
|
GBP;de;Pfund;Britische Pfund
|
||||||
|
ILS;de;Schekel;Israelische Schekel
|
||||||
|
EUR;fr;euro;de la Zone euro
|
||||||
|
USD;fr;dollar;dollar des États-Unis
|
||||||
|
CAD;fr;dollar canadien;dollar canadien
|
||||||
|
AUD;fr;dollar australien;dollar australien
|
||||||
|
GBP;fr;livre sterling;pound sterling
|
||||||
|
ILS;fr;Shekel;shekel israelien
|
||||||
|
17
packages/common-currencies/index.cds
Normal file
17
packages/common-currencies/index.cds
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace sap.capire.currencies;
|
||||||
|
using { sap.common.Currencies } from '@sap/cds/common';
|
||||||
|
|
||||||
|
extend Currencies with {
|
||||||
|
// Currencies.code = ISO 4217 alphabetic three-letter code
|
||||||
|
// with the first two letters being equal to ISO 3166 alphabetic country codes
|
||||||
|
numcode : Integer;
|
||||||
|
exponent : Integer; //> e.g. 2 --> 1 Dollar = 10^2 Cent
|
||||||
|
minor : String; //> e.g. 'Cent'
|
||||||
|
// country : String; //> country or region
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// see also
|
||||||
|
// [1] https://www.iso.org/iso-4217-currency-codes.html
|
||||||
|
// [2] https://www.currency-iso.org/en/home/tables/table-a1.html
|
||||||
|
// [3] https://www.ibm.com/support/knowledgecenter/en/SSZLC2_7.0.0/com.ibm.commerce.payments.developer.doc/refs/rpylerl2mst97.htm
|
||||||
10
packages/common-currencies/package.json
Normal file
10
packages/common-currencies/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-currencies",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse package providing common domain models and services for currencies-related data.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/media-server/index.cds
Normal file
15
packages/media-server/index.cds
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace sap.capire.media;
|
||||||
|
|
||||||
|
service MediaServer {
|
||||||
|
entity Images {
|
||||||
|
key url : URL;
|
||||||
|
type : String enum { jpeg; png; gif; };
|
||||||
|
content : Image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImageURL : URL;
|
||||||
|
// type ImageURL : Association to MediaServer.Images;
|
||||||
|
//> would need Assotiations targeting off service to turn into references w/ foreign keys
|
||||||
|
type Image : LargeBinary @stream;
|
||||||
|
type URL : String(222);
|
||||||
11
packages/media-server/package.json
Normal file
11
packages/media-server/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-media",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A generic platform service to manage and serve media content on behalf of other services and apps.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ID;amount;parent_ID;article
|
||||||
|
58040e66-1dcd-4ffb-ab10-fdce32028b79;1;7e2f2640-6866-4dcf-8f4d-3027aa831cad;201
|
||||||
|
64e718c9-ff99-47f1-8ca3-950c850777d4;1;7e2f2640-6866-4dcf-8f4d-3027aa831cad;271
|
||||||
|
e9641166-e050-4261-bfee-d1e797e6cb7f;2;64e718c9-ff99-47f1-8ca3-950c850777d4;252
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
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;christian.georgi@sap.com;;2;EUR
|
||||||
|
15
packages/orders-service/db/schema.cds
Normal file
15
packages/orders-service/db/schema.cds
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace sap.capire.orders;
|
||||||
|
using { Currency, cuid, managed } from '@sap/cds/common';
|
||||||
|
|
||||||
|
|
||||||
|
entity Orders : cuid, managed {
|
||||||
|
OrderNo : String @title:'Order Number'; //> readable key
|
||||||
|
Items : Composition of many OrderItems on Items.parent = $self;
|
||||||
|
currency : Currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity OrderItems : cuid {
|
||||||
|
parent : Association to Orders not null;
|
||||||
|
article : String;
|
||||||
|
amount : Integer;
|
||||||
|
}
|
||||||
2
packages/orders-service/index.cds
Normal file
2
packages/orders-service/index.cds
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
namespace sap.capire.orders;
|
||||||
|
using from './srv/orders-service';
|
||||||
11
packages/orders-service/package.json
Normal file
11
packages/orders-service/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-orders",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse package providing domain models and services to submit and manage purchase orders.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
packages/orders-service/srv/orders-service.cds
Normal file
6
packages/orders-service/srv/orders-service.cds
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace sap.capire.orders;
|
||||||
|
using { sap.capire.orders as my } from '../db/schema';
|
||||||
|
|
||||||
|
service OrdersService {
|
||||||
|
entity Orders as projection on my.Orders;
|
||||||
|
}
|
||||||
18
packages/products-service/db/schema.cds
Normal file
18
packages/products-service/db/schema.cds
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace sap.capire.products;
|
||||||
|
|
||||||
|
using { Currency, cuid, managed, sap.common.CodeList } from '@sap/cds/common';
|
||||||
|
|
||||||
|
entity Products : cuid, managed {
|
||||||
|
title : localized String(111);
|
||||||
|
descr : localized String(1111);
|
||||||
|
stock : Integer;
|
||||||
|
price : Decimal(9,2);
|
||||||
|
currency : Currency;
|
||||||
|
category : Association to Categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Categories : CodeList {
|
||||||
|
key ID : Integer;
|
||||||
|
parent : Association to Categories;
|
||||||
|
children : Composition of many Categories on children.parent = $self;
|
||||||
|
}
|
||||||
2
packages/products-service/index.cds
Normal file
2
packages/products-service/index.cds
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
using from './db/schema';
|
||||||
|
using from './srv/admin-service';
|
||||||
16
packages/products-service/package.json
Normal file
16
packages/products-service/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-products",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse package providing domain models and services to manage product catalogs.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"db",
|
||||||
|
"srv",
|
||||||
|
"index.cds"
|
||||||
|
]
|
||||||
|
}
|
||||||
7
packages/products-service/srv/admin-service.cds
Normal file
7
packages/products-service/srv/admin-service.cds
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using { sap.capire.products as db } from '../db/schema';
|
||||||
|
namespace sap.capire.products;
|
||||||
|
|
||||||
|
service AdminService @(_requires:'admin') {
|
||||||
|
entity Products as projection on db.Products;
|
||||||
|
entity Categories as projection on db.Categories;
|
||||||
|
}
|
||||||
68
packages/products-service/tests/categories.test.js
Normal file
68
packages/products-service/tests/categories.test.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
describe('reading/writing hierarchies', ()=>{
|
||||||
|
|
||||||
|
it ('should prepare to sqlite in-memory', async()=>{
|
||||||
|
await cds.deploy (__dirname+'/../db') .to ('sqlite::memory:')
|
||||||
|
expect (cds.model) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should insert hierarchy of categories', ()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
return INSERT.into (Categories) .entries (
|
||||||
|
{ ID:100, name:'Some Sample Categories...', children:[
|
||||||
|
{ ID:101, name:'Cat', children:[
|
||||||
|
{ ID:102, name:'Kitty', children:[
|
||||||
|
{ ID:103, name:'Kitty Cat', children:[
|
||||||
|
{ ID:104, name:'Aristocat' } ]},
|
||||||
|
{ ID:105, name:'Kitty Bat' } ]},
|
||||||
|
{ ID:106, name:'Catwoman', children:[
|
||||||
|
{ ID:107, name:'Catalina' } ]} ]},
|
||||||
|
{ ID:108, name:'Catweazle' }
|
||||||
|
]}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read categories with children', async()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
expect (await
|
||||||
|
|
||||||
|
SELECT.one.from (Categories, c=>{
|
||||||
|
c.ID, c.name.as('parent'), c.children (c=>{
|
||||||
|
c.name.as('child')
|
||||||
|
})
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
|
||||||
|
) .toMatchObject (
|
||||||
|
|
||||||
|
{ ID:101, parent:'Cat', children:[
|
||||||
|
{ child:'Kitty' },
|
||||||
|
{ child:'Catwoman' },
|
||||||
|
]}
|
||||||
|
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read hierarchy of categories', async()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
expect (await
|
||||||
|
|
||||||
|
SELECT.one.from (Categories, c=>{
|
||||||
|
c.ID, c.name, c.children (c=>{ c.name },{levels:3})
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
|
||||||
|
) .toMatchObject (
|
||||||
|
|
||||||
|
{ ID:101, name:'Cat', children:[
|
||||||
|
{ name:'Kitty', children:[
|
||||||
|
{ name:'Kitty Cat', children:[
|
||||||
|
{ name:'Aristocat' }, ]},
|
||||||
|
{ name:'Kitty Bat' }, ]},
|
||||||
|
{ name:'Catwoman', children:[
|
||||||
|
{ name:'Catalina' } ]},
|
||||||
|
]}
|
||||||
|
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
ID;parent_ID;name
|
||||||
|
0;;Some Sample Categories...
|
||||||
|
1;;Cat
|
||||||
|
2;1;Kitty
|
||||||
|
3;2;Kitty Cat
|
||||||
|
4;3;Aristocat
|
||||||
|
5;2;Kitty Bat
|
||||||
|
6;1;Catwoman
|
||||||
|
7;6;Catalina
|
||||||
|
8;;Catweazle
|
||||||
|
157
packages/products-service/tests/postman.json
Normal file
157
packages/products-service/tests/postman.json
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"_postman_id": "0f8d4e79-a1c2-47fe-aeab-0319fb4ce180",
|
||||||
|
"name": "@sap/capire-products",
|
||||||
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
|
},
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{ \"ID\":0, \"name\":\"Some Sample Categories...\", \"children\":[\n { \"ID\":1, \"name\":\"Cat\", \"children\":[\n { \"ID\":2, \"name\":\"Kitty\", \"children\":[\n { \"ID\":3, \"name\":\"Kitty Cat\", \"children\":[\n { \"ID\":4, \"name\":\"Aristocat\" }\n ]},\n { \"ID\":5, \"name\":\"Kitty Bat\" }\n ]},\n { \"ID\":6, \"name\":\"Catwoman\", \"children\":[\n { \"ID\":7, \"name\":\"Catalina\" }\n ]}\n ] },\n { \"ID\":8, \"name\":\"Catweazle\" }\n]}\n"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/Categories",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"Categories"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/Categories/0?$expand=children($expand=children($expand=children($expand=children)))",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"Categories",
|
||||||
|
"0"
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
{
|
||||||
|
"key": "$expand",
|
||||||
|
"value": "children($expand=children($expand=children($expand=children)))"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/Categories/0?$expand=children($expand=children($expand=children($expand=children)))",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"Categories",
|
||||||
|
"0"
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
{
|
||||||
|
"key": "$expand",
|
||||||
|
"value": "children($expand=children($expand=children($expand=children)))"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "X-Powered-By",
|
||||||
|
"value": "Express"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "OData-Version",
|
||||||
|
"value": "4.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json;odata.metadata=minimal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Date",
|
||||||
|
"value": "Tue, 21 May 2019 19:20:24 GMT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Connection",
|
||||||
|
"value": "keep-alive"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Content-Length",
|
||||||
|
"value": "767"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"@odata.context\": \"$metadata#cats(children(children(children(children()))))/$entity\",\n \"@odata.metadataEtag\": \"W/\\\"+AAp4JKNOcr+OusjrdQo55RCfM+UHKpTh8EbhsxyPhM=\\\"\",\n \"name\": \"Some Sample Categories...\",\n \"descr\": null,\n \"ID\": 0,\n \"parent_ID\": null,\n \"children\": [\n {\n \"name\": \"Cat\",\n \"descr\": null,\n \"ID\": 1,\n \"parent_ID\": 0,\n \"children\": [\n {\n \"name\": \"Kitty\",\n \"descr\": null,\n \"ID\": 2,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Kitty Cat\",\n \"descr\": null,\n \"ID\": 3,\n \"parent_ID\": 2,\n \"children\": [\n {\n \"name\": \"Aristocat\",\n \"descr\": null,\n \"ID\": 4,\n \"parent_ID\": 3\n }\n ]\n },\n {\n \"name\": \"Kitty Bat\",\n \"descr\": null,\n \"ID\": 5,\n \"parent_ID\": 2,\n \"children\": []\n }\n ]\n },\n {\n \"name\": \"Catwoman\",\n \"descr\": null,\n \"ID\": 6,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Catalina\",\n \"descr\": null,\n \"ID\": 7,\n \"parent_ID\": 6,\n \"children\": []\n }\n ]\n }\n ]\n },\n {\n \"name\": \"Catweazle\",\n \"descr\": null,\n \"ID\": 8,\n \"parent_ID\": 0,\n \"children\": []\n }\n ]\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/Categories/0",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"Categories",
|
||||||
|
"0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
31
packages/reviews-service/db/schema.cds
Normal file
31
packages/reviews-service/db/schema.cds
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
namespace sap.capire.reviews;
|
||||||
|
using { User } from '@sap/cds/common';
|
||||||
|
|
||||||
|
// Reviewed subjects can be any entity that is uniquely identified
|
||||||
|
// by a single key element such as a UUID
|
||||||
|
type ReviewedSubject : String(111);
|
||||||
|
|
||||||
|
entity Reviews {
|
||||||
|
key ID : UUID;
|
||||||
|
subject : ReviewedSubject;
|
||||||
|
reviewer : User;
|
||||||
|
rating : Rating;
|
||||||
|
title : String(111);
|
||||||
|
text : String(1111);
|
||||||
|
date : DateTime;
|
||||||
|
likes : Composition of many Likes on likes.review = $self;
|
||||||
|
liked : Integer default 0; // counter for likes as helpful review (count of all _likes belonging to this review)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rating : Decimal(3,2) enum {
|
||||||
|
Best = 5;
|
||||||
|
Good = 4;
|
||||||
|
Avg = 3;
|
||||||
|
Poor = 2;
|
||||||
|
Worst = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Likes {
|
||||||
|
key review : Association to Reviews;
|
||||||
|
key user : User;
|
||||||
|
}
|
||||||
1
packages/reviews-service/index.cds
Normal file
1
packages/reviews-service/index.cds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
using from './srv/reviews-service';
|
||||||
30
packages/reviews-service/package.json
Normal file
30
packages/reviews-service/package.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-reviews",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse service providing generic means to add reviews and ratings to target objects, e.g. products.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "cds run --in-memory?",
|
||||||
|
"watch": "cds watch"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"db",
|
||||||
|
"srv",
|
||||||
|
"index.cds"
|
||||||
|
],
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"db": {
|
||||||
|
"kind": "sql"
|
||||||
|
},
|
||||||
|
"messaging": {
|
||||||
|
"kind": "file-based-messaging"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
packages/reviews-service/srv/reviews-service.cds
Normal file
41
packages/reviews-service/srv/reviews-service.cds
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using { sap.capire.reviews as my } from '../db/schema';
|
||||||
|
namespace sap.capire.reviews;
|
||||||
|
|
||||||
|
service ReviewsService {
|
||||||
|
// Sync API
|
||||||
|
entity Reviews as projection on my.Reviews excluding { likes }
|
||||||
|
action like (review:Reviews.ID); // TODO: can be a bound action in OData
|
||||||
|
action unlike (review:Reviews.ID); // TODO: can be a bound action in OData
|
||||||
|
|
||||||
|
// Async API
|
||||||
|
event reviewed : { subject: Reviews.subject; rating: Decimal(2,1) };
|
||||||
|
|
||||||
|
// Input validation
|
||||||
|
annotate Reviews with {
|
||||||
|
subject @mandatory;
|
||||||
|
title @mandatory;
|
||||||
|
rating @mandatory @assert.enum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-fill reviewers and review dates
|
||||||
|
annotate Reviews with {
|
||||||
|
reviewer @cds.on.insert:$user;
|
||||||
|
date @cds.on.insert:$now;
|
||||||
|
date @cds.on.update:$now;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Access control restrictions
|
||||||
|
annotate ReviewsService.Reviews with @restrict_:[
|
||||||
|
{ grant:'READ', to:'any' }, // everybody can read reviews
|
||||||
|
{ grant:'CREATE', to:'authenticated-user' }, // users must login to add reviews
|
||||||
|
{ grant:'UPDATE', to:'authenticated-user', where:'reviewer=$user' },
|
||||||
|
{ grant:'DELETE', to:'admin' },
|
||||||
|
];
|
||||||
|
|
||||||
|
annotate ReviewsService with @restrict_:[
|
||||||
|
{ grant:'like', to:'identified-user' },
|
||||||
|
{ grant:'unlike', to:'identified-user', where:'user=$user' },
|
||||||
|
];
|
||||||
41
packages/reviews-service/srv/reviews-service.js
Normal file
41
packages/reviews-service/srv/reviews-service.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
module.exports = cds.service.impl (function(){
|
||||||
|
|
||||||
|
// Get the CSN definition for Reviews from the db schema for sub-sequent queries
|
||||||
|
// ( Note: we explicitly specify the namespace to support embedded reuse )
|
||||||
|
const { Reviews, Likes } = this.entities ('sap.capire.reviews')
|
||||||
|
|
||||||
|
// Emit an event to inform subscribers about new avg ratings for reviewed subjects
|
||||||
|
// ( Note: req.on.succeeded ensures we only do that if there's no error )
|
||||||
|
this.after (['CREATE','UPDATE','DELETE'], 'Reviews', async(_,req) => {
|
||||||
|
const {subject} = req.data
|
||||||
|
const {rating} = await cds.transaction(req) .run (
|
||||||
|
SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject})
|
||||||
|
)
|
||||||
|
req.on ('succeeded', ()=>{
|
||||||
|
console.log ('< emitting:', 'reviewed', { subject, rating })
|
||||||
|
this.emit ('reviewed', { subject, rating })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Increment counter for reviews considered helpful
|
||||||
|
this.on ('like', (req) => {
|
||||||
|
if (!req.user) return req.reject(400, 'You must be identified to like a review')
|
||||||
|
const {review} = req.data, {user} = req
|
||||||
|
const tx = cds.transaction(req)
|
||||||
|
return tx.run ([
|
||||||
|
INSERT.into (Likes) .entries ({review_ID: review, user: user.id}),
|
||||||
|
UPDATE (Reviews) .set({liked: {'+=': 1}}) .where({ID:review})
|
||||||
|
]).catch(() => req.reject(400, 'You already liked that review'))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Delete a former like by the same user
|
||||||
|
this.on ('unlike', async (req) => {
|
||||||
|
if (!req.user) return req.reject(400, 'You must be identified to remove a former like of yours')
|
||||||
|
const {review} = req.data, {user} = req
|
||||||
|
const tx = cds.transaction(req)
|
||||||
|
const affectedRows = await tx.run (DELETE.from (Likes) .where ({review_ID: review,user: user.id}))
|
||||||
|
if (affectedRows === 1) return tx.run (UPDATE (Reviews) .set ({liked: {'-=': 1}}) .where ({ID:review}))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
69
packages/reviews-service/tests/messaging.test.js
Normal file
69
packages/reviews-service/tests/messaging.test.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
const _model = __dirname+'/..'
|
||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
describe('messaging tests', ()=>{
|
||||||
|
|
||||||
|
it ('should bootstrap sqlite in-memory db', async()=>{
|
||||||
|
const db = await cds.deploy (_model) .to ('sqlite::memory:')
|
||||||
|
expect (db.model) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
let srv
|
||||||
|
it ('should serve reviews services', async()=>{
|
||||||
|
srv = await cds.serve('ReviewsService') .from (_model)
|
||||||
|
expect (srv.name) .toMatch ('ReviewsService')
|
||||||
|
})
|
||||||
|
|
||||||
|
let N=0, received=[], M=0
|
||||||
|
it ('should add messaging event handlers', ()=>{
|
||||||
|
srv.on('reviewed', (msg)=> received.push(msg))
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should add more messaging event handlers', ()=>{
|
||||||
|
srv.on('reviewed', ()=> ++M)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should add review', async ()=>{
|
||||||
|
const review = {
|
||||||
|
ID: 111 + (++N), // FIXME: why does the generic handler not fill this in automatically ?!? --> it does so when the request comes in via Postman / OData
|
||||||
|
subject: "201", title: "Captivating", rating: N
|
||||||
|
}
|
||||||
|
const response = await srv.create ('Reviews') .entries (review)
|
||||||
|
expect (response) .toMatchObject (review)
|
||||||
|
},100)
|
||||||
|
|
||||||
|
it ('should add more reviews', ()=> Promise.all ([
|
||||||
|
// REVISIT: mass operation should trigger one message per entry
|
||||||
|
// srv.create('Reviews').entries(
|
||||||
|
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
||||||
|
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
||||||
|
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
||||||
|
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
|
||||||
|
// ),
|
||||||
|
srv.create ('Reviews') .entries (
|
||||||
|
{ ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
|
||||||
|
),
|
||||||
|
srv.create ('Reviews') .entries (
|
||||||
|
{ ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
|
||||||
|
),
|
||||||
|
srv.create ('Reviews') .entries (
|
||||||
|
{ ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
|
||||||
|
),
|
||||||
|
srv.create ('Reviews') .entries (
|
||||||
|
{ ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
|
||||||
|
),
|
||||||
|
]) ,100)
|
||||||
|
|
||||||
|
it ('should have received all messages', async()=> {
|
||||||
|
await new Promise((done)=>setImmediate(done))
|
||||||
|
expect(M).toBe(N)
|
||||||
|
expect(received.length).toBe(N)
|
||||||
|
expect(received.map(m=>m.data)).toEqual([
|
||||||
|
{ subject: '201', rating: 1 },
|
||||||
|
{ subject: '201', rating: 1.5 },
|
||||||
|
{ subject: '201', rating: 2 },
|
||||||
|
{ subject: '201', rating: 2.5 },
|
||||||
|
{ subject: '201', rating: 3 },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
1
packages/users-service/index.cds
Normal file
1
packages/users-service/index.cds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
using from './srv/services';
|
||||||
12
packages/users-service/package.json
Normal file
12
packages/users-service/package.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-users",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse service for users-related functions, like registration, user profile mgmt, etc.",
|
||||||
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/capire-contacts": "^1.0.0",
|
||||||
|
"@sap/cds": "latest",
|
||||||
|
"express": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
packages/users-service/srv/services.cds
Normal file
7
packages/users-service/srv/services.cds
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using { sap.capire.contacts.Contacts as RegisteredUsers } from '@sap/capire-contacts';
|
||||||
|
namespace sap.capire.users;
|
||||||
|
|
||||||
|
service UsersService @(requires:'authenticated-user') {
|
||||||
|
entity MyProfile as select from RegisteredUsers;
|
||||||
|
action login ();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user