From 3731a7ea2335c7382d5b48a7d6e94ed2419f3333 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 1 Mar 2020 18:25:53 +0100 Subject: [PATCH 01/29] reloaded --- .../db/data/sap.capire.bookshop-Authors.csv | 0 .../db/data/sap.capire.bookshop-Books.csv | 0 .../data/sap.capire.bookshop-Books_texts.csv | 0 .../data/sap.capire.bookshop-OrderItems.csv | 0 .../db/data/sap.capire.bookshop-Orders.csv | 0 {packages/bookshop => bookshop}/db/schema.cds | 0 {packages/bookshop => bookshop}/package.json | 3 +- .../srv/admin-service.cds | 0 .../bookshop => bookshop}/srv/cat-service.cds | 0 .../bookshop => bookshop}/srv/cat-service.js | 0 .../bookshop => bookshop}/tests/bookshop.http | 0 .../bookshop => bookshop}/tests/orders.http | 0 .../data/sap.common-Countries.csv | 0 .../data/sap.common-Countries_texts.csv | 0 .../data/sap.common-Currencies.csv | 0 .../data/sap.common-Currencies_texts.csv | 0 common/index.cds | 45 +++++++++++++++++++ common/package.json | 7 +++ .../app/_i18n/i18n.properties | 0 .../app/_i18n/i18n_de.properties | 0 .../app/admin/fiori-service.cds | 2 +- .../app/admin/webapp/Component.js | 0 .../app/admin/webapp/i18n/i18n.properties | 0 .../app/admin/webapp/manifest.json | 0 .../app/browse/fiori-service.cds | 2 +- .../app/browse/webapp/Component.js | 0 .../app/browse/webapp/i18n/i18n.properties | 0 .../app/browse/webapp/manifest.json | 0 {packages/bookshop => fiori}/app/common.cds | 2 +- {packages/bookshop => fiori}/app/fiori.html | 0 {packages/bookshop => fiori}/app/index.cds | 2 + .../app/orders/fiori-service.cds | 2 +- .../app/orders/webapp/Component.js | 0 .../app/orders/webapp/i18n/i18n.properties | 0 .../app/orders/webapp/manifest.json | 0 fiori/package.json | 23 ++++++++++ lerna.json | 1 - package.json | 17 ++----- .../db/data/sap.common-Currencies.csv | 7 --- packages/common-contacts/db/code-lists.cds | 11 +---- .../data/sap.common-Currencies_texts.csv | 13 ------ packages/common-currencies/index.cds | 17 ------- packages/common-currencies/package.json | 10 ----- 43 files changed, 87 insertions(+), 77 deletions(-) rename {packages/bookshop => bookshop}/db/data/sap.capire.bookshop-Authors.csv (100%) rename {packages/bookshop => bookshop}/db/data/sap.capire.bookshop-Books.csv (100%) rename {packages/bookshop => bookshop}/db/data/sap.capire.bookshop-Books_texts.csv (100%) rename {packages/bookshop => bookshop}/db/data/sap.capire.bookshop-OrderItems.csv (100%) rename {packages/bookshop => bookshop}/db/data/sap.capire.bookshop-Orders.csv (100%) rename {packages/bookshop => bookshop}/db/schema.cds (100%) rename {packages/bookshop => bookshop}/package.json (89%) rename {packages/bookshop => bookshop}/srv/admin-service.cds (100%) rename {packages/bookshop => bookshop}/srv/cat-service.cds (100%) rename {packages/bookshop => bookshop}/srv/cat-service.js (100%) rename {packages/bookshop => bookshop}/tests/bookshop.http (100%) rename {packages/bookshop => bookshop}/tests/orders.http (100%) rename packages/common-contacts/db/data/sap.capire.contacts-Countries.csv => common/data/sap.common-Countries.csv (100%) rename packages/common-contacts/db/data/sap.capire.contacts-Countries_texts.csv => common/data/sap.common-Countries_texts.csv (100%) rename {packages/common-currencies => common}/data/sap.common-Currencies.csv (100%) rename {packages/bookshop/db => common}/data/sap.common-Currencies_texts.csv (100%) create mode 100644 common/index.cds create mode 100644 common/package.json rename {packages/bookshop => fiori}/app/_i18n/i18n.properties (100%) rename {packages/bookshop => fiori}/app/_i18n/i18n_de.properties (100%) rename {packages/bookshop => fiori}/app/admin/fiori-service.cds (92%) rename {packages/bookshop => fiori}/app/admin/webapp/Component.js (100%) rename {packages/bookshop => fiori}/app/admin/webapp/i18n/i18n.properties (100%) rename {packages/bookshop => fiori}/app/admin/webapp/manifest.json (100%) rename {packages/bookshop => fiori}/app/browse/fiori-service.cds (93%) rename {packages/bookshop => fiori}/app/browse/webapp/Component.js (100%) rename {packages/bookshop => fiori}/app/browse/webapp/i18n/i18n.properties (100%) rename {packages/bookshop => fiori}/app/browse/webapp/manifest.json (100%) rename {packages/bookshop => fiori}/app/common.cds (94%) rename {packages/bookshop => fiori}/app/fiori.html (100%) rename {packages/bookshop => fiori}/app/index.cds (85%) rename {packages/bookshop => fiori}/app/orders/fiori-service.cds (97%) rename {packages/bookshop => fiori}/app/orders/webapp/Component.js (100%) rename {packages/bookshop => fiori}/app/orders/webapp/i18n/i18n.properties (100%) rename {packages/bookshop => fiori}/app/orders/webapp/manifest.json (100%) create mode 100644 fiori/package.json delete mode 100644 lerna.json delete mode 100644 packages/bookshop/db/data/sap.common-Currencies.csv delete mode 100644 packages/common-currencies/data/sap.common-Currencies_texts.csv delete mode 100644 packages/common-currencies/index.cds delete mode 100644 packages/common-currencies/package.json diff --git a/packages/bookshop/db/data/sap.capire.bookshop-Authors.csv b/bookshop/db/data/sap.capire.bookshop-Authors.csv similarity index 100% rename from packages/bookshop/db/data/sap.capire.bookshop-Authors.csv rename to bookshop/db/data/sap.capire.bookshop-Authors.csv diff --git a/packages/bookshop/db/data/sap.capire.bookshop-Books.csv b/bookshop/db/data/sap.capire.bookshop-Books.csv similarity index 100% rename from packages/bookshop/db/data/sap.capire.bookshop-Books.csv rename to bookshop/db/data/sap.capire.bookshop-Books.csv diff --git a/packages/bookshop/db/data/sap.capire.bookshop-Books_texts.csv b/bookshop/db/data/sap.capire.bookshop-Books_texts.csv similarity index 100% rename from packages/bookshop/db/data/sap.capire.bookshop-Books_texts.csv rename to bookshop/db/data/sap.capire.bookshop-Books_texts.csv diff --git a/packages/bookshop/db/data/sap.capire.bookshop-OrderItems.csv b/bookshop/db/data/sap.capire.bookshop-OrderItems.csv similarity index 100% rename from packages/bookshop/db/data/sap.capire.bookshop-OrderItems.csv rename to bookshop/db/data/sap.capire.bookshop-OrderItems.csv diff --git a/packages/bookshop/db/data/sap.capire.bookshop-Orders.csv b/bookshop/db/data/sap.capire.bookshop-Orders.csv similarity index 100% rename from packages/bookshop/db/data/sap.capire.bookshop-Orders.csv rename to bookshop/db/data/sap.capire.bookshop-Orders.csv diff --git a/packages/bookshop/db/schema.cds b/bookshop/db/schema.cds similarity index 100% rename from packages/bookshop/db/schema.cds rename to bookshop/db/schema.cds diff --git a/packages/bookshop/package.json b/bookshop/package.json similarity index 89% rename from packages/bookshop/package.json rename to bookshop/package.json index 6764a1b0..d8588d4b 100644 --- a/packages/bookshop/package.json +++ b/bookshop/package.json @@ -4,7 +4,8 @@ "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "license": "SAP SAMPLE CODE LICENSE", "dependencies": { - "@sap/cds": "latest", + "@sap/capire-common": "*", + "@sap/cds": "*", "express": "*" }, "scripts": { diff --git a/packages/bookshop/srv/admin-service.cds b/bookshop/srv/admin-service.cds similarity index 100% rename from packages/bookshop/srv/admin-service.cds rename to bookshop/srv/admin-service.cds diff --git a/packages/bookshop/srv/cat-service.cds b/bookshop/srv/cat-service.cds similarity index 100% rename from packages/bookshop/srv/cat-service.cds rename to bookshop/srv/cat-service.cds diff --git a/packages/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js similarity index 100% rename from packages/bookshop/srv/cat-service.js rename to bookshop/srv/cat-service.js diff --git a/packages/bookshop/tests/bookshop.http b/bookshop/tests/bookshop.http similarity index 100% rename from packages/bookshop/tests/bookshop.http rename to bookshop/tests/bookshop.http diff --git a/packages/bookshop/tests/orders.http b/bookshop/tests/orders.http similarity index 100% rename from packages/bookshop/tests/orders.http rename to bookshop/tests/orders.http diff --git a/packages/common-contacts/db/data/sap.capire.contacts-Countries.csv b/common/data/sap.common-Countries.csv similarity index 100% rename from packages/common-contacts/db/data/sap.capire.contacts-Countries.csv rename to common/data/sap.common-Countries.csv diff --git a/packages/common-contacts/db/data/sap.capire.contacts-Countries_texts.csv b/common/data/sap.common-Countries_texts.csv similarity index 100% rename from packages/common-contacts/db/data/sap.capire.contacts-Countries_texts.csv rename to common/data/sap.common-Countries_texts.csv diff --git a/packages/common-currencies/data/sap.common-Currencies.csv b/common/data/sap.common-Currencies.csv similarity index 100% rename from packages/common-currencies/data/sap.common-Currencies.csv rename to common/data/sap.common-Currencies.csv diff --git a/packages/bookshop/db/data/sap.common-Currencies_texts.csv b/common/data/sap.common-Currencies_texts.csv similarity index 100% rename from packages/bookshop/db/data/sap.common-Currencies_texts.csv rename to common/data/sap.common-Currencies_texts.csv diff --git a/common/index.cds b/common/index.cds new file mode 100644 index 00000000..39e42d28 --- /dev/null +++ b/common/index.cds @@ -0,0 +1,45 @@ +using { sap } from '@sap/cds/common'; + +extend sap.common.Currencies with { + // Currencies.code = ISO 4217 alphabetic three-letter code + // with the first two letters being equal to ISO 3166 alphabetic country codes + // 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 + numcode : Integer; + exponent : Integer; //> e.g. 2 --> 1 Dollar = 10^2 Cent + minor : String; //> e.g. 'Cent' +} + + +/** + * 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; + */ + +context 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; + } + +} diff --git a/common/package.json b/common/package.json new file mode 100644 index 00000000..ec5c34f7 --- /dev/null +++ b/common/package.json @@ -0,0 +1,7 @@ +{ + "name": "@sap/capire-common", + "version": "1.0.0", + "description": "A reuse package providing common domain models and services for common data.", + "repository": "https://github.com/SAP-samples/cloud-cap-samples.git", + "license": "SAP SAMPLE CODE LICENSE" +} diff --git a/packages/bookshop/app/_i18n/i18n.properties b/fiori/app/_i18n/i18n.properties similarity index 100% rename from packages/bookshop/app/_i18n/i18n.properties rename to fiori/app/_i18n/i18n.properties diff --git a/packages/bookshop/app/_i18n/i18n_de.properties b/fiori/app/_i18n/i18n_de.properties similarity index 100% rename from packages/bookshop/app/_i18n/i18n_de.properties rename to fiori/app/_i18n/i18n_de.properties diff --git a/packages/bookshop/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds similarity index 92% rename from packages/bookshop/app/admin/fiori-service.cds rename to fiori/app/admin/fiori-service.cds index 5fd19df0..dbb7f581 100644 --- a/packages/bookshop/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '../../srv/admin-service'; +using AdminService from '@sap/capire-bookshop/srv/admin-service'; //////////////////////////////////////////////////////////////////////////// // diff --git a/packages/bookshop/app/admin/webapp/Component.js b/fiori/app/admin/webapp/Component.js similarity index 100% rename from packages/bookshop/app/admin/webapp/Component.js rename to fiori/app/admin/webapp/Component.js diff --git a/packages/bookshop/app/admin/webapp/i18n/i18n.properties b/fiori/app/admin/webapp/i18n/i18n.properties similarity index 100% rename from packages/bookshop/app/admin/webapp/i18n/i18n.properties rename to fiori/app/admin/webapp/i18n/i18n.properties diff --git a/packages/bookshop/app/admin/webapp/manifest.json b/fiori/app/admin/webapp/manifest.json similarity index 100% rename from packages/bookshop/app/admin/webapp/manifest.json rename to fiori/app/admin/webapp/manifest.json diff --git a/packages/bookshop/app/browse/fiori-service.cds b/fiori/app/browse/fiori-service.cds similarity index 93% rename from packages/bookshop/app/browse/fiori-service.cds rename to fiori/app/browse/fiori-service.cds index d0d12da3..712bca29 100644 --- a/packages/bookshop/app/browse/fiori-service.cds +++ b/fiori/app/browse/fiori-service.cds @@ -1,4 +1,4 @@ -using CatalogService from '../../srv/cat-service'; +using CatalogService from '@sap/capire-bookshop/srv/cat-service'; //////////////////////////////////////////////////////////////////////////// // diff --git a/packages/bookshop/app/browse/webapp/Component.js b/fiori/app/browse/webapp/Component.js similarity index 100% rename from packages/bookshop/app/browse/webapp/Component.js rename to fiori/app/browse/webapp/Component.js diff --git a/packages/bookshop/app/browse/webapp/i18n/i18n.properties b/fiori/app/browse/webapp/i18n/i18n.properties similarity index 100% rename from packages/bookshop/app/browse/webapp/i18n/i18n.properties rename to fiori/app/browse/webapp/i18n/i18n.properties diff --git a/packages/bookshop/app/browse/webapp/manifest.json b/fiori/app/browse/webapp/manifest.json similarity index 100% rename from packages/bookshop/app/browse/webapp/manifest.json rename to fiori/app/browse/webapp/manifest.json diff --git a/packages/bookshop/app/common.cds b/fiori/app/common.cds similarity index 94% rename from packages/bookshop/app/common.cds rename to fiori/app/common.cds index 309daaf5..d82ed16b 100644 --- a/packages/bookshop/app/common.cds +++ b/fiori/app/common.cds @@ -2,7 +2,7 @@ Common Annotations shared by all apps */ -using { sap.capire.bookshop as my } from '../db/schema'; +using { sap.capire.bookshop as my } from '@sap/capire-bookshop/db/schema'; //////////////////////////////////////////////////////////////////////////// diff --git a/packages/bookshop/app/fiori.html b/fiori/app/fiori.html similarity index 100% rename from packages/bookshop/app/fiori.html rename to fiori/app/fiori.html diff --git a/packages/bookshop/app/index.cds b/fiori/app/index.cds similarity index 85% rename from packages/bookshop/app/index.cds rename to fiori/app/index.cds index 431bace1..b457f478 100644 --- a/packages/bookshop/app/index.cds +++ b/fiori/app/index.cds @@ -6,3 +6,5 @@ using from './admin/fiori-service'; using from './browse/fiori-service'; using from './orders/fiori-service'; using from './common'; + +using from '@sap/capire-common'; diff --git a/packages/bookshop/app/orders/fiori-service.cds b/fiori/app/orders/fiori-service.cds similarity index 97% rename from packages/bookshop/app/orders/fiori-service.cds rename to fiori/app/orders/fiori-service.cds index a504a022..3733aa18 100644 --- a/packages/bookshop/app/orders/fiori-service.cds +++ b/fiori/app/orders/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '../../srv/admin-service'; +using AdminService from '@sap/capire-bookshop/srv/admin-service'; annotate AdminService.Books with { price @Common.FieldControl: #ReadOnly; diff --git a/packages/bookshop/app/orders/webapp/Component.js b/fiori/app/orders/webapp/Component.js similarity index 100% rename from packages/bookshop/app/orders/webapp/Component.js rename to fiori/app/orders/webapp/Component.js diff --git a/packages/bookshop/app/orders/webapp/i18n/i18n.properties b/fiori/app/orders/webapp/i18n/i18n.properties similarity index 100% rename from packages/bookshop/app/orders/webapp/i18n/i18n.properties rename to fiori/app/orders/webapp/i18n/i18n.properties diff --git a/packages/bookshop/app/orders/webapp/manifest.json b/fiori/app/orders/webapp/manifest.json similarity index 100% rename from packages/bookshop/app/orders/webapp/manifest.json rename to fiori/app/orders/webapp/manifest.json diff --git a/fiori/package.json b/fiori/package.json new file mode 100644 index 00000000..950e0fc2 --- /dev/null +++ b/fiori/package.json @@ -0,0 +1,23 @@ +{ + "name": "@sap/capire-fiori", + "version": "1.0.0", + "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", + "license": "SAP SAMPLE CODE LICENSE", + "dependencies": { + "@sap/capire-bookshop": "*", + "@sap/capire-common": "*", + "@sap/cds": "*", + "express": "*" + }, + "scripts": { + "start": "cds run --in-memory?", + "watch": "cds watch" + }, + "cds": { + "requires": { + "db": { + "kind": "sql" + } + } + } +} \ No newline at end of file diff --git a/lerna.json b/lerna.json deleted file mode 100644 index c8e17ebd..00000000 --- a/lerna.json +++ /dev/null @@ -1 +0,0 @@ -{"packages":["packages/*"],"version":"1.0.0"} diff --git a/package.json b/package.json index 499371c6..e0d3a140 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,11 @@ "author": "daniel.hutzel@sap.com", "private": true, "scripts": { - "lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save", - "install": "(npm -s run lerna) && lerna bootstrap --hoist", - "cleanup": "lerna clean -y && rm -fr node_modules", - "bookshop": "cds watch packages/bookshop", - "bookshop-enhanced": "cds watch packages/bookshop-enhanced", - "reviews-service": "cds watch packages/reviews-service", - - "bookstore": "cds watch packages/bookstore", - "media-server": "cds watch packages/media-server" + "bookshop": "cds watch bookshop" }, "dependencies": { - "@sap/cds": "latest", - "express": "*" - }, - "devDependencies": { - "sqlite3": "*" + "@sap/capire-bookshop": "./bookshop", + "@sap/capire-common": "./common" }, "--add-these-to-devDependencies-for-tests": { "@types/jest": "*", diff --git a/packages/bookshop/db/data/sap.common-Currencies.csv b/packages/bookshop/db/data/sap.common-Currencies.csv deleted file mode 100644 index 48f3ec32..00000000 --- a/packages/bookshop/db/data/sap.common-Currencies.csv +++ /dev/null @@ -1,7 +0,0 @@ -code;symbol;name;descr -EUR;€;Euro;European Euro -USD;$;US Dollar;United States Dollar -CAD;$;Canadian Dollar;Canadian Dollar -AUD;$;Australian Dollar;Australian Dollar -GBP;£;Pound;Great Britain Pound -ILS;₪;Shekel;Israeli New Shekel \ No newline at end of file diff --git a/packages/common-contacts/db/code-lists.cds b/packages/common-contacts/db/code-lists.cds index 4da5c872..1d31dc7a 100644 --- a/packages/common-contacts/db/code-lists.cds +++ b/packages/common-contacts/db/code-lists.cds @@ -1,6 +1,5 @@ -using { sap.capire.contacts.PostalAddress } from './schema'; using { sap } from '@sap/cds/common'; -namespace sap.capire.contacts; +namespace sap.common; /** * The Code Lists below are designed as optional extensions to @@ -9,7 +8,6 @@ namespace sap.capire.contacts; * 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; } @@ -28,10 +26,3 @@ 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; -} diff --git a/packages/common-currencies/data/sap.common-Currencies_texts.csv b/packages/common-currencies/data/sap.common-Currencies_texts.csv deleted file mode 100644 index 4d2ead51..00000000 --- a/packages/common-currencies/data/sap.common-Currencies_texts.csv +++ /dev/null @@ -1,13 +0,0 @@ -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 \ No newline at end of file diff --git a/packages/common-currencies/index.cds b/packages/common-currencies/index.cds deleted file mode 100644 index 82da4228..00000000 --- a/packages/common-currencies/index.cds +++ /dev/null @@ -1,17 +0,0 @@ -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 \ No newline at end of file diff --git a/packages/common-currencies/package.json b/packages/common-currencies/package.json deleted file mode 100644 index 68be970e..00000000 --- a/packages/common-currencies/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "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" - } -} From 658a961459754d733ec4962c5b9be89ba88cff44 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 1 Mar 2020 18:27:12 +0100 Subject: [PATCH 02/29] Added languages data --- common/data/sap.common-Languages.csv | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 common/data/sap.common-Languages.csv diff --git a/common/data/sap.common-Languages.csv b/common/data/sap.common-Languages.csv new file mode 100644 index 00000000..17350b35 --- /dev/null +++ b/common/data/sap.common-Languages.csv @@ -0,0 +1,5 @@ +code;name +de;German +fr;French +en;English +en_GB;British English From d9df2930cbd36d40a27a07272a91e34dc40967bc Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 1 Mar 2020 18:28:25 +0100 Subject: [PATCH 03/29] Added language texts --- common/data/sap.common-Languages_texts.csv | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/data/sap.common-Languages_texts.csv diff --git a/common/data/sap.common-Languages_texts.csv b/common/data/sap.common-Languages_texts.csv new file mode 100644 index 00000000..d850ec0d --- /dev/null +++ b/common/data/sap.common-Languages_texts.csv @@ -0,0 +1,10 @@ +code;locale;name +de;en;German +de;de;Deutsch +de;fr;Allemande +fr;en;French +fr;de;Französisch +fr;fr;Francais +en;en;English +en;de;Englisch +en;fr;Anglais From 26d7fc767cbbecfb43742f19ef9ccbb142d8602b Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 00:08:49 +0100 Subject: [PATCH 04/29] ... --- .../bookshop-enhanced/app/index.cds | 0 .../bookshop-enhanced/db/schema.cds | 0 .../bookshop-enhanced/package.json | 0 .../bookshop-enhanced/srv/services.cds | 0 .../bookshop-enhanced/srv/services.js | 0 .../bookshop-enhanced/tests/genres.http | 0 .../bookshop-enhanced/tests/reviews.http | 0 .../db/data/sap.capire.bookstore-Authors.csv | 0 .../data/sap.capire.products-Categories.csv | 0 .../db/data/sap.capire.products-Products.csv | 0 .../sap.capire.products-Products_texts.csv | 0 .../bookstore/db/schema.cds | 0 .../bookstore/package.json | 0 .../bookstore/srv/_workarounds.cds | 0 .../bookstore/srv/services.cds | 0 .../bookstore/srv/services.js | 0 .../bookstore/tests/books.cds | 0 .../bookstore/tests/localized-data.test.js | 0 .../common-contacts/db/code-lists.cds | 0 .../common-contacts/db/schema.cds | 0 .../common-contacts/index.cds | 0 .../common-contacts/package.json | 0 .../common-contacts/readme.md | 0 .../common-contacts/srv/code-lists.js | 0 .../common-contacts/tests/code-lists.test.js | 0 .../common-contacts/tests/index.cds | 0 .../media-server/db/data-model.cds | 0 .../media-server/index.cds | 0 .../media-server/package.json | 0 .../media-server/srv/media-service.cds | 0 .../media-server/srv/media-service.js | 0 .../db/data/sap.capire.orders-OrderItems.csv | 0 .../db/data/sap.capire.orders-Orders.csv | 0 .../orders-service/db/schema.cds | 0 .../orders-service/index.cds | 0 .../orders-service/package.json | 0 .../orders-service/srv/orders-service.cds | 0 .../products-service/db/schema.cds | 0 .../products-service/index.cds | 0 .../products-service/package.json | 0 .../products-service/srv/admin-service.cds | 0 .../products-service/tests/categories.test.js | 0 .../data/sap.capire.products-Categories.csv | 0 .../products-service/tests/postman.json | 0 .../users-service/index.cds | 0 .../users-service/package.json | 0 .../users-service/srv/services.cds | 0 .../db/data/sap.capire.bookshop-Genres.csv | 16 ++++++++ bookshop/db/schema.cds | 9 ++++- bookshop/package.json | 7 ++-- bookshop/test/genres.cds | 4 ++ bookshop/test/genres.http | 38 +++++++++++++++++++ .../bookshop.http => test/requests.http} | 0 bookshop/tests/orders.http | 18 --------- common/package.json | 2 +- fiori/app/admin/fiori-service.cds | 37 +++++++++++++++++- fiori/app/browse/fiori-service.cds | 3 +- fiori/app/common.cds | 7 +++- fiori/app/index.cds | 2 +- fiori/app/orders/fiori-service.cds | 2 +- fiori/db/schema.cds | 3 ++ fiori/package.json | 7 ++-- fiori/srv/admin-service.cds | 5 +++ fiori/srv/admin-service.js | 8 ++++ package.json | 7 ++-- .../reviews-service => reviews}/db/schema.cds | 0 .../reviews-service => reviews}/index.cds | 0 .../reviews-service => reviews}/package.json | 0 .../srv/reviews-service.cds | 0 .../srv/reviews-service.js | 0 .../tests/messaging.test.js | 0 71 files changed, 141 insertions(+), 34 deletions(-) rename {packages => _packages}/bookshop-enhanced/app/index.cds (100%) rename {packages => _packages}/bookshop-enhanced/db/schema.cds (100%) rename {packages => _packages}/bookshop-enhanced/package.json (100%) rename {packages => _packages}/bookshop-enhanced/srv/services.cds (100%) rename {packages => _packages}/bookshop-enhanced/srv/services.js (100%) rename {packages => _packages}/bookshop-enhanced/tests/genres.http (100%) rename {packages => _packages}/bookshop-enhanced/tests/reviews.http (100%) rename {packages => _packages}/bookstore/db/data/sap.capire.bookstore-Authors.csv (100%) rename {packages => _packages}/bookstore/db/data/sap.capire.products-Categories.csv (100%) rename {packages => _packages}/bookstore/db/data/sap.capire.products-Products.csv (100%) rename {packages => _packages}/bookstore/db/data/sap.capire.products-Products_texts.csv (100%) rename {packages => _packages}/bookstore/db/schema.cds (100%) rename {packages => _packages}/bookstore/package.json (100%) rename {packages => _packages}/bookstore/srv/_workarounds.cds (100%) rename {packages => _packages}/bookstore/srv/services.cds (100%) rename {packages => _packages}/bookstore/srv/services.js (100%) rename {packages => _packages}/bookstore/tests/books.cds (100%) rename {packages => _packages}/bookstore/tests/localized-data.test.js (100%) rename {packages => _packages}/common-contacts/db/code-lists.cds (100%) rename {packages => _packages}/common-contacts/db/schema.cds (100%) rename {packages => _packages}/common-contacts/index.cds (100%) rename {packages => _packages}/common-contacts/package.json (100%) rename {packages => _packages}/common-contacts/readme.md (100%) rename {packages => _packages}/common-contacts/srv/code-lists.js (100%) rename {packages => _packages}/common-contacts/tests/code-lists.test.js (100%) rename {packages => _packages}/common-contacts/tests/index.cds (100%) rename {packages => _packages}/media-server/db/data-model.cds (100%) rename {packages => _packages}/media-server/index.cds (100%) rename {packages => _packages}/media-server/package.json (100%) rename {packages => _packages}/media-server/srv/media-service.cds (100%) rename {packages => _packages}/media-server/srv/media-service.js (100%) rename {packages => _packages}/orders-service/db/data/sap.capire.orders-OrderItems.csv (100%) rename {packages => _packages}/orders-service/db/data/sap.capire.orders-Orders.csv (100%) rename {packages => _packages}/orders-service/db/schema.cds (100%) rename {packages => _packages}/orders-service/index.cds (100%) rename {packages => _packages}/orders-service/package.json (100%) rename {packages => _packages}/orders-service/srv/orders-service.cds (100%) rename {packages => _packages}/products-service/db/schema.cds (100%) rename {packages => _packages}/products-service/index.cds (100%) rename {packages => _packages}/products-service/package.json (100%) rename {packages => _packages}/products-service/srv/admin-service.cds (100%) rename {packages => _packages}/products-service/tests/categories.test.js (100%) rename {packages => _packages}/products-service/tests/data/sap.capire.products-Categories.csv (100%) rename {packages => _packages}/products-service/tests/postman.json (100%) rename {packages => _packages}/users-service/index.cds (100%) rename {packages => _packages}/users-service/package.json (100%) rename {packages => _packages}/users-service/srv/services.cds (100%) create mode 100644 bookshop/db/data/sap.capire.bookshop-Genres.csv create mode 100644 bookshop/test/genres.cds create mode 100644 bookshop/test/genres.http rename bookshop/{tests/bookshop.http => test/requests.http} (100%) delete mode 100644 bookshop/tests/orders.http create mode 100644 fiori/db/schema.cds create mode 100644 fiori/srv/admin-service.cds create mode 100644 fiori/srv/admin-service.js rename {packages/reviews-service => reviews}/db/schema.cds (100%) rename {packages/reviews-service => reviews}/index.cds (100%) rename {packages/reviews-service => reviews}/package.json (100%) rename {packages/reviews-service => reviews}/srv/reviews-service.cds (100%) rename {packages/reviews-service => reviews}/srv/reviews-service.js (100%) rename {packages/reviews-service => reviews}/tests/messaging.test.js (100%) diff --git a/packages/bookshop-enhanced/app/index.cds b/_packages/bookshop-enhanced/app/index.cds similarity index 100% rename from packages/bookshop-enhanced/app/index.cds rename to _packages/bookshop-enhanced/app/index.cds diff --git a/packages/bookshop-enhanced/db/schema.cds b/_packages/bookshop-enhanced/db/schema.cds similarity index 100% rename from packages/bookshop-enhanced/db/schema.cds rename to _packages/bookshop-enhanced/db/schema.cds diff --git a/packages/bookshop-enhanced/package.json b/_packages/bookshop-enhanced/package.json similarity index 100% rename from packages/bookshop-enhanced/package.json rename to _packages/bookshop-enhanced/package.json diff --git a/packages/bookshop-enhanced/srv/services.cds b/_packages/bookshop-enhanced/srv/services.cds similarity index 100% rename from packages/bookshop-enhanced/srv/services.cds rename to _packages/bookshop-enhanced/srv/services.cds diff --git a/packages/bookshop-enhanced/srv/services.js b/_packages/bookshop-enhanced/srv/services.js similarity index 100% rename from packages/bookshop-enhanced/srv/services.js rename to _packages/bookshop-enhanced/srv/services.js diff --git a/packages/bookshop-enhanced/tests/genres.http b/_packages/bookshop-enhanced/tests/genres.http similarity index 100% rename from packages/bookshop-enhanced/tests/genres.http rename to _packages/bookshop-enhanced/tests/genres.http diff --git a/packages/bookshop-enhanced/tests/reviews.http b/_packages/bookshop-enhanced/tests/reviews.http similarity index 100% rename from packages/bookshop-enhanced/tests/reviews.http rename to _packages/bookshop-enhanced/tests/reviews.http diff --git a/packages/bookstore/db/data/sap.capire.bookstore-Authors.csv b/_packages/bookstore/db/data/sap.capire.bookstore-Authors.csv similarity index 100% rename from packages/bookstore/db/data/sap.capire.bookstore-Authors.csv rename to _packages/bookstore/db/data/sap.capire.bookstore-Authors.csv diff --git a/packages/bookstore/db/data/sap.capire.products-Categories.csv b/_packages/bookstore/db/data/sap.capire.products-Categories.csv similarity index 100% rename from packages/bookstore/db/data/sap.capire.products-Categories.csv rename to _packages/bookstore/db/data/sap.capire.products-Categories.csv diff --git a/packages/bookstore/db/data/sap.capire.products-Products.csv b/_packages/bookstore/db/data/sap.capire.products-Products.csv similarity index 100% rename from packages/bookstore/db/data/sap.capire.products-Products.csv rename to _packages/bookstore/db/data/sap.capire.products-Products.csv diff --git a/packages/bookstore/db/data/sap.capire.products-Products_texts.csv b/_packages/bookstore/db/data/sap.capire.products-Products_texts.csv similarity index 100% rename from packages/bookstore/db/data/sap.capire.products-Products_texts.csv rename to _packages/bookstore/db/data/sap.capire.products-Products_texts.csv diff --git a/packages/bookstore/db/schema.cds b/_packages/bookstore/db/schema.cds similarity index 100% rename from packages/bookstore/db/schema.cds rename to _packages/bookstore/db/schema.cds diff --git a/packages/bookstore/package.json b/_packages/bookstore/package.json similarity index 100% rename from packages/bookstore/package.json rename to _packages/bookstore/package.json diff --git a/packages/bookstore/srv/_workarounds.cds b/_packages/bookstore/srv/_workarounds.cds similarity index 100% rename from packages/bookstore/srv/_workarounds.cds rename to _packages/bookstore/srv/_workarounds.cds diff --git a/packages/bookstore/srv/services.cds b/_packages/bookstore/srv/services.cds similarity index 100% rename from packages/bookstore/srv/services.cds rename to _packages/bookstore/srv/services.cds diff --git a/packages/bookstore/srv/services.js b/_packages/bookstore/srv/services.js similarity index 100% rename from packages/bookstore/srv/services.js rename to _packages/bookstore/srv/services.js diff --git a/packages/bookstore/tests/books.cds b/_packages/bookstore/tests/books.cds similarity index 100% rename from packages/bookstore/tests/books.cds rename to _packages/bookstore/tests/books.cds diff --git a/packages/bookstore/tests/localized-data.test.js b/_packages/bookstore/tests/localized-data.test.js similarity index 100% rename from packages/bookstore/tests/localized-data.test.js rename to _packages/bookstore/tests/localized-data.test.js diff --git a/packages/common-contacts/db/code-lists.cds b/_packages/common-contacts/db/code-lists.cds similarity index 100% rename from packages/common-contacts/db/code-lists.cds rename to _packages/common-contacts/db/code-lists.cds diff --git a/packages/common-contacts/db/schema.cds b/_packages/common-contacts/db/schema.cds similarity index 100% rename from packages/common-contacts/db/schema.cds rename to _packages/common-contacts/db/schema.cds diff --git a/packages/common-contacts/index.cds b/_packages/common-contacts/index.cds similarity index 100% rename from packages/common-contacts/index.cds rename to _packages/common-contacts/index.cds diff --git a/packages/common-contacts/package.json b/_packages/common-contacts/package.json similarity index 100% rename from packages/common-contacts/package.json rename to _packages/common-contacts/package.json diff --git a/packages/common-contacts/readme.md b/_packages/common-contacts/readme.md similarity index 100% rename from packages/common-contacts/readme.md rename to _packages/common-contacts/readme.md diff --git a/packages/common-contacts/srv/code-lists.js b/_packages/common-contacts/srv/code-lists.js similarity index 100% rename from packages/common-contacts/srv/code-lists.js rename to _packages/common-contacts/srv/code-lists.js diff --git a/packages/common-contacts/tests/code-lists.test.js b/_packages/common-contacts/tests/code-lists.test.js similarity index 100% rename from packages/common-contacts/tests/code-lists.test.js rename to _packages/common-contacts/tests/code-lists.test.js diff --git a/packages/common-contacts/tests/index.cds b/_packages/common-contacts/tests/index.cds similarity index 100% rename from packages/common-contacts/tests/index.cds rename to _packages/common-contacts/tests/index.cds diff --git a/packages/media-server/db/data-model.cds b/_packages/media-server/db/data-model.cds similarity index 100% rename from packages/media-server/db/data-model.cds rename to _packages/media-server/db/data-model.cds diff --git a/packages/media-server/index.cds b/_packages/media-server/index.cds similarity index 100% rename from packages/media-server/index.cds rename to _packages/media-server/index.cds diff --git a/packages/media-server/package.json b/_packages/media-server/package.json similarity index 100% rename from packages/media-server/package.json rename to _packages/media-server/package.json diff --git a/packages/media-server/srv/media-service.cds b/_packages/media-server/srv/media-service.cds similarity index 100% rename from packages/media-server/srv/media-service.cds rename to _packages/media-server/srv/media-service.cds diff --git a/packages/media-server/srv/media-service.js b/_packages/media-server/srv/media-service.js similarity index 100% rename from packages/media-server/srv/media-service.js rename to _packages/media-server/srv/media-service.js diff --git a/packages/orders-service/db/data/sap.capire.orders-OrderItems.csv b/_packages/orders-service/db/data/sap.capire.orders-OrderItems.csv similarity index 100% rename from packages/orders-service/db/data/sap.capire.orders-OrderItems.csv rename to _packages/orders-service/db/data/sap.capire.orders-OrderItems.csv diff --git a/packages/orders-service/db/data/sap.capire.orders-Orders.csv b/_packages/orders-service/db/data/sap.capire.orders-Orders.csv similarity index 100% rename from packages/orders-service/db/data/sap.capire.orders-Orders.csv rename to _packages/orders-service/db/data/sap.capire.orders-Orders.csv diff --git a/packages/orders-service/db/schema.cds b/_packages/orders-service/db/schema.cds similarity index 100% rename from packages/orders-service/db/schema.cds rename to _packages/orders-service/db/schema.cds diff --git a/packages/orders-service/index.cds b/_packages/orders-service/index.cds similarity index 100% rename from packages/orders-service/index.cds rename to _packages/orders-service/index.cds diff --git a/packages/orders-service/package.json b/_packages/orders-service/package.json similarity index 100% rename from packages/orders-service/package.json rename to _packages/orders-service/package.json diff --git a/packages/orders-service/srv/orders-service.cds b/_packages/orders-service/srv/orders-service.cds similarity index 100% rename from packages/orders-service/srv/orders-service.cds rename to _packages/orders-service/srv/orders-service.cds diff --git a/packages/products-service/db/schema.cds b/_packages/products-service/db/schema.cds similarity index 100% rename from packages/products-service/db/schema.cds rename to _packages/products-service/db/schema.cds diff --git a/packages/products-service/index.cds b/_packages/products-service/index.cds similarity index 100% rename from packages/products-service/index.cds rename to _packages/products-service/index.cds diff --git a/packages/products-service/package.json b/_packages/products-service/package.json similarity index 100% rename from packages/products-service/package.json rename to _packages/products-service/package.json diff --git a/packages/products-service/srv/admin-service.cds b/_packages/products-service/srv/admin-service.cds similarity index 100% rename from packages/products-service/srv/admin-service.cds rename to _packages/products-service/srv/admin-service.cds diff --git a/packages/products-service/tests/categories.test.js b/_packages/products-service/tests/categories.test.js similarity index 100% rename from packages/products-service/tests/categories.test.js rename to _packages/products-service/tests/categories.test.js diff --git a/packages/products-service/tests/data/sap.capire.products-Categories.csv b/_packages/products-service/tests/data/sap.capire.products-Categories.csv similarity index 100% rename from packages/products-service/tests/data/sap.capire.products-Categories.csv rename to _packages/products-service/tests/data/sap.capire.products-Categories.csv diff --git a/packages/products-service/tests/postman.json b/_packages/products-service/tests/postman.json similarity index 100% rename from packages/products-service/tests/postman.json rename to _packages/products-service/tests/postman.json diff --git a/packages/users-service/index.cds b/_packages/users-service/index.cds similarity index 100% rename from packages/users-service/index.cds rename to _packages/users-service/index.cds diff --git a/packages/users-service/package.json b/_packages/users-service/package.json similarity index 100% rename from packages/users-service/package.json rename to _packages/users-service/package.json diff --git a/packages/users-service/srv/services.cds b/_packages/users-service/srv/services.cds similarity index 100% rename from packages/users-service/srv/services.cds rename to _packages/users-service/srv/services.cds diff --git a/bookshop/db/data/sap.capire.bookshop-Genres.csv b/bookshop/db/data/sap.capire.bookshop-Genres.csv new file mode 100644 index 00000000..08435ca9 --- /dev/null +++ b/bookshop/db/data/sap.capire.bookshop-Genres.csv @@ -0,0 +1,16 @@ +ID;parent_ID;name +10;;Fiction +11;10;Drama +12;10;Poetry +13;10;Fantasy +14;10;Science Fiction +15;10;Romance +16;10;Mystery +17;10;Thriller +18;10;Dystopia +19;10;Fairy Tale +20;;Non-Fiction +21;20;Biography +22;20;Autobiography +23;20;Essay +24;20;Speech diff --git a/bookshop/db/schema.cds b/bookshop/db/schema.cds index e0e587be..bb428f1d 100644 --- a/bookshop/db/schema.cds +++ b/bookshop/db/schema.cds @@ -1,11 +1,12 @@ namespace sap.capire.bookshop; -using { Currency, managed, cuid } from '@sap/cds/common'; +using { Currency, managed, cuid, sap } from '@sap/cds/common'; entity Books : managed { key ID : Integer; title : localized String(111); descr : localized String(1111); author : Association to Authors; + genre : Association to Genres; stock : Integer; price : Decimal(9,2); currency : Currency; @@ -21,6 +22,12 @@ entity Authors : managed { books : Association to many Books on books.author = $self; } +entity Genres : sap.common.CodeList { + key ID : Integer; + parent : Association to Genres; + children : Composition of many Genres on children.parent = $self; +} + entity Orders : cuid, managed { OrderNo : String @title:'Order Number'; //> readable key Items : Composition of many OrderItems on Items.parent = $self; diff --git a/bookshop/package.json b/bookshop/package.json index d8588d4b..e874e8df 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -1,16 +1,17 @@ { - "name": "@sap/capire-bookshop", + "name": "@capire/bookshop", "version": "1.0.0", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "license": "SAP SAMPLE CODE LICENSE", "dependencies": { - "@sap/capire-common": "*", + "@capire/common": "*", "@sap/cds": "*", "express": "*" }, "scripts": { "start": "cds run --in-memory?", - "watch": "cds watch" + "watch": "cds watch", + "test:genres": "cds serve test/genres --in-memory" }, "cds": { "requires": { diff --git a/bookshop/test/genres.cds b/bookshop/test/genres.cds new file mode 100644 index 00000000..a9347153 --- /dev/null +++ b/bookshop/test/genres.cds @@ -0,0 +1,4 @@ +using { sap.capire.bookshop as my } from '../db/schema'; +service TestService { + entity Genres as projection on my.Genres; +} diff --git a/bookshop/test/genres.http b/bookshop/test/genres.http new file mode 100644 index 00000000..9d85a472 --- /dev/null +++ b/bookshop/test/genres.http @@ -0,0 +1,38 @@ +################################################# +# +# Genres +# + +GET http://localhost:4004/test/Genres? +### + +GET http://localhost:4004/test/Genres? +&$filter=parent_ID eq null&$select=name +&$expand=children($select=name) +### + +POST http://localhost:4004/test/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/test/Genres(100)? +# &$expand=children +# &$expand=children($expand=children($expand=children($expand=children))) +### + +DELETE http://localhost:4004/test/Genres(103) +### + +DELETE http://localhost:4004/test/Genres(100) +### diff --git a/bookshop/tests/bookshop.http b/bookshop/test/requests.http similarity index 100% rename from bookshop/tests/bookshop.http rename to bookshop/test/requests.http diff --git a/bookshop/tests/orders.http b/bookshop/tests/orders.http deleted file mode 100644 index a0f72d1c..00000000 --- a/bookshop/tests/orders.http +++ /dev/null @@ -1,18 +0,0 @@ - -### List Books with their current stocks -GET http://localhost:4004/admin/Books?$select=ID,stock - -### List all Orders -GET http://localhost:4004/admin/Orders? -&$expand=Items - -### Submit Orders -POST http://localhost:4004/browse/Orders -Content-Type: application/json - -{ "OrderNo":"2019-09...", "Items":[ - { "book_ID":201, "amount":5 }, - { "book_ID":207, "amount":3 } -]} - -# Sending this three times should result in a 409: 5 exceeds stock for book #201 \ No newline at end of file diff --git a/common/package.json b/common/package.json index ec5c34f7..8cb5b2bc 100644 --- a/common/package.json +++ b/common/package.json @@ -1,5 +1,5 @@ { - "name": "@sap/capire-common", + "name": "@capire/common", "version": "1.0.0", "description": "A reuse package providing common domain models and services for common data.", "repository": "https://github.com/SAP-samples/cloud-cap-samples.git", diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index dbb7f581..55d1b36b 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,13 +1,15 @@ -using AdminService from '@sap/capire-bookshop/srv/admin-service'; +using AdminService from '@capire/bookshop/srv/admin-service'; //////////////////////////////////////////////////////////////////////////// // // Books Object Page // + annotate AdminService.Books with @( UI: { Facets: [ {$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'}, + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Translations}', Target: 'texts/@UI.LineItem'}, {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, {$Type: 'UI.ReferenceFacet', Label: '{i18n>Admin}', Target: '@UI.FieldGroup#Admin'}, ], @@ -15,6 +17,7 @@ annotate AdminService.Books with @( Data: [ {Value: title}, {Value: author_ID}, + {Value: genre_ID}, {Value: descr}, ] }, @@ -35,3 +38,35 @@ annotate AdminService.Books with @( } } ); + + + +//////////////////////////////////////////////////////////// +// +// Draft for Localized Data +// + +annotate sap.capire.bookshop.Books with @fiori.draft.enabled; +annotate AdminService.Books with @odata.draft.enabled; + +annotate AdminService.Books_texts with @( + UI: { + Identification: [{Value:title}], + SelectionFields: [ locale, title ], + LineItem: [ + {Value: locale, Label: 'Locale'}, + {Value: title, Label: 'Title'}, + {Value: descr, Label: 'Description'}, + ] + } +); + +// Add Value Help for Locales +annotate AdminService.Books_texts { + locale @ValueList:{entity:'Languages',type:#fixed} +} +// In addition we need to expose Languages through AdminService +using { sap } from '@sap/cds/common'; +extend service AdminService { + entity Languages as projection on sap.common.Languages; +} diff --git a/fiori/app/browse/fiori-service.cds b/fiori/app/browse/fiori-service.cds index 712bca29..8f45518d 100644 --- a/fiori/app/browse/fiori-service.cds +++ b/fiori/app/browse/fiori-service.cds @@ -1,4 +1,4 @@ -using CatalogService from '@sap/capire-bookshop/srv/cat-service'; +using CatalogService from '@capire/bookshop/srv/cat-service'; //////////////////////////////////////////////////////////////////////////// // @@ -40,6 +40,7 @@ annotate CatalogService.Books with @( LineItem: [ {Value: title}, {Value: author, Label:'{i18n>Author}'}, + {Value: genre.name}, {Value: price}, {Value: currency.symbol, Label:' '}, ] diff --git a/fiori/app/common.cds b/fiori/app/common.cds index d82ed16b..ab1fdd7d 100644 --- a/fiori/app/common.cds +++ b/fiori/app/common.cds @@ -2,7 +2,7 @@ Common Annotations shared by all apps */ -using { sap.capire.bookshop as my } from '@sap/capire-bookshop/db/schema'; +using { sap.capire.bookshop as my } from '@capire/bookshop/db/schema'; //////////////////////////////////////////////////////////////////////////// @@ -17,6 +17,7 @@ annotate my.Books with @( {Value: ID}, {Value: title}, {Value: author.name, Label:'{i18n>Author}'}, + {Value: genre.name}, {Value: stock}, {Value: price}, {Value: currency.symbol, Label:' '}, @@ -57,12 +58,16 @@ annotate my.Books with @( annotate my.Books with { ID @title:'{i18n>ID}' @UI.HiddenFilter; title @title:'{i18n>Title}'; + genre @title:'{i18n>Genre}'; author @title:'{i18n>AuthorID}'; price @title:'{i18n>Price}'; stock @title:'{i18n>Stock}'; descr @UI.MultiLineText; } +annotate my.Genres with { + name @title: '{i18n>Genre}'; +} //////////////////////////////////////////////////////////////////////////// // diff --git a/fiori/app/index.cds b/fiori/app/index.cds index b457f478..379e55ab 100644 --- a/fiori/app/index.cds +++ b/fiori/app/index.cds @@ -7,4 +7,4 @@ using from './browse/fiori-service'; using from './orders/fiori-service'; using from './common'; -using from '@sap/capire-common'; +using from '@capire/common'; diff --git a/fiori/app/orders/fiori-service.cds b/fiori/app/orders/fiori-service.cds index 3733aa18..44612ee5 100644 --- a/fiori/app/orders/fiori-service.cds +++ b/fiori/app/orders/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '@sap/capire-bookshop/srv/admin-service'; +using AdminService from '@capire/bookshop/srv/admin-service'; annotate AdminService.Books with { price @Common.FieldControl: #ReadOnly; diff --git a/fiori/db/schema.cds b/fiori/db/schema.cds new file mode 100644 index 00000000..2a82f52e --- /dev/null +++ b/fiori/db/schema.cds @@ -0,0 +1,3 @@ +// Proxy for importing schema from bookshop sample +using from '@capire/bookshop/db/schema'; +namespace sap.capire.bookshop; diff --git a/fiori/package.json b/fiori/package.json index 950e0fc2..681e4551 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -1,11 +1,12 @@ { - "name": "@sap/capire-fiori", + "name": "@capire/fiori", "version": "1.0.0", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "license": "SAP SAMPLE CODE LICENSE", "dependencies": { - "@sap/capire-bookshop": "*", - "@sap/capire-common": "*", + "@capire/bookshop": "*", + "@capire/genres": "*", + "@capire/common": "*", "@sap/cds": "*", "express": "*" }, diff --git a/fiori/srv/admin-service.cds b/fiori/srv/admin-service.cds new file mode 100644 index 00000000..fceb9936 --- /dev/null +++ b/fiori/srv/admin-service.cds @@ -0,0 +1,5 @@ +// Proxy for importing services from bookshop sample +using from '@capire/bookshop/srv/admin-service'; +using from '@capire/bookshop/srv/cat-service'; + +annotate AdminService with @impl:'srv/admin-service.js'; diff --git a/fiori/srv/admin-service.js b/fiori/srv/admin-service.js new file mode 100644 index 00000000..e8853182 --- /dev/null +++ b/fiori/srv/admin-service.js @@ -0,0 +1,8 @@ +const cds = require('@sap/cds') + +module.exports = cds.service.impl (async function() { + const {Books} = cds.entities + const {ID} = await SELECT.one.from(Books).columns('max(ID) as ID') + let newID = ID - ID % 100 + 100 + this.before ('NEW','Books', req => req.data.ID = ++newID) +}) diff --git a/package.json b/package.json index e0d3a140..8495b2c0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@sap/capire-samples", + "name": "@capire/samples", "description": "The umbrella project for all samples to easily setup for local development and tests.", "repository": "https://github.com/SAP-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", @@ -8,8 +8,9 @@ "bookshop": "cds watch bookshop" }, "dependencies": { - "@sap/capire-bookshop": "./bookshop", - "@sap/capire-common": "./common" + "@capire/bookshop": "./bookshop", + "@capire/genres": "./genres", + "@capire/common": "./common" }, "--add-these-to-devDependencies-for-tests": { "@types/jest": "*", diff --git a/packages/reviews-service/db/schema.cds b/reviews/db/schema.cds similarity index 100% rename from packages/reviews-service/db/schema.cds rename to reviews/db/schema.cds diff --git a/packages/reviews-service/index.cds b/reviews/index.cds similarity index 100% rename from packages/reviews-service/index.cds rename to reviews/index.cds diff --git a/packages/reviews-service/package.json b/reviews/package.json similarity index 100% rename from packages/reviews-service/package.json rename to reviews/package.json diff --git a/packages/reviews-service/srv/reviews-service.cds b/reviews/srv/reviews-service.cds similarity index 100% rename from packages/reviews-service/srv/reviews-service.cds rename to reviews/srv/reviews-service.cds diff --git a/packages/reviews-service/srv/reviews-service.js b/reviews/srv/reviews-service.js similarity index 100% rename from packages/reviews-service/srv/reviews-service.js rename to reviews/srv/reviews-service.js diff --git a/packages/reviews-service/tests/messaging.test.js b/reviews/tests/messaging.test.js similarity index 100% rename from packages/reviews-service/tests/messaging.test.js rename to reviews/tests/messaging.test.js From 9921b2f3de314aa178f1617a476e9d92a1543355 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 01:22:59 +0100 Subject: [PATCH 05/29] . --- NOTICE | 1 - README.md | 73 ++++++------------- .../bookshop-enhanced/app/index.cds | 0 .../bookshop-enhanced/db/schema.cds | 0 .../bookshop-enhanced/package.json | 0 .../bookshop-enhanced/srv/services.cds | 0 .../bookshop-enhanced/srv/services.js | 0 .../bookshop-enhanced/tests/genres.http | 0 .../bookshop-enhanced/tests/reviews.http | 0 .../db/data/sap.capire.bookstore-Authors.csv | 0 .../data/sap.capire.products-Categories.csv | 0 .../db/data/sap.capire.products-Products.csv | 0 .../sap.capire.products-Products_texts.csv | 0 {_packages => _attic}/bookstore/db/schema.cds | 0 {_packages => _attic}/bookstore/package.json | 0 .../bookstore/srv/_workarounds.cds | 0 .../bookstore/srv/services.cds | 0 .../bookstore/srv/services.js | 0 .../bookstore/tests/books.cds | 0 .../bookstore/tests/localized-data.test.js | 0 .../common-contacts/db/code-lists.cds | 0 .../common-contacts/db/schema.cds | 0 .../common-contacts/index.cds | 0 .../common-contacts/package.json | 0 .../common-contacts/readme.md | 0 .../common-contacts/srv/code-lists.js | 0 .../common-contacts/tests/code-lists.test.js | 0 .../common-contacts/tests/index.cds | 0 .../media-server/db/data-model.cds | 0 {_packages => _attic}/media-server/index.cds | 0 .../media-server/package.json | 0 .../media-server/srv/media-service.cds | 0 .../media-server/srv/media-service.js | 0 .../db/data/sap.capire.orders-OrderItems.csv | 0 .../db/data/sap.capire.orders-Orders.csv | 0 .../orders-service/db/schema.cds | 0 .../orders-service/index.cds | 0 .../orders-service/package.json | 0 .../orders-service/srv/orders-service.cds | 0 .../products-service/db/schema.cds | 0 .../products-service/index.cds | 0 .../products-service/package.json | 0 .../products-service/srv/admin-service.cds | 0 .../products-service/tests/categories.test.js | 0 .../data/sap.capire.products-Categories.csv | 0 .../products-service/tests/postman.json | 0 {_packages => _attic}/users-service/index.cds | 0 .../users-service/package.json | 0 .../users-service/srv/services.cds | 0 bookshop/package.json | 6 +- bookshop/{test => tests}/genres.cds | 0 bookshop/{test => tests}/genres.http | 0 bookshop/{test => tests}/requests.http | 0 fiori/package.json | 5 +- package.json | 11 +-- reviews/package.json | 4 +- 56 files changed, 34 insertions(+), 66 deletions(-) delete mode 100644 NOTICE rename {_packages => _attic}/bookshop-enhanced/app/index.cds (100%) rename {_packages => _attic}/bookshop-enhanced/db/schema.cds (100%) rename {_packages => _attic}/bookshop-enhanced/package.json (100%) rename {_packages => _attic}/bookshop-enhanced/srv/services.cds (100%) rename {_packages => _attic}/bookshop-enhanced/srv/services.js (100%) rename {_packages => _attic}/bookshop-enhanced/tests/genres.http (100%) rename {_packages => _attic}/bookshop-enhanced/tests/reviews.http (100%) rename {_packages => _attic}/bookstore/db/data/sap.capire.bookstore-Authors.csv (100%) rename {_packages => _attic}/bookstore/db/data/sap.capire.products-Categories.csv (100%) rename {_packages => _attic}/bookstore/db/data/sap.capire.products-Products.csv (100%) rename {_packages => _attic}/bookstore/db/data/sap.capire.products-Products_texts.csv (100%) rename {_packages => _attic}/bookstore/db/schema.cds (100%) rename {_packages => _attic}/bookstore/package.json (100%) rename {_packages => _attic}/bookstore/srv/_workarounds.cds (100%) rename {_packages => _attic}/bookstore/srv/services.cds (100%) rename {_packages => _attic}/bookstore/srv/services.js (100%) rename {_packages => _attic}/bookstore/tests/books.cds (100%) rename {_packages => _attic}/bookstore/tests/localized-data.test.js (100%) rename {_packages => _attic}/common-contacts/db/code-lists.cds (100%) rename {_packages => _attic}/common-contacts/db/schema.cds (100%) rename {_packages => _attic}/common-contacts/index.cds (100%) rename {_packages => _attic}/common-contacts/package.json (100%) rename {_packages => _attic}/common-contacts/readme.md (100%) rename {_packages => _attic}/common-contacts/srv/code-lists.js (100%) rename {_packages => _attic}/common-contacts/tests/code-lists.test.js (100%) rename {_packages => _attic}/common-contacts/tests/index.cds (100%) rename {_packages => _attic}/media-server/db/data-model.cds (100%) rename {_packages => _attic}/media-server/index.cds (100%) rename {_packages => _attic}/media-server/package.json (100%) rename {_packages => _attic}/media-server/srv/media-service.cds (100%) rename {_packages => _attic}/media-server/srv/media-service.js (100%) rename {_packages => _attic}/orders-service/db/data/sap.capire.orders-OrderItems.csv (100%) rename {_packages => _attic}/orders-service/db/data/sap.capire.orders-Orders.csv (100%) rename {_packages => _attic}/orders-service/db/schema.cds (100%) rename {_packages => _attic}/orders-service/index.cds (100%) rename {_packages => _attic}/orders-service/package.json (100%) rename {_packages => _attic}/orders-service/srv/orders-service.cds (100%) rename {_packages => _attic}/products-service/db/schema.cds (100%) rename {_packages => _attic}/products-service/index.cds (100%) rename {_packages => _attic}/products-service/package.json (100%) rename {_packages => _attic}/products-service/srv/admin-service.cds (100%) rename {_packages => _attic}/products-service/tests/categories.test.js (100%) rename {_packages => _attic}/products-service/tests/data/sap.capire.products-Categories.csv (100%) rename {_packages => _attic}/products-service/tests/postman.json (100%) rename {_packages => _attic}/users-service/index.cds (100%) rename {_packages => _attic}/users-service/package.json (100%) rename {_packages => _attic}/users-service/srv/services.cds (100%) rename bookshop/{test => tests}/genres.cds (100%) rename bookshop/{test => tests}/genres.http (100%) rename bookshop/{test => tests}/requests.http (100%) diff --git a/NOTICE b/NOTICE deleted file mode 100644 index 21661b4c..00000000 --- a/NOTICE +++ /dev/null @@ -1 +0,0 @@ -Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. \ No newline at end of file diff --git a/README.md b/README.md index 035f076c..f72bd32f 100644 --- a/README.md +++ b/README.md @@ -1,71 +1,46 @@ -# cloud-cap-samples +# Welcome to cap/samples -This is a monorepository for sample projects on [SAP Cloud Application Programming Model](https://cap.cloud.sap). +Find here code samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) oganised in a simplistic monorepo. -## Description +## Preliminaries -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. - -The samples provided can be run in a local setup on SQLite Database. +- [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in capire -## 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) +## Download -#### 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) +Clone this repo as shown below, if you have [git](https://git-scm.com/downloads) installed, +otherwise [download as zip file](archive/master.zip). -## Download and Installation - -#### Install `cds` development kit ```sh -# `@sap`-scoped packages are set via .npmrc -npm install -g @sap/cds-dk -cds #> test-run it +git clone https://github.com/sap-samples/cap samples +cd samples ``` -Got issues? Check out the [documentation](https://cap.cloud.sap/docs/get-started/). -#### Clone and build the application -`git clone https://github.com/SAP-samples/cloud-cap-samples samples && cd samples && npm i` +## Setup -#### Run the samples +In the samples folder run: +```sh +npm install +``` -With that you're ready to run the samples, e.g. start the [_bookshop_](./packages/bookshop) sample as follows: +## Run -`npm run bookshop` +With that you're ready to run the samples, for example: +```sh +npm run bookshop # or... +npm run bookshop-fiori +``` -## Test - -For example, try these links in your browser: -- to test with generic index page. -- to test with Fiori sandbox. +After that open this link in your browser: -## Debug +## Get Support -For example, in [VS Code](https://code.visualstudio.com) switch to _Debug_ view and launch one of the prepared _cds run_ launch configurations. +Check out the cap docs at https://cap.cloud.sap.
+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 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. diff --git a/_packages/bookshop-enhanced/app/index.cds b/_attic/bookshop-enhanced/app/index.cds similarity index 100% rename from _packages/bookshop-enhanced/app/index.cds rename to _attic/bookshop-enhanced/app/index.cds diff --git a/_packages/bookshop-enhanced/db/schema.cds b/_attic/bookshop-enhanced/db/schema.cds similarity index 100% rename from _packages/bookshop-enhanced/db/schema.cds rename to _attic/bookshop-enhanced/db/schema.cds diff --git a/_packages/bookshop-enhanced/package.json b/_attic/bookshop-enhanced/package.json similarity index 100% rename from _packages/bookshop-enhanced/package.json rename to _attic/bookshop-enhanced/package.json diff --git a/_packages/bookshop-enhanced/srv/services.cds b/_attic/bookshop-enhanced/srv/services.cds similarity index 100% rename from _packages/bookshop-enhanced/srv/services.cds rename to _attic/bookshop-enhanced/srv/services.cds diff --git a/_packages/bookshop-enhanced/srv/services.js b/_attic/bookshop-enhanced/srv/services.js similarity index 100% rename from _packages/bookshop-enhanced/srv/services.js rename to _attic/bookshop-enhanced/srv/services.js diff --git a/_packages/bookshop-enhanced/tests/genres.http b/_attic/bookshop-enhanced/tests/genres.http similarity index 100% rename from _packages/bookshop-enhanced/tests/genres.http rename to _attic/bookshop-enhanced/tests/genres.http diff --git a/_packages/bookshop-enhanced/tests/reviews.http b/_attic/bookshop-enhanced/tests/reviews.http similarity index 100% rename from _packages/bookshop-enhanced/tests/reviews.http rename to _attic/bookshop-enhanced/tests/reviews.http diff --git a/_packages/bookstore/db/data/sap.capire.bookstore-Authors.csv b/_attic/bookstore/db/data/sap.capire.bookstore-Authors.csv similarity index 100% rename from _packages/bookstore/db/data/sap.capire.bookstore-Authors.csv rename to _attic/bookstore/db/data/sap.capire.bookstore-Authors.csv diff --git a/_packages/bookstore/db/data/sap.capire.products-Categories.csv b/_attic/bookstore/db/data/sap.capire.products-Categories.csv similarity index 100% rename from _packages/bookstore/db/data/sap.capire.products-Categories.csv rename to _attic/bookstore/db/data/sap.capire.products-Categories.csv diff --git a/_packages/bookstore/db/data/sap.capire.products-Products.csv b/_attic/bookstore/db/data/sap.capire.products-Products.csv similarity index 100% rename from _packages/bookstore/db/data/sap.capire.products-Products.csv rename to _attic/bookstore/db/data/sap.capire.products-Products.csv diff --git a/_packages/bookstore/db/data/sap.capire.products-Products_texts.csv b/_attic/bookstore/db/data/sap.capire.products-Products_texts.csv similarity index 100% rename from _packages/bookstore/db/data/sap.capire.products-Products_texts.csv rename to _attic/bookstore/db/data/sap.capire.products-Products_texts.csv diff --git a/_packages/bookstore/db/schema.cds b/_attic/bookstore/db/schema.cds similarity index 100% rename from _packages/bookstore/db/schema.cds rename to _attic/bookstore/db/schema.cds diff --git a/_packages/bookstore/package.json b/_attic/bookstore/package.json similarity index 100% rename from _packages/bookstore/package.json rename to _attic/bookstore/package.json diff --git a/_packages/bookstore/srv/_workarounds.cds b/_attic/bookstore/srv/_workarounds.cds similarity index 100% rename from _packages/bookstore/srv/_workarounds.cds rename to _attic/bookstore/srv/_workarounds.cds diff --git a/_packages/bookstore/srv/services.cds b/_attic/bookstore/srv/services.cds similarity index 100% rename from _packages/bookstore/srv/services.cds rename to _attic/bookstore/srv/services.cds diff --git a/_packages/bookstore/srv/services.js b/_attic/bookstore/srv/services.js similarity index 100% rename from _packages/bookstore/srv/services.js rename to _attic/bookstore/srv/services.js diff --git a/_packages/bookstore/tests/books.cds b/_attic/bookstore/tests/books.cds similarity index 100% rename from _packages/bookstore/tests/books.cds rename to _attic/bookstore/tests/books.cds diff --git a/_packages/bookstore/tests/localized-data.test.js b/_attic/bookstore/tests/localized-data.test.js similarity index 100% rename from _packages/bookstore/tests/localized-data.test.js rename to _attic/bookstore/tests/localized-data.test.js diff --git a/_packages/common-contacts/db/code-lists.cds b/_attic/common-contacts/db/code-lists.cds similarity index 100% rename from _packages/common-contacts/db/code-lists.cds rename to _attic/common-contacts/db/code-lists.cds diff --git a/_packages/common-contacts/db/schema.cds b/_attic/common-contacts/db/schema.cds similarity index 100% rename from _packages/common-contacts/db/schema.cds rename to _attic/common-contacts/db/schema.cds diff --git a/_packages/common-contacts/index.cds b/_attic/common-contacts/index.cds similarity index 100% rename from _packages/common-contacts/index.cds rename to _attic/common-contacts/index.cds diff --git a/_packages/common-contacts/package.json b/_attic/common-contacts/package.json similarity index 100% rename from _packages/common-contacts/package.json rename to _attic/common-contacts/package.json diff --git a/_packages/common-contacts/readme.md b/_attic/common-contacts/readme.md similarity index 100% rename from _packages/common-contacts/readme.md rename to _attic/common-contacts/readme.md diff --git a/_packages/common-contacts/srv/code-lists.js b/_attic/common-contacts/srv/code-lists.js similarity index 100% rename from _packages/common-contacts/srv/code-lists.js rename to _attic/common-contacts/srv/code-lists.js diff --git a/_packages/common-contacts/tests/code-lists.test.js b/_attic/common-contacts/tests/code-lists.test.js similarity index 100% rename from _packages/common-contacts/tests/code-lists.test.js rename to _attic/common-contacts/tests/code-lists.test.js diff --git a/_packages/common-contacts/tests/index.cds b/_attic/common-contacts/tests/index.cds similarity index 100% rename from _packages/common-contacts/tests/index.cds rename to _attic/common-contacts/tests/index.cds diff --git a/_packages/media-server/db/data-model.cds b/_attic/media-server/db/data-model.cds similarity index 100% rename from _packages/media-server/db/data-model.cds rename to _attic/media-server/db/data-model.cds diff --git a/_packages/media-server/index.cds b/_attic/media-server/index.cds similarity index 100% rename from _packages/media-server/index.cds rename to _attic/media-server/index.cds diff --git a/_packages/media-server/package.json b/_attic/media-server/package.json similarity index 100% rename from _packages/media-server/package.json rename to _attic/media-server/package.json diff --git a/_packages/media-server/srv/media-service.cds b/_attic/media-server/srv/media-service.cds similarity index 100% rename from _packages/media-server/srv/media-service.cds rename to _attic/media-server/srv/media-service.cds diff --git a/_packages/media-server/srv/media-service.js b/_attic/media-server/srv/media-service.js similarity index 100% rename from _packages/media-server/srv/media-service.js rename to _attic/media-server/srv/media-service.js diff --git a/_packages/orders-service/db/data/sap.capire.orders-OrderItems.csv b/_attic/orders-service/db/data/sap.capire.orders-OrderItems.csv similarity index 100% rename from _packages/orders-service/db/data/sap.capire.orders-OrderItems.csv rename to _attic/orders-service/db/data/sap.capire.orders-OrderItems.csv diff --git a/_packages/orders-service/db/data/sap.capire.orders-Orders.csv b/_attic/orders-service/db/data/sap.capire.orders-Orders.csv similarity index 100% rename from _packages/orders-service/db/data/sap.capire.orders-Orders.csv rename to _attic/orders-service/db/data/sap.capire.orders-Orders.csv diff --git a/_packages/orders-service/db/schema.cds b/_attic/orders-service/db/schema.cds similarity index 100% rename from _packages/orders-service/db/schema.cds rename to _attic/orders-service/db/schema.cds diff --git a/_packages/orders-service/index.cds b/_attic/orders-service/index.cds similarity index 100% rename from _packages/orders-service/index.cds rename to _attic/orders-service/index.cds diff --git a/_packages/orders-service/package.json b/_attic/orders-service/package.json similarity index 100% rename from _packages/orders-service/package.json rename to _attic/orders-service/package.json diff --git a/_packages/orders-service/srv/orders-service.cds b/_attic/orders-service/srv/orders-service.cds similarity index 100% rename from _packages/orders-service/srv/orders-service.cds rename to _attic/orders-service/srv/orders-service.cds diff --git a/_packages/products-service/db/schema.cds b/_attic/products-service/db/schema.cds similarity index 100% rename from _packages/products-service/db/schema.cds rename to _attic/products-service/db/schema.cds diff --git a/_packages/products-service/index.cds b/_attic/products-service/index.cds similarity index 100% rename from _packages/products-service/index.cds rename to _attic/products-service/index.cds diff --git a/_packages/products-service/package.json b/_attic/products-service/package.json similarity index 100% rename from _packages/products-service/package.json rename to _attic/products-service/package.json diff --git a/_packages/products-service/srv/admin-service.cds b/_attic/products-service/srv/admin-service.cds similarity index 100% rename from _packages/products-service/srv/admin-service.cds rename to _attic/products-service/srv/admin-service.cds diff --git a/_packages/products-service/tests/categories.test.js b/_attic/products-service/tests/categories.test.js similarity index 100% rename from _packages/products-service/tests/categories.test.js rename to _attic/products-service/tests/categories.test.js diff --git a/_packages/products-service/tests/data/sap.capire.products-Categories.csv b/_attic/products-service/tests/data/sap.capire.products-Categories.csv similarity index 100% rename from _packages/products-service/tests/data/sap.capire.products-Categories.csv rename to _attic/products-service/tests/data/sap.capire.products-Categories.csv diff --git a/_packages/products-service/tests/postman.json b/_attic/products-service/tests/postman.json similarity index 100% rename from _packages/products-service/tests/postman.json rename to _attic/products-service/tests/postman.json diff --git a/_packages/users-service/index.cds b/_attic/users-service/index.cds similarity index 100% rename from _packages/users-service/index.cds rename to _attic/users-service/index.cds diff --git a/_packages/users-service/package.json b/_attic/users-service/package.json similarity index 100% rename from _packages/users-service/package.json rename to _attic/users-service/package.json diff --git a/_packages/users-service/srv/services.cds b/_attic/users-service/srv/services.cds similarity index 100% rename from _packages/users-service/srv/services.cds rename to _attic/users-service/srv/services.cds diff --git a/bookshop/package.json b/bookshop/package.json index e874e8df..62543c2a 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -4,14 +4,12 @@ "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "license": "SAP SAMPLE CODE LICENSE", "dependencies": { - "@capire/common": "*", - "@sap/cds": "*", - "express": "*" + "@capire/common": "*" }, "scripts": { "start": "cds run --in-memory?", "watch": "cds watch", - "test:genres": "cds serve test/genres --in-memory" + "test:genres": "cds serve tests/genres.cds --in-memory" }, "cds": { "requires": { diff --git a/bookshop/test/genres.cds b/bookshop/tests/genres.cds similarity index 100% rename from bookshop/test/genres.cds rename to bookshop/tests/genres.cds diff --git a/bookshop/test/genres.http b/bookshop/tests/genres.http similarity index 100% rename from bookshop/test/genres.http rename to bookshop/tests/genres.http diff --git a/bookshop/test/requests.http b/bookshop/tests/requests.http similarity index 100% rename from bookshop/test/requests.http rename to bookshop/tests/requests.http diff --git a/fiori/package.json b/fiori/package.json index 681e4551..5924c98d 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -5,10 +5,7 @@ "license": "SAP SAMPLE CODE LICENSE", "dependencies": { "@capire/bookshop": "*", - "@capire/genres": "*", - "@capire/common": "*", - "@sap/cds": "*", - "express": "*" + "@capire/common": "*" }, "scripts": { "start": "cds run --in-memory?", diff --git a/package.json b/package.json index 8495b2c0..dfe31f95 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,15 @@ "author": "daniel.hutzel@sap.com", "private": true, "scripts": { - "bookshop": "cds watch bookshop" + "bookshop": "cds watch bookshop", + "bookshop-fiori": "cds watch fiori" }, "dependencies": { - "@capire/bookshop": "./bookshop", - "@capire/genres": "./genres", - "@capire/common": "./common" + "@capire/bookshop": "file:bookshop", + "@capire/common": "file:common", + "@capire/reviews": "file:reviews" }, - "--add-these-to-devDependencies-for-tests": { + "add-these-to-devDependencies-for-tests": { "@types/jest": "*", "jest": "*" }, diff --git a/reviews/package.json b/reviews/package.json index 990f4e35..4c7e6062 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -1,12 +1,10 @@ { - "name": "@sap/capire-reviews", + "name": "@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?", From cb066233c9e451964ae1c273fc7f6ed995aa3d87 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 02:43:15 +0100 Subject: [PATCH 06/29] reviews + events --- _attic/bookshop-enhanced/app/index.cds | 1 - _attic/bookshop-enhanced/db/schema.cds | 25 --- _attic/bookshop-enhanced/package.json | 29 --- _attic/bookshop-enhanced/srv/services.cds | 9 - _attic/bookshop-enhanced/tests/genres.http | 33 --- .../db/data/sap.capire.bookstore-Authors.csv | 5 - .../data/sap.capire.products-Categories.csv | 11 - .../db/data/sap.capire.products-Products.csv | 6 - .../sap.capire.products-Products_texts.csv | 4 - _attic/bookstore/db/schema.cds | 18 -- _attic/bookstore/package.json | 48 ----- _attic/bookstore/srv/_workarounds.cds | 12 -- _attic/bookstore/srv/services.cds | 35 ---- _attic/bookstore/srv/services.js | 38 ---- _attic/bookstore/tests/books.cds | 7 - _attic/bookstore/tests/localized-data.test.js | 190 ------------------ _attic/common-contacts/db/code-lists.cds | 28 --- _attic/common-contacts/db/schema.cds | 58 ------ _attic/common-contacts/index.cds | 2 - _attic/common-contacts/package.json | 10 - _attic/common-contacts/readme.md | 67 ------ _attic/common-contacts/srv/code-lists.js | 70 ------- .../common-contacts/tests/code-lists.test.js | 68 ------- _attic/common-contacts/tests/index.cds | 11 - .../db/data/sap.capire.orders-OrderItems.csv | 4 - .../db/data/sap.capire.orders-Orders.csv | 3 - _attic/orders-service/db/schema.cds | 15 -- _attic/orders-service/index.cds | 2 - _attic/orders-service/package.json | 11 - _attic/orders-service/srv/orders-service.cds | 6 - _attic/products-service/db/schema.cds | 18 -- _attic/products-service/index.cds | 2 - _attic/products-service/package.json | 16 -- _attic/products-service/srv/admin-service.cds | 7 - .../data/sap.capire.products-Categories.csv | 10 - _attic/products-service/tests/postman.json | 157 --------------- _attic/users-service/index.cds | 1 - _attic/users-service/package.json | 12 -- _attic/users-service/srv/services.cds | 7 - .../tests/genres.test.js | 30 +-- events/package.json | 21 ++ events/services.cds | 13 ++ .../srv => events}/services.js | 4 +- events/tests.http | 40 ++++ .../media-server => media}/db/data-model.cds | 0 {_attic/media-server => media}/index.cds | 0 {_attic/media-server => media}/package.json | 4 +- .../srv/media-service.cds | 0 .../srv/media-service.js | 0 package.json | 11 +- reviews/.env | 1 + .../tests/requests.http | 0 52 files changed, 103 insertions(+), 1077 deletions(-) delete mode 100644 _attic/bookshop-enhanced/app/index.cds delete mode 100644 _attic/bookshop-enhanced/db/schema.cds delete mode 100644 _attic/bookshop-enhanced/package.json delete mode 100644 _attic/bookshop-enhanced/srv/services.cds delete mode 100644 _attic/bookshop-enhanced/tests/genres.http delete mode 100644 _attic/bookstore/db/data/sap.capire.bookstore-Authors.csv delete mode 100644 _attic/bookstore/db/data/sap.capire.products-Categories.csv delete mode 100644 _attic/bookstore/db/data/sap.capire.products-Products.csv delete mode 100644 _attic/bookstore/db/data/sap.capire.products-Products_texts.csv delete mode 100644 _attic/bookstore/db/schema.cds delete mode 100644 _attic/bookstore/package.json delete mode 100644 _attic/bookstore/srv/_workarounds.cds delete mode 100644 _attic/bookstore/srv/services.cds delete mode 100644 _attic/bookstore/srv/services.js delete mode 100644 _attic/bookstore/tests/books.cds delete mode 100644 _attic/bookstore/tests/localized-data.test.js delete mode 100644 _attic/common-contacts/db/code-lists.cds delete mode 100644 _attic/common-contacts/db/schema.cds delete mode 100644 _attic/common-contacts/index.cds delete mode 100644 _attic/common-contacts/package.json delete mode 100644 _attic/common-contacts/readme.md delete mode 100644 _attic/common-contacts/srv/code-lists.js delete mode 100644 _attic/common-contacts/tests/code-lists.test.js delete mode 100644 _attic/common-contacts/tests/index.cds delete mode 100644 _attic/orders-service/db/data/sap.capire.orders-OrderItems.csv delete mode 100644 _attic/orders-service/db/data/sap.capire.orders-Orders.csv delete mode 100644 _attic/orders-service/db/schema.cds delete mode 100644 _attic/orders-service/index.cds delete mode 100644 _attic/orders-service/package.json delete mode 100644 _attic/orders-service/srv/orders-service.cds delete mode 100644 _attic/products-service/db/schema.cds delete mode 100644 _attic/products-service/index.cds delete mode 100644 _attic/products-service/package.json delete mode 100644 _attic/products-service/srv/admin-service.cds delete mode 100644 _attic/products-service/tests/data/sap.capire.products-Categories.csv delete mode 100644 _attic/products-service/tests/postman.json delete mode 100644 _attic/users-service/index.cds delete mode 100644 _attic/users-service/package.json delete mode 100644 _attic/users-service/srv/services.cds rename _attic/products-service/tests/categories.test.js => bookshop/tests/genres.test.js (66%) create mode 100644 events/package.json create mode 100644 events/services.cds rename {_attic/bookshop-enhanced/srv => events}/services.js (92%) create mode 100644 events/tests.http rename {_attic/media-server => media}/db/data-model.cds (100%) rename {_attic/media-server => media}/index.cds (100%) rename {_attic/media-server => media}/package.json (85%) rename {_attic/media-server => media}/srv/media-service.cds (100%) rename {_attic/media-server => media}/srv/media-service.js (100%) create mode 100644 reviews/.env rename _attic/bookshop-enhanced/tests/reviews.http => reviews/tests/requests.http (100%) diff --git a/_attic/bookshop-enhanced/app/index.cds b/_attic/bookshop-enhanced/app/index.cds deleted file mode 100644 index 1674468e..00000000 --- a/_attic/bookshop-enhanced/app/index.cds +++ /dev/null @@ -1 +0,0 @@ -using from '@sap/capire-bookshop/app'; diff --git a/_attic/bookshop-enhanced/db/schema.cds b/_attic/bookshop-enhanced/db/schema.cds deleted file mode 100644 index d6adb541..00000000 --- a/_attic/bookshop-enhanced/db/schema.cds +++ /dev/null @@ -1,25 +0,0 @@ -/* - 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; -} diff --git a/_attic/bookshop-enhanced/package.json b/_attic/bookshop-enhanced/package.json deleted file mode 100644 index 94c0ae7e..00000000 --- a/_attic/bookshop-enhanced/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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" - } - } - } -} diff --git a/_attic/bookshop-enhanced/srv/services.cds b/_attic/bookshop-enhanced/srv/services.cds deleted file mode 100644 index 7ff9f9af..00000000 --- a/_attic/bookshop-enhanced/srv/services.cds +++ /dev/null @@ -1,9 +0,0 @@ -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; -} diff --git a/_attic/bookshop-enhanced/tests/genres.http b/_attic/bookshop-enhanced/tests/genres.http deleted file mode 100644 index aecd8777..00000000 --- a/_attic/bookshop-enhanced/tests/genres.http +++ /dev/null @@ -1,33 +0,0 @@ -################################################# -# -# 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) -### diff --git a/_attic/bookstore/db/data/sap.capire.bookstore-Authors.csv b/_attic/bookstore/db/data/sap.capire.bookstore-Authors.csv deleted file mode 100644 index 8c2d2f71..00000000 --- a/_attic/bookstore/db/data/sap.capire.bookstore-Authors.csv +++ /dev/null @@ -1,5 +0,0 @@ -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 \ No newline at end of file diff --git a/_attic/bookstore/db/data/sap.capire.products-Categories.csv b/_attic/bookstore/db/data/sap.capire.products-Categories.csv deleted file mode 100644 index 331e8ba2..00000000 --- a/_attic/bookstore/db/data/sap.capire.products-Categories.csv +++ /dev/null @@ -1,11 +0,0 @@ -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 diff --git a/_attic/bookstore/db/data/sap.capire.products-Products.csv b/_attic/bookstore/db/data/sap.capire.products-Products.csv deleted file mode 100644 index ddbd0834..00000000 --- a/_attic/bookstore/db/data/sap.capire.products-Products.csv +++ /dev/null @@ -1,6 +0,0 @@ -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 \ No newline at end of file diff --git a/_attic/bookstore/db/data/sap.capire.products-Products_texts.csv b/_attic/bookstore/db/data/sap.capire.products-Products_texts.csv deleted file mode 100644 index fcd8a35e..00000000 --- a/_attic/bookstore/db/data/sap.capire.products-Products_texts.csv +++ /dev/null @@ -1,4 +0,0 @@ -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. \ No newline at end of file diff --git a/_attic/bookstore/db/schema.cds b/_attic/bookstore/db/schema.cds deleted file mode 100644 index 5f82d533..00000000 --- a/_attic/bookstore/db/schema.cds +++ /dev/null @@ -1,18 +0,0 @@ -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'; diff --git a/_attic/bookstore/package.json b/_attic/bookstore/package.json deleted file mode 100644 index 0f18561b..00000000 --- a/_attic/bookstore/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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" - } - } - } -} diff --git a/_attic/bookstore/srv/_workarounds.cds b/_attic/bookstore/srv/_workarounds.cds deleted file mode 100644 index 60cc099a..00000000 --- a/_attic/bookstore/srv/_workarounds.cds +++ /dev/null @@ -1,12 +0,0 @@ -//---------------------- -// 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; diff --git a/_attic/bookstore/srv/services.cds b/_attic/bookstore/srv/services.cds deleted file mode 100644 index b630ebe9..00000000 --- a/_attic/bookstore/srv/services.cds +++ /dev/null @@ -1,35 +0,0 @@ -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'; diff --git a/_attic/bookstore/srv/services.js b/_attic/bookstore/srv/services.js deleted file mode 100644 index 3b6430aa..00000000 --- a/_attic/bookstore/srv/services.js +++ /dev/null @@ -1,38 +0,0 @@ -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.transaction(msg) - 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' -}]) diff --git a/_attic/bookstore/tests/books.cds b/_attic/bookstore/tests/books.cds deleted file mode 100644 index 4c1309d9..00000000 --- a/_attic/bookstore/tests/books.cds +++ /dev/null @@ -1,7 +0,0 @@ -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'; diff --git a/_attic/bookstore/tests/localized-data.test.js b/_attic/bookstore/tests/localized-data.test.js deleted file mode 100644 index acf35d44..00000000 --- a/_attic/bookstore/tests/localized-data.test.js +++ /dev/null @@ -1,190 +0,0 @@ -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) - }) -}) diff --git a/_attic/common-contacts/db/code-lists.cds b/_attic/common-contacts/db/code-lists.cds deleted file mode 100644 index 1d31dc7a..00000000 --- a/_attic/common-contacts/db/code-lists.cds +++ /dev/null @@ -1,28 +0,0 @@ -using { sap } from '@sap/cds/common'; -namespace sap.common; - -/** - * 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; - */ - -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; -} diff --git a/_attic/common-contacts/db/schema.cds b/_attic/common-contacts/db/schema.cds deleted file mode 100644 index c9a7410f..00000000 --- a/_attic/common-contacts/db/schema.cds +++ /dev/null @@ -1,58 +0,0 @@ -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; - } diff --git a/_attic/common-contacts/index.cds b/_attic/common-contacts/index.cds deleted file mode 100644 index 0a1d479d..00000000 --- a/_attic/common-contacts/index.cds +++ /dev/null @@ -1,2 +0,0 @@ -using from './db/code-lists'; -using from './db/schema'; diff --git a/_attic/common-contacts/package.json b/_attic/common-contacts/package.json deleted file mode 100644 index 4221f4ab..00000000 --- a/_attic/common-contacts/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "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" - } -} \ No newline at end of file diff --git a/_attic/common-contacts/readme.md b/_attic/common-contacts/readme.md deleted file mode 100644 index 77ea0ed2..00000000 --- a/_attic/common-contacts/readme.md +++ /dev/null @@ -1,67 +0,0 @@ -# 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` diff --git a/_attic/common-contacts/srv/code-lists.js b/_attic/common-contacts/srv/code-lists.js deleted file mode 100644 index aac662b8..00000000 --- a/_attic/common-contacts/srv/code-lists.js +++ /dev/null @@ -1,70 +0,0 @@ -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 = {} diff --git a/_attic/common-contacts/tests/code-lists.test.js b/_attic/common-contacts/tests/code-lists.test.js deleted file mode 100644 index ee367abf..00000000 --- a/_attic/common-contacts/tests/code-lists.test.js +++ /dev/null @@ -1,68 +0,0 @@ -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! - -}) diff --git a/_attic/common-contacts/tests/index.cds b/_attic/common-contacts/tests/index.cds deleted file mode 100644 index 96adbe01..00000000 --- a/_attic/common-contacts/tests/index.cds +++ /dev/null @@ -1,11 +0,0 @@ -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; -} diff --git a/_attic/orders-service/db/data/sap.capire.orders-OrderItems.csv b/_attic/orders-service/db/data/sap.capire.orders-OrderItems.csv deleted file mode 100644 index 1b5ff074..00000000 --- a/_attic/orders-service/db/data/sap.capire.orders-OrderItems.csv +++ /dev/null @@ -1,4 +0,0 @@ -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 \ No newline at end of file diff --git a/_attic/orders-service/db/data/sap.capire.orders-Orders.csv b/_attic/orders-service/db/data/sap.capire.orders-Orders.csv deleted file mode 100644 index 143da2c3..00000000 --- a/_attic/orders-service/db/data/sap.capire.orders-Orders.csv +++ /dev/null @@ -1,3 +0,0 @@ -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 \ No newline at end of file diff --git a/_attic/orders-service/db/schema.cds b/_attic/orders-service/db/schema.cds deleted file mode 100644 index f7d7b4fc..00000000 --- a/_attic/orders-service/db/schema.cds +++ /dev/null @@ -1,15 +0,0 @@ -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; -} diff --git a/_attic/orders-service/index.cds b/_attic/orders-service/index.cds deleted file mode 100644 index 8e460ac4..00000000 --- a/_attic/orders-service/index.cds +++ /dev/null @@ -1,2 +0,0 @@ -namespace sap.capire.orders; -using from './srv/orders-service'; diff --git a/_attic/orders-service/package.json b/_attic/orders-service/package.json deleted file mode 100644 index f8341b12..00000000 --- a/_attic/orders-service/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "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": "*" - } -} diff --git a/_attic/orders-service/srv/orders-service.cds b/_attic/orders-service/srv/orders-service.cds deleted file mode 100644 index 766cc012..00000000 --- a/_attic/orders-service/srv/orders-service.cds +++ /dev/null @@ -1,6 +0,0 @@ -namespace sap.capire.orders; -using { sap.capire.orders as my } from '../db/schema'; - -service OrdersService { - entity Orders as projection on my.Orders; -} diff --git a/_attic/products-service/db/schema.cds b/_attic/products-service/db/schema.cds deleted file mode 100644 index 573e93ad..00000000 --- a/_attic/products-service/db/schema.cds +++ /dev/null @@ -1,18 +0,0 @@ -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; -} diff --git a/_attic/products-service/index.cds b/_attic/products-service/index.cds deleted file mode 100644 index 581fba09..00000000 --- a/_attic/products-service/index.cds +++ /dev/null @@ -1,2 +0,0 @@ -using from './db/schema'; -using from './srv/admin-service'; diff --git a/_attic/products-service/package.json b/_attic/products-service/package.json deleted file mode 100644 index 3415c423..00000000 --- a/_attic/products-service/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "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" - ] -} \ No newline at end of file diff --git a/_attic/products-service/srv/admin-service.cds b/_attic/products-service/srv/admin-service.cds deleted file mode 100644 index a7ebd575..00000000 --- a/_attic/products-service/srv/admin-service.cds +++ /dev/null @@ -1,7 +0,0 @@ -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; -} diff --git a/_attic/products-service/tests/data/sap.capire.products-Categories.csv b/_attic/products-service/tests/data/sap.capire.products-Categories.csv deleted file mode 100644 index 20183828..00000000 --- a/_attic/products-service/tests/data/sap.capire.products-Categories.csv +++ /dev/null @@ -1,10 +0,0 @@ -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 diff --git a/_attic/products-service/tests/postman.json b/_attic/products-service/tests/postman.json deleted file mode 100644 index 6fbc8a8c..00000000 --- a/_attic/products-service/tests/postman.json +++ /dev/null @@ -1,157 +0,0 @@ -{ - "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": [] - } - ] - -} \ No newline at end of file diff --git a/_attic/users-service/index.cds b/_attic/users-service/index.cds deleted file mode 100644 index 8b17f004..00000000 --- a/_attic/users-service/index.cds +++ /dev/null @@ -1 +0,0 @@ -using from './srv/services'; diff --git a/_attic/users-service/package.json b/_attic/users-service/package.json deleted file mode 100644 index e3f995b4..00000000 --- a/_attic/users-service/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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": "*" - } -} diff --git a/_attic/users-service/srv/services.cds b/_attic/users-service/srv/services.cds deleted file mode 100644 index 05e5b9ac..00000000 --- a/_attic/users-service/srv/services.cds +++ /dev/null @@ -1,7 +0,0 @@ -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 (); -} \ No newline at end of file diff --git a/_attic/products-service/tests/categories.test.js b/bookshop/tests/genres.test.js similarity index 66% rename from _attic/products-service/tests/categories.test.js rename to bookshop/tests/genres.test.js index 8e541a4b..c4d295f3 100644 --- a/_attic/products-service/tests/categories.test.js +++ b/bookshop/tests/genres.test.js @@ -1,16 +1,18 @@ const cds = require ('@sap/cds') +const { expect } = require('chai').use (require('chai-deep-match')) describe('reading/writing hierarchies', ()=>{ - it ('should prepare to sqlite in-memory', async()=>{ + it ('should bootstrap sqlite in-memory db', async()=>{ await cds.deploy (__dirname+'/../db') .to ('sqlite::memory:') - expect (cds.model) .toBeDefined() + expect (cds.db) .to.exist + expect (cds.db.model) .to.exist }) - it ('should insert hierarchy of categories', ()=>{ - const { Categories } = cds.entities - return INSERT.into (Categories) .entries ( - { ID:100, name:'Some Sample Categories...', children:[ + it ('should insert hierarchy of genres', ()=>{ + const { Genres } = cds.entities + return INSERT.into (Genres) .entries ( + { ID:100, name:'Some Sample Genres...', children:[ { ID:101, name:'Cat', children:[ { ID:102, name:'Kitty', children:[ { ID:103, name:'Kitty Cat', children:[ @@ -23,17 +25,17 @@ describe('reading/writing hierarchies', ()=>{ ) }) - it ('should read categories with children', async()=>{ - const { Categories } = cds.entities + it ('should read genres with children', async()=>{ + const { Genres } = cds.entities expect (await - SELECT.one.from (Categories, c=>{ + SELECT.one.from (Genres, c=>{ c.ID, c.name.as('parent'), c.children (c=>{ c.name.as('child') }) }) .where ({name:'Cat'}) - ) .toMatchObject ( + ) .to.deep.match ( { ID:101, parent:'Cat', children:[ { child:'Kitty' }, @@ -43,15 +45,15 @@ describe('reading/writing hierarchies', ()=>{ ) }) - it ('should read hierarchy of categories', async()=>{ - const { Categories } = cds.entities + it ('should read hierarchy of genres', async()=>{ + const { Genres } = cds.entities expect (await - SELECT.one.from (Categories, c=>{ + SELECT.one.from (Genres, c=>{ c.ID, c.name, c.children (c=>{ c.name },{levels:3}) }) .where ({name:'Cat'}) - ) .toMatchObject ( + ) .to.deep.match ( { ID:101, name:'Cat', children:[ { name:'Kitty', children:[ diff --git a/events/package.json b/events/package.json new file mode 100644 index 00000000..898be68e --- /dev/null +++ b/events/package.json @@ -0,0 +1,21 @@ +{ + "name": "@capire/bookshop-with-reviews", + "version": "1.0.0", + "dependencies": { + "@capire/bookshop": "*", + "@capire/reviews": "*" + }, + "cds": { + "requires": { + "db": { + "kind": "sql" + }, + "sap.capire.reviews.ReviewsService": { + "kind": "odata" + }, + "messaging": { + "kind": "file-based-messaging" + } + } + } +} \ No newline at end of file diff --git a/events/services.cds b/events/services.cds new file mode 100644 index 00000000..6cf3bd70 --- /dev/null +++ b/events/services.cds @@ -0,0 +1,13 @@ +namespace sap.capire.bookshop; +using { sap.capire.reviews.ReviewsService as external } from '@capire/reviews'; +using { sap.capire.bookshop.Books } from '@capire/bookshop/db/schema'; + +// Extending Books by Reviews +extend Books with { + reviews : Composition of many external.Reviews on reviews.subject = ID; + rating : external.Reviews.rating; +} + +using from '@capire/bookshop/srv/admin-service'; +using from '@capire/bookshop/srv/cat-service'; +annotate AdminService with @impl:'services.js'; diff --git a/_attic/bookshop-enhanced/srv/services.js b/events/services.js similarity index 92% rename from _attic/bookshop-enhanced/srv/services.js rename to events/services.js index 24503d49..261c3e9f 100644 --- a/_attic/bookshop-enhanced/srv/services.js +++ b/events/services.js @@ -2,15 +2,17 @@ const cds = require ('@sap/cds') module.exports = cds.service.impl (async()=>{ + // connect to requires services 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 + // delegate requests to read reviews to ReviewsService 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) diff --git a/events/tests.http b/events/tests.http new file mode 100644 index 00000000..1476f53f --- /dev/null +++ b/events/tests.http @@ -0,0 +1,40 @@ +################################################# +# +# Reviews Service +# + + +### 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 + + + +### ReviewsService mocked in same process +GET http://localhost:4004/reviews/Reviews? + +### +POST http://localhost:4004/reviews/Reviews +Content-Type: application/json;IEEE754Compatible=true + +{"subject":"201", "rating":"5", "title":"boo"} + + + + +### ReviewsService running as separate process +GET http://localhost:5005/reviews/Reviews? + +### +POST http://localhost:5005/reviews/Reviews +Content-Type: application/json;IEEE754Compatible=true + +{"subject":"201", "rating":"5", "title":"boo"} diff --git a/_attic/media-server/db/data-model.cds b/media/db/data-model.cds similarity index 100% rename from _attic/media-server/db/data-model.cds rename to media/db/data-model.cds diff --git a/_attic/media-server/index.cds b/media/index.cds similarity index 100% rename from _attic/media-server/index.cds rename to media/index.cds diff --git a/_attic/media-server/package.json b/media/package.json similarity index 85% rename from _attic/media-server/package.json rename to media/package.json index c144037d..9453255f 100644 --- a/_attic/media-server/package.json +++ b/media/package.json @@ -1,12 +1,10 @@ { - "name": "@sap/capire-media", + "name": "@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": "*", "lokijs": "^1.5.6" }, "files": [ diff --git a/_attic/media-server/srv/media-service.cds b/media/srv/media-service.cds similarity index 100% rename from _attic/media-server/srv/media-service.cds rename to media/srv/media-service.cds diff --git a/_attic/media-server/srv/media-service.js b/media/srv/media-service.js similarity index 100% rename from _attic/media-server/srv/media-service.js rename to media/srv/media-service.js diff --git a/package.json b/package.json index dfe31f95..bd5aeee5 100644 --- a/package.json +++ b/package.json @@ -5,17 +5,22 @@ "author": "daniel.hutzel@sap.com", "private": true, "scripts": { - "bookshop": "cds watch bookshop", - "bookshop-fiori": "cds watch fiori" + "bookshop-fiori": "cds watch fiori", + "bookshop": "cds watch bookshop" }, "dependencies": { "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", + "@capire/fiori": "file:fiori", "@capire/reviews": "file:reviews" }, "add-these-to-devDependencies-for-tests": { "@types/jest": "*", "jest": "*" }, - "license": "SAP SAMPLE CODE LICENSE" + "license": "SAP SAMPLE CODE LICENSE", + "devDependencies": { + "chai": "^4.2.0", + "chai-deep-match": "^1.2.1" + } } diff --git a/reviews/.env b/reviews/.env new file mode 100644 index 00000000..378d6075 --- /dev/null +++ b/reviews/.env @@ -0,0 +1 @@ +PORT = 5005 \ No newline at end of file diff --git a/_attic/bookshop-enhanced/tests/reviews.http b/reviews/tests/requests.http similarity index 100% rename from _attic/bookshop-enhanced/tests/reviews.http rename to reviews/tests/requests.http From c6eb21ec5127db4e99da5489b4a2b1bbf494deb8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 08:29:49 +0100 Subject: [PATCH 07/29] cleaned up --- .eslintrc | 2 +- .vscode/tasks.json | 17 -------- README.md | 4 +- bookshop/db/schema.cds | 16 +------- bookshop/package.json | 13 ++---- bookshop/srv/admin-service.cds | 1 - bookshop/srv/cat-service.cds | 5 +-- bookshop/srv/cat-service.js | 41 +++++++++---------- bookshop/tests/genres.test.js | 6 +-- bookshop/tests/requests.http | 38 +++++++++++++---- events/package.json | 3 ++ fiori/app/fiori.html | 2 +- fiori/app/orders/fiori-service.cds | 14 ++++--- fiori/app/orders/webapp/manifest.json | 10 ++--- fiori/package.json | 10 +---- fiori/srv/admin-service.cds | 2 - .../data/sap.capire.bookshop-OrderItems.csv | 0 .../db/data/sap.capire.bookshop-Orders.csv | 0 orders/db/schema.cds | 17 ++++++++ orders/package.json | 5 +++ orders/srv/orders-service.cds | 5 +++ orders/srv/orders-service.js | 21 ++++++++++ package.json | 18 ++++---- reviews/.env | 1 - reviews/db/schema.cds | 2 +- reviews/package.json | 9 ++-- 26 files changed, 140 insertions(+), 122 deletions(-) delete mode 100644 .vscode/tasks.json rename {bookshop => orders}/db/data/sap.capire.bookshop-OrderItems.csv (100%) rename {bookshop => orders}/db/data/sap.capire.bookshop-Orders.csv (100%) create mode 100644 orders/db/schema.cds create mode 100644 orders/package.json create mode 100644 orders/srv/orders-service.cds create mode 100644 orders/srv/orders-service.js delete mode 100644 reviews/.env diff --git a/.eslintrc b/.eslintrc index 7e6f79e2..052d4616 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,4 +21,4 @@ "no-console": "off", "require-atomic-updates": "off" } -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index c507ca84..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "type": "npm", "script": "watch", "path": "packages/bookshop/", - "options": { "env": { "PORT": "4004" }}, - "presentation": { "group": "A" } - }, - { - "type": "npm", "script": "watch", "path": "packages/reviews-service/", - "options": { "env": { "PORT": "5005" }}, - "presentation": { "group": "A" } - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index f72bd32f..e883a04d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Clone this repo as shown below, if you have [git](https://git-scm.com/downloads) otherwise [download as zip file](archive/master.zip). ```sh -git clone https://github.com/sap-samples/cap samples +git clone https://github.com/sap-samples/cloud-cap-samples samples cd samples ``` @@ -29,7 +29,7 @@ npm install With that you're ready to run the samples, for example: ```sh npm run bookshop # or... -npm run bookshop-fiori +cd bookshop; cds watch ``` After that open this link in your browser: diff --git a/bookshop/db/schema.cds b/bookshop/db/schema.cds index bb428f1d..23f00497 100644 --- a/bookshop/db/schema.cds +++ b/bookshop/db/schema.cds @@ -1,5 +1,6 @@ namespace sap.capire.bookshop; -using { Currency, managed, cuid, sap } from '@sap/cds/common'; +// using { Currency, managed, sap } from '@sap/cds/common'; +using { Currency, managed, sap } from '@capire/common'; entity Books : managed { key ID : Integer; @@ -27,16 +28,3 @@ entity Genres : sap.common.CodeList { parent : Association to Genres; children : Composition of many Genres on children.parent = $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 { - parent : Association to Orders; - book : Association to Books; - amount : Integer; - netAmount : Decimal(9,2); -} diff --git a/bookshop/package.json b/bookshop/package.json index 62543c2a..1e0a334d 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -2,20 +2,13 @@ "name": "@capire/bookshop", "version": "1.0.0", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", - "license": "SAP SAMPLE CODE LICENSE", "dependencies": { "@capire/common": "*" }, "scripts": { + "test:genres": "cds serve tests/genres.cds --in-memory", "start": "cds run --in-memory?", - "watch": "cds watch", - "test:genres": "cds serve tests/genres.cds --in-memory" + "watch": "cds watch" }, - "cds": { - "requires": { - "db": { - "kind": "sql" - } - } - } + "license": "SAP SAMPLE CODE LICENSE" } \ No newline at end of file diff --git a/bookshop/srv/admin-service.cds b/bookshop/srv/admin-service.cds index 10c0fef1..8bfc1371 100644 --- a/bookshop/srv/admin-service.cds +++ b/bookshop/srv/admin-service.cds @@ -3,5 +3,4 @@ using { sap.capire.bookshop as my } from '../db/schema'; service AdminService @(_requires:'authenticated-user') { entity Books as projection on my.Books; entity Authors as projection on my.Authors; - entity Orders as select from my.Orders; } diff --git a/bookshop/srv/cat-service.cds b/bookshop/srv/cat-service.cds index efe7b5d9..4654c158 100644 --- a/bookshop/srv/cat-service.cds +++ b/bookshop/srv/cat-service.cds @@ -1,13 +1,12 @@ using { sap.capire.bookshop as my } from '../db/schema'; -@path:'/browse' -service CatalogService { +service CatalogService @(path:'/browse') { @readonly entity Books as SELECT from my.Books {*, author.name as author } excluding { createdBy, modifiedBy }; @requires_: 'authenticated-user' - @insertonly entity Orders as projection on my.Orders; + action order (book : Books.ID, amount: Integer); } diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 8ee056a7..25819333 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -1,26 +1,23 @@ const cds = require('@sap/cds') -const { Books } = cds.entities /** Service implementation for CatalogService */ -module.exports = cds.service.impl(function() { - this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11)) - this.before ('CREATE', 'Orders', _reduceStock) +module.exports = cds.service.impl (function() { + + // Get entity definitions from reflected model + const { Books } = cds.entities + + // Add some discount for overstocked books + this.after ('READ', 'Books', each => { + if (each.stock > 111) each.title += ` -- 11% discount!` + }) + + // Reduce stock of ordered books if available stock suffices + this.on ('order', async (req) => { + const {UPDATE} = cds.ql(req), {book,amount} = req.data + const n = await UPDATE (Books, book) + .where ('stock >=', amount) + .set ('stock -=', amount) + n > 0 || req.error (409,`${amount} exceeds stock for book #${book}`) + }) + }) - -/** 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}` - ) - })) -} \ No newline at end of file diff --git a/bookshop/tests/genres.test.js b/bookshop/tests/genres.test.js index c4d295f3..a3030f57 100644 --- a/bookshop/tests/genres.test.js +++ b/bookshop/tests/genres.test.js @@ -1,5 +1,5 @@ const cds = require ('@sap/cds') -const { expect } = require('chai').use (require('chai-deep-match')) +const { expect } = require('chai') .use (require('chai-subset')) describe('reading/writing hierarchies', ()=>{ @@ -35,7 +35,7 @@ describe('reading/writing hierarchies', ()=>{ }) }) .where ({name:'Cat'}) - ) .to.deep.match ( + ) .to.containSubset ( { ID:101, parent:'Cat', children:[ { child:'Kitty' }, @@ -53,7 +53,7 @@ describe('reading/writing hierarchies', ()=>{ c.ID, c.name, c.children (c=>{ c.name },{levels:3}) }) .where ({name:'Cat'}) - ) .to.deep.match ( + ) .to.containSubset ( { ID:101, name:'Cat', children:[ { name:'Kitty', children:[ diff --git a/bookshop/tests/requests.http b/bookshop/tests/requests.http index 0d50023e..14416fbd 100644 --- a/bookshop/tests/requests.http +++ b/bookshop/tests/requests.http @@ -1,18 +1,40 @@ -### Service Document GET http://localhost:4004/browse +### -### Service $metadata document GET http://localhost:4004/browse/$metadata +### + -### Browsing Books GET http://localhost:4004/browse/Books? -# &$select=title,author -# &$expand=currency +&$select=title,stock +&$expand=currency +#> add @capire/common to see data for currencies # &sap-language=de +### + -### Browsing Authors GET http://localhost:4004/admin/Authors? # &$select=name,dateOfBirth,placeOfBirth -# &$expand=books($select=title;$expand=currency) +&$expand=books($select=title;$expand=currency) +#> add @capire/common to see data for currencies # &$filter=ID eq 101 -# &sap-language=de +&sap-language=de +### + + +POST http://localhost:4004/browse/order +# Run that three times to get out-of-stock message +Content-Type: application/json + +{ "book":201, "amount":5 } +### + + + +GET http://localhost:4004/browse/Genres? +### + +GET http://localhost:4004/browse/Genres? +&$filter=parent_ID eq null&$select=name +&$expand=children($select=name) +### diff --git a/events/package.json b/events/package.json index 898be68e..55c4f202 100644 --- a/events/package.json +++ b/events/package.json @@ -5,6 +5,9 @@ "@capire/bookshop": "*", "@capire/reviews": "*" }, + "scripts": { + "watch": "cds watch" + }, "cds": { "requires": { "db": { diff --git a/fiori/app/fiori.html b/fiori/app/fiori.html index 2fc2a0d4..26182c12 100644 --- a/fiori/app/fiori.html +++ b/fiori/app/fiori.html @@ -28,7 +28,7 @@ navigationMode: "embedded" }, "manage-orders": { - title: "Manage Orders", + title: "Order Books", description: "... testing FE v42", additionalInformation: "SAPUI5.Component=orders", applicationType : "URL", diff --git a/fiori/app/orders/fiori-service.cds b/fiori/app/orders/fiori-service.cds index 44612ee5..cced0972 100644 --- a/fiori/app/orders/fiori-service.cds +++ b/fiori/app/orders/fiori-service.cds @@ -1,13 +1,15 @@ -using AdminService from '@capire/bookshop/srv/admin-service'; +using OrdersService from '@capire/orders/srv/orders-service'; -annotate AdminService.Books with { +annotate OrdersService.Books with { price @Common.FieldControl: #ReadOnly; } + + //////////////////////////////////////////////////////////////////////////// // // Common // -annotate AdminService.OrderItems with { +annotate OrdersService.OrderItems with { book @( Common: { Text: book.title, @@ -22,7 +24,7 @@ annotate AdminService.OrderItems with { @odata.draft.enabled -annotate AdminService.Orders with @( +annotate OrdersService.Orders with @( UI: { //////////////////////////////////////////////////////////////////////////// // @@ -83,9 +85,9 @@ annotate AdminService.Orders with @( -//The enity types name is AdminService.my_bookshop_OrderItems +//The enity types name is OrdersService.my_bookshop_OrderItems //The annotations below are not generated in edmx WHY? -annotate AdminService.OrderItems with @( +annotate OrdersService.OrderItems with @( UI: { HeaderInfo: { TypeName: 'Order Item', TypeNamePlural: ' ', diff --git a/fiori/app/orders/webapp/manifest.json b/fiori/app/orders/webapp/manifest.json index e33eb24b..ce659ec2 100644 --- a/fiori/app/orders/webapp/manifest.json +++ b/fiori/app/orders/webapp/manifest.json @@ -3,12 +3,12 @@ "sap.app": { "id": "orders", "type": "application", - "title": "Manage Orders", + "title": "Order Books", "description": "Sample Application", "i18n": "i18n/i18n.properties", "dataSources": { - "AdminService": { - "uri": "/admin/", + "OrdersService": { + "uri": "/orders/", "type": "OData", "settings": { "odataVersion": "4.0" @@ -33,7 +33,7 @@ "uri": "i18n/i18n.properties" }, "": { - "dataSource": "AdminService", + "dataSource": "OrdersService", "settings": { "synchronizationMode": "None", "operationMode": "Server", @@ -140,7 +140,7 @@ } } } - } + } }, "AuthorsDetails": { "type": "Component", diff --git a/fiori/package.json b/fiori/package.json index 5924c98d..84da4ecb 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -2,20 +2,14 @@ "name": "@capire/fiori", "version": "1.0.0", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", - "license": "SAP SAMPLE CODE LICENSE", "dependencies": { "@capire/bookshop": "*", + "@capire/orders": "*", "@capire/common": "*" }, "scripts": { "start": "cds run --in-memory?", "watch": "cds watch" }, - "cds": { - "requires": { - "db": { - "kind": "sql" - } - } - } + "license": "SAP SAMPLE CODE LICENSE" } \ No newline at end of file diff --git a/fiori/srv/admin-service.cds b/fiori/srv/admin-service.cds index fceb9936..83bc3a9c 100644 --- a/fiori/srv/admin-service.cds +++ b/fiori/srv/admin-service.cds @@ -1,5 +1,3 @@ // Proxy for importing services from bookshop sample using from '@capire/bookshop/srv/admin-service'; -using from '@capire/bookshop/srv/cat-service'; - annotate AdminService with @impl:'srv/admin-service.js'; diff --git a/bookshop/db/data/sap.capire.bookshop-OrderItems.csv b/orders/db/data/sap.capire.bookshop-OrderItems.csv similarity index 100% rename from bookshop/db/data/sap.capire.bookshop-OrderItems.csv rename to orders/db/data/sap.capire.bookshop-OrderItems.csv diff --git a/bookshop/db/data/sap.capire.bookshop-Orders.csv b/orders/db/data/sap.capire.bookshop-Orders.csv similarity index 100% rename from bookshop/db/data/sap.capire.bookshop-Orders.csv rename to orders/db/data/sap.capire.bookshop-Orders.csv diff --git a/orders/db/schema.cds b/orders/db/schema.cds new file mode 100644 index 00000000..f64b307a --- /dev/null +++ b/orders/db/schema.cds @@ -0,0 +1,17 @@ +using { sap.capire.bookshop.Books } from '@capire/bookshop/db/schema'; +using { Currency, managed, cuid } from '@sap/cds/common'; +namespace sap.capire.bookshop; + +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 { + parent : Association to Orders; + book : Association to Books; + amount : Integer; + netAmount : Decimal(9,2); +} diff --git a/orders/package.json b/orders/package.json new file mode 100644 index 00000000..f8d2c6c6 --- /dev/null +++ b/orders/package.json @@ -0,0 +1,5 @@ +{ + "name": "@capire/orders", + "version": "1.0.0", + "license": "SAP SAMPLE CODE LICENSE" +} \ No newline at end of file diff --git a/orders/srv/orders-service.cds b/orders/srv/orders-service.cds new file mode 100644 index 00000000..249bcca4 --- /dev/null +++ b/orders/srv/orders-service.cds @@ -0,0 +1,5 @@ +using { sap.capire.bookshop as my } from '../db/schema'; + +service OrdersService { + entity Orders as projection on my.Orders; +} diff --git a/orders/srv/orders-service.js b/orders/srv/orders-service.js new file mode 100644 index 00000000..55d0e1ba --- /dev/null +++ b/orders/srv/orders-service.js @@ -0,0 +1,21 @@ +const cds = require('@sap/cds') + +module.exports = cds.service.impl(function() { + + const { Books } = cds.entities + + // Reduce stock of ordered books if available stock suffices + this.before ('CREATE', 'Orders', (req) => { + const { Items: OrderItems } = req.data + return cds.transaction(req) .run (()=> OrderItems.map (order => + UPDATE (Books) .where ('ID =', order.book_ID) + .and ('stock >=', order.amount) + .set ('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}` + ) + })) + }) + +}) diff --git a/package.json b/package.json index bd5aeee5..76386cd0 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,22 @@ { "name": "@capire/samples", "description": "The umbrella project for all samples to easily setup for local development and tests.", - "repository": "https://github.com/SAP-samples/cloud-cap-samples.git", + "repository": "https://github.com/sap-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", - "private": true, "scripts": { - "bookshop-fiori": "cds watch fiori", - "bookshop": "cds watch bookshop" + "bookshop": "cds watch fiori" }, "dependencies": { "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", "@capire/fiori": "file:fiori", + "@capire/orders": "file:orders", "@capire/reviews": "file:reviews" }, - "add-these-to-devDependencies-for-tests": { - "@types/jest": "*", - "jest": "*" - }, - "license": "SAP SAMPLE CODE LICENSE", "devDependencies": { "chai": "^4.2.0", - "chai-deep-match": "^1.2.1" - } + "chai-subset": "^1.6.0" + }, + "license": "SAP SAMPLE CODE LICENSE", + "private": true } diff --git a/reviews/.env b/reviews/.env deleted file mode 100644 index 378d6075..00000000 --- a/reviews/.env +++ /dev/null @@ -1 +0,0 @@ -PORT = 5005 \ No newline at end of file diff --git a/reviews/db/schema.cds b/reviews/db/schema.cds index 9b07b02b..0183a8fd 100644 --- a/reviews/db/schema.cds +++ b/reviews/db/schema.cds @@ -28,4 +28,4 @@ type Rating : Decimal(3,2) enum { entity Likes { key review : Association to Reviews; key user : User; -} \ No newline at end of file +} diff --git a/reviews/package.json b/reviews/package.json index 4c7e6062..bb996e51 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -4,17 +4,14 @@ "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": { - }, - "scripts": { - "start": "cds run --in-memory?", - "watch": "cds watch" - }, "files": [ "db", "srv", "index.cds" ], + "scripts": { + "watch": "PORT=5005 cds watch" + }, "cds": { "requires": { "db": { From 125cb6e5c24d82a631efe3264c6edcc1c434e6f6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 08:35:31 +0100 Subject: [PATCH 08/29] Added hello world --- hello/package.json | 20 ++++++++++++++++++++ hello/test.http | 1 + hello/world.cds | 3 +++ hello/world.js | 3 +++ reviews/package.json | 4 ++-- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 hello/package.json create mode 100644 hello/test.http create mode 100644 hello/world.cds create mode 100644 hello/world.js diff --git a/hello/package.json b/hello/package.json new file mode 100644 index 00000000..3282f8bf --- /dev/null +++ b/hello/package.json @@ -0,0 +1,20 @@ +{ + "name": "@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", + "scripts": { + "watch": "cds serve world.cds" + }, + "cds": { + "requires": { + "db": { + "kind": "sql" + }, + "messaging": { + "kind": "file-based-messaging" + } + } + }, + "license": "SAP SAMPLE CODE LICENSE" +} \ No newline at end of file diff --git a/hello/test.http b/hello/test.http new file mode 100644 index 00000000..e3ab0a6f --- /dev/null +++ b/hello/test.http @@ -0,0 +1 @@ +GET http://localhost:4004/say/hello(to='world') diff --git a/hello/world.cds b/hello/world.cds new file mode 100644 index 00000000..54bf59fa --- /dev/null +++ b/hello/world.cds @@ -0,0 +1,3 @@ +service say { + function hello (to:String) returns String; +} diff --git a/hello/world.js b/hello/world.js new file mode 100644 index 00000000..ff1a370e --- /dev/null +++ b/hello/world.js @@ -0,0 +1,3 @@ +module.exports = class say { + hello(req) { return `Hello ${req.data.to}!` } +} diff --git a/reviews/package.json b/reviews/package.json index bb996e51..d1142aad 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -3,7 +3,6 @@ "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", "files": [ "db", "srv", @@ -21,5 +20,6 @@ "kind": "file-based-messaging" } } - } + }, + "license": "SAP SAMPLE CODE LICENSE" } \ No newline at end of file From ddb25d5ff58f8802276b3e55cbfc4fa682aa6449 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 08:45:39 +0100 Subject: [PATCH 09/29] cleaned up package.jsons --- README.md | 4 ++-- bookshop/package.json | 8 ++------ common/package.json | 5 +---- fiori/package.json | 4 +--- hello/package.json | 17 ++--------------- media/package.json | 3 --- orders/package.json | 3 +-- package.json | 10 ++++------ reviews/package.json | 5 +---- 9 files changed, 14 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index e883a04d..835c7ff8 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ npm install With that you're ready to run the samples, for example: ```sh -npm run bookshop # or... -cd bookshop; cds watch +cd bookshop +cds watch ``` After that open this link in your browser: diff --git a/bookshop/package.json b/bookshop/package.json index 1e0a334d..f8d6f799 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -1,14 +1,10 @@ { "name": "@capire/bookshop", "version": "1.0.0", - "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", - "dependencies": { - "@capire/common": "*" - }, + "description": "A simple self-contained bookshop service.", "scripts": { "test:genres": "cds serve tests/genres.cds --in-memory", "start": "cds run --in-memory?", "watch": "cds watch" - }, - "license": "SAP SAMPLE CODE LICENSE" + } } \ No newline at end of file diff --git a/common/package.json b/common/package.json index 8cb5b2bc..d5c6dc24 100644 --- a/common/package.json +++ b/common/package.json @@ -1,7 +1,4 @@ { "name": "@capire/common", - "version": "1.0.0", - "description": "A reuse package providing common domain models and services for common data.", - "repository": "https://github.com/SAP-samples/cloud-cap-samples.git", - "license": "SAP SAMPLE CODE LICENSE" + "version": "1.0.0" } diff --git a/fiori/package.json b/fiori/package.json index 84da4ecb..29b65631 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -1,7 +1,6 @@ { "name": "@capire/fiori", "version": "1.0.0", - "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "dependencies": { "@capire/bookshop": "*", "@capire/orders": "*", @@ -10,6 +9,5 @@ "scripts": { "start": "cds run --in-memory?", "watch": "cds watch" - }, - "license": "SAP SAMPLE CODE LICENSE" + } } \ No newline at end of file diff --git a/hello/package.json b/hello/package.json index 3282f8bf..ef9c6602 100644 --- a/hello/package.json +++ b/hello/package.json @@ -1,20 +1,7 @@ { - "name": "@capire/reviews", + "name": "@capire/hello-world", "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", "scripts": { "watch": "cds serve world.cds" - }, - "cds": { - "requires": { - "db": { - "kind": "sql" - }, - "messaging": { - "kind": "file-based-messaging" - } - } - }, - "license": "SAP SAMPLE CODE LICENSE" + } } \ No newline at end of file diff --git a/media/package.json b/media/package.json index 9453255f..8fb8100a 100644 --- a/media/package.json +++ b/media/package.json @@ -1,9 +1,6 @@ { "name": "@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": { "lokijs": "^1.5.6" }, diff --git a/orders/package.json b/orders/package.json index f8d2c6c6..242aefc4 100644 --- a/orders/package.json +++ b/orders/package.json @@ -1,5 +1,4 @@ { "name": "@capire/orders", - "version": "1.0.0", - "license": "SAP SAMPLE CODE LICENSE" + "version": "1.0.0" } \ No newline at end of file diff --git a/package.json b/package.json index 76386cd0..be257a94 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,14 @@ { "name": "@capire/samples", - "description": "The umbrella project for all samples to easily setup for local development and tests.", + "description": "A monorepo with several samples for CAP.", "repository": "https://github.com/sap-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", - "scripts": { - "bookshop": "cds watch fiori" - }, "dependencies": { "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", + "@capire/events": "file:events", "@capire/fiori": "file:fiori", + "@capire/media": "file:media", "@capire/orders": "file:orders", "@capire/reviews": "file:reviews" }, @@ -17,6 +16,5 @@ "chai": "^4.2.0", "chai-subset": "^1.6.0" }, - "license": "SAP SAMPLE CODE LICENSE", - "private": true + "license": "SAP SAMPLE CODE LICENSE" } diff --git a/reviews/package.json b/reviews/package.json index d1142aad..74ba2373 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -1,8 +1,6 @@ { "name": "@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", "files": [ "db", "srv", @@ -20,6 +18,5 @@ "kind": "file-based-messaging" } } - }, - "license": "SAP SAMPLE CODE LICENSE" + } } \ No newline at end of file From 946331168a4e0a84bafbbade847233e06fd4d3fa Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 08:48:36 +0100 Subject: [PATCH 10/29] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 835c7ff8..d6128544 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Find here code samples for the [SAP Cloud Application Programming Model](https:/ ## Preliminaries -- [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in capire +- [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in [capire](https://cap.cloud.sap) ## Download From 8429bdc9a3a28c5a86eb0cbd3ba3c236594c2589 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 10:24:33 +0100 Subject: [PATCH 11/29] Added samples overview --- README.md | 6 ++- {events => reviewed}/package.json | 0 {events => reviewed}/services.cds | 0 {events => reviewed}/services.js | 0 {events => reviewed}/tests.http | 0 samples.md | 73 +++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 2 deletions(-) rename {events => reviewed}/package.json (100%) rename {events => reviewed}/services.cds (100%) rename {events => reviewed}/services.js (100%) rename {events => reviewed}/tests.http (100%) create mode 100644 samples.md diff --git a/README.md b/README.md index d6128544..035f62cd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # Welcome to cap/samples -Find here code samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) oganised in a simplistic monorepo. +Find here a collection of samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) oganised in a simplistic [monorepo setup](samples.md#all-in-one-monorepo). → See [**Overview** of contained samples](samples.md) + ## Preliminaries -- [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in [capire](https://cap.cloud.sap) +1. [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in [capire](https://cap.cloud.sap) +2. _Optional:_ [Use Visual Studio Code](https://cap.cloud.sap/docs/get-started/in-vscode) ## Download diff --git a/events/package.json b/reviewed/package.json similarity index 100% rename from events/package.json rename to reviewed/package.json diff --git a/events/services.cds b/reviewed/services.cds similarity index 100% rename from events/services.cds rename to reviewed/services.cds diff --git a/events/services.js b/reviewed/services.js similarity index 100% rename from events/services.js rename to reviewed/services.js diff --git a/events/tests.http b/reviewed/tests.http similarity index 100% rename from events/tests.http rename to reviewed/tests.http diff --git a/samples.md b/samples.md new file mode 100644 index 00000000..7bd1ee81 --- /dev/null +++ b/samples.md @@ -0,0 +1,73 @@ +# Overview of Samples + +The list below gives an overview of the samples provided in subdirectories. +Each sub directory essentially is a individual npm package arranged in an [all-in-one monorepo](all-in-one-monorepo) umbrella setup. + + +## [hello](hello) + +- A simplistic [Hello World](https://cap.cloud.sap/docs/get-started/hello-world) service using [CDS](https://cap.cloud.sap/docs/cds/) and [cds.services](https://cap.cloud.sap/docs/node.js/api#services-api). + + +## [bookshop](bookshop) + +- [Getting Started](https://cap.cloud.sap/docs/get-started/in-a-nutshell) with CAP, briefly introducing: +- [Project Setup](https://cap.cloud.sap/docs/get-started/) and [Layouts](https://cap.cloud.sap/docs/get-started/projects) +- [Domain Modelling](https://cap.cloud.sap/docs/guides/domain-models) +- [Defining Services](https://cap.cloud.sap/docs/guides/providing-services) +- [Generic Providers](https://cap.cloud.sap/docs/guides/generic-providers) +- [Adding Custom Logic](https://cap.cloud.sap/docs/guides/service-impl) +- [Using Databases](https://cap.cloud.sap/docs/guides/databases) + + +## [common](common) + +- Showcases how to extend [@sap/cds/common](https://cap.cloud.sap/docs/cds/common) thereby covering... +- Building [extension packages](https://cap.cloud.sap/docs/guides/domain-models#aspects-extensibility) +- Providing [reuse packages](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content) +- [Verticalization](https://cap.cloud.sap/docs/cds/common#adapting-to-your-needs) +- Using [Aspects](https://cap.cloud.sap/docs/cds/cdl#aspects) +- Used in the [fiori app sample](#fiori) + + +## [orders](orders) + +- Adds orders to the [bookshop](#bookshop), thereby demonstrating... +- Using [Compositions](https://cap.cloud.sap/docs/cds/cdl#compositions) in [Domain Models](https://cap.cloud.sap/docs/guides/domain-models), along with +- [Serving deeply nested documents](https://cap.cloud.sap/docs/guides/generic-providers#serving-structured-data) + + +## [reviews](reviews) + +- Shows how to implement a modular service to manage product reviews, including... +- Serving requests synchronously +- Emitting events asynchronously +- As well as managed data, input validations and authorization + + +## [reviewed](reviewed) + +- Enhances [bookshop](#bookshop) with [reviews](#reviews), thereby showcasing... +- Consuming other services synchronously +- As well as asynchronously, subscribing to events +- Grow as you go, with... +- Mocking app services +- Running service meshes +- Late-cut Micro Services + + +## [fiori](fiori) + +- [Adds a Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/), introducing to... +- [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files +- Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft) +- Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help) +- Serving Fiori apps locally +- Combining most of the other samples through [package reuse](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content) + + +
+ +# All-in-one Monorepo + +Each sample sub directory essentially is a standard npm package, some with standard npm dependencies to other samples. The root folder's [package.json](package.json) has local links to the sub folders, such that an `npm install` populates a local `node_modules` folder acts like a local npm registry to the individual sample packages. From 2744fe1d9cdb1e9e315c7254a20675851efad117 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 10:38:31 +0100 Subject: [PATCH 12/29] fixed copy error --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index be257a94..c28bec6b 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,11 @@ "dependencies": { "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", - "@capire/events": "file:events", "@capire/fiori": "file:fiori", "@capire/media": "file:media", "@capire/orders": "file:orders", - "@capire/reviews": "file:reviews" + "@capire/reviews": "file:reviews", + "@capire/bookshop-with-reviews": "file:reviewed" }, "devDependencies": { "chai": "^4.2.0", From 2a78b8fb6413e2616ea238b56498d5085b287084 Mon Sep 17 00:00:00 2001 From: "Dr. David Kunz" Date: Mon, 2 Mar 2020 14:54:56 +0100 Subject: [PATCH 13/29] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 035f62cd..0c98ba24 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Welcome to cap/samples -Find here a collection of samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) oganised in a simplistic [monorepo setup](samples.md#all-in-one-monorepo). → See [**Overview** of contained samples](samples.md) +Find here a collection of samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) organised in a simplistic [monorepo setup](samples.md#all-in-one-monorepo). → See [**Overview** of contained samples](samples.md) ## Preliminaries From 93579f83f2c569c05f0051ca276be63e2b5c191a Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 18:33:30 +0100 Subject: [PATCH 14/29] fixed git clone link --- README.md | 3 ++- reviewed/tests.http | 4 ++-- reviews/srv/reviews-service.js | 4 ++++ reviews/tests/requests.http | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 035f62cd..bf6dc1fd 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ Clone this repo as shown below, if you have [git](https://git-scm.com/downloads) otherwise [download as zip file](archive/master.zip). ```sh -git clone https://github.com/sap-samples/cloud-cap-samples samples +# git clone https://github.com/sap-samples/cloud-cap-samples samples +git clone https://github.com/SAP-samples/cloud-cap-samples -b cap-samples-reloaded samples cd samples ``` diff --git a/reviewed/tests.http b/reviewed/tests.http index 1476f53f..d1c89504 100644 --- a/reviewed/tests.http +++ b/reviewed/tests.http @@ -25,7 +25,7 @@ GET http://localhost:4004/reviews/Reviews? POST http://localhost:4004/reviews/Reviews Content-Type: application/json;IEEE754Compatible=true -{"subject":"201", "rating":"5", "title":"boo"} +{"subject":"201", "title":"boo"} @@ -37,4 +37,4 @@ GET http://localhost:5005/reviews/Reviews? POST http://localhost:5005/reviews/Reviews Content-Type: application/json;IEEE754Compatible=true -{"subject":"201", "rating":"5", "title":"boo"} +{"subject":"201", "title":"boo"} diff --git a/reviews/srv/reviews-service.js b/reviews/srv/reviews-service.js index ae24ebba..c798ec0c 100644 --- a/reviews/srv/reviews-service.js +++ b/reviews/srv/reviews-service.js @@ -5,6 +5,10 @@ module.exports = cds.service.impl (function(){ // ( Note: we explicitly specify the namespace to support embedded reuse ) const { Reviews, Likes } = this.entities ('sap.capire.reviews') + this.before (['CREATE','UPDATE','DELETE'], 'Reviews', req => { + if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 + }) + // 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) => { diff --git a/reviews/tests/requests.http b/reviews/tests/requests.http index 21206196..564c8789 100644 --- a/reviews/tests/requests.http +++ b/reviews/tests/requests.http @@ -10,7 +10,7 @@ POST http://localhost:5005/reviews/Reviews # POST http://localhost:4004/reviews/Reviews Content-Type: application/json;IEEE754Compatible=true -{"subject":"201", "rating":"5", "title":"boo"} +{"subject":"201", "rating":"4", "title":"boo"} ### Direct Request to ReviewsService # Note: use 5005 instead of 4004 in case of separate service From 531b6cbf690934ce4759d495c25c8142856c537a Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Mar 2020 18:49:39 +0100 Subject: [PATCH 15/29] Fixed package dependencies --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c28bec6b..00841793 100644 --- a/package.json +++ b/package.json @@ -4,17 +4,20 @@ "repository": "https://github.com/sap-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", "dependencies": { + "@capire/bookshop-with-reviews": "file:reviewed", "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", "@capire/fiori": "file:fiori", "@capire/media": "file:media", "@capire/orders": "file:orders", "@capire/reviews": "file:reviews", - "@capire/bookshop-with-reviews": "file:reviewed" + "@sap/cds": "^3.31.1", + "express": "^4.17.1" }, "devDependencies": { "chai": "^4.2.0", "chai-subset": "^1.6.0" }, - "license": "SAP SAMPLE CODE LICENSE" + "license": "SAP SAMPLE CODE LICENSE", + "private": true } From ea010077161427ffda7c909e12065978399390ca Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Mar 2020 09:08:11 +0100 Subject: [PATCH 16/29] Fixed tests and prepared for mocha --- bookshop/{tests => test}/genres.cds | 0 bookshop/{tests => test}/genres.http | 0 bookshop/{tests => test}/genres.test.js | 0 bookshop/{tests => test}/requests.http | 0 reviews/srv/reviews-service.js | 6 +++--- reviews/{tests => test}/messaging.test.js | 18 ++++++++---------- reviews/{tests => test}/requests.http | 0 7 files changed, 11 insertions(+), 13 deletions(-) rename bookshop/{tests => test}/genres.cds (100%) rename bookshop/{tests => test}/genres.http (100%) rename bookshop/{tests => test}/genres.test.js (100%) rename bookshop/{tests => test}/requests.http (100%) rename reviews/{tests => test}/messaging.test.js (80%) rename reviews/{tests => test}/requests.http (100%) diff --git a/bookshop/tests/genres.cds b/bookshop/test/genres.cds similarity index 100% rename from bookshop/tests/genres.cds rename to bookshop/test/genres.cds diff --git a/bookshop/tests/genres.http b/bookshop/test/genres.http similarity index 100% rename from bookshop/tests/genres.http rename to bookshop/test/genres.http diff --git a/bookshop/tests/genres.test.js b/bookshop/test/genres.test.js similarity index 100% rename from bookshop/tests/genres.test.js rename to bookshop/test/genres.test.js diff --git a/bookshop/tests/requests.http b/bookshop/test/requests.http similarity index 100% rename from bookshop/tests/requests.http rename to bookshop/test/requests.http diff --git a/reviews/srv/reviews-service.js b/reviews/srv/reviews-service.js index c798ec0c..2e347a93 100644 --- a/reviews/srv/reviews-service.js +++ b/reviews/srv/reviews-service.js @@ -5,9 +5,9 @@ module.exports = cds.service.impl (function(){ // ( Note: we explicitly specify the namespace to support embedded reuse ) const { Reviews, Likes } = this.entities ('sap.capire.reviews') - this.before (['CREATE','UPDATE','DELETE'], 'Reviews', req => { - if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 - }) + // this.before (['CREATE','UPDATE'], 'Reviews', req => { + // if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 + // }) // 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 ) diff --git a/reviews/tests/messaging.test.js b/reviews/test/messaging.test.js similarity index 80% rename from reviews/tests/messaging.test.js rename to reviews/test/messaging.test.js index a814a79d..55e758ac 100644 --- a/reviews/tests/messaging.test.js +++ b/reviews/test/messaging.test.js @@ -1,17 +1,18 @@ const _model = __dirname+'/..' const cds = require ('@sap/cds') +const {expect} = require('chai').use(require('chai-subset')) describe('messaging tests', ()=>{ it ('should bootstrap sqlite in-memory db', async()=>{ const db = await cds.deploy (_model) .to ('sqlite::memory:') - expect (db.model) .toBeDefined() + expect (db.model) .not.undefined }) let srv it ('should serve reviews services', async()=>{ srv = await cds.serve('ReviewsService') .from (_model) - expect (srv.name) .toMatch ('ReviewsService') + expect (srv.name) .to.match (/ReviewsService/) }) let N=0, received=[], M=0 @@ -24,12 +25,9 @@ describe('messaging tests', ()=>{ }) 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 review = { subject: "201", title: "Captivating", rating: ++N } const response = await srv.create ('Reviews') .entries (review) - expect (response) .toMatchObject (review) + expect (response) .to.containSubset (review) },100) it ('should add more reviews', ()=> Promise.all ([ @@ -56,9 +54,9 @@ describe('messaging tests', ()=>{ 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([ + expect(M).equals(N) + expect(received.length).equals(N) + expect(received.map(m=>m.data)).to.deep.equal([ { subject: '201', rating: 1 }, { subject: '201', rating: 1.5 }, { subject: '201', rating: 2 }, diff --git a/reviews/tests/requests.http b/reviews/test/requests.http similarity index 100% rename from reviews/tests/requests.http rename to reviews/test/requests.http From 8c9e8a08dd406d6f8a58dbc46136d93de049a52f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Mar 2020 07:52:46 +0100 Subject: [PATCH 17/29] Added recommended extensions for vscode --- .vscode/extensions.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..438b613e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,18 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + // "CDS Editor !", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "mechatroner.rainbow-csv", + "humao.rest-client", + "alexcvzz.vscode-sqlite" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + + ] +} \ No newline at end of file From 737027ded453f37ecb530e2a4d734c06f5e4b000 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 12:41:28 +0100 Subject: [PATCH 18/29] automonous package.jsons --- bookshop/package.json | 15 +++++++++++++-- fiori/package.json | 4 +++- package.json | 4 +--- reviews/package.json | 7 ++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bookshop/package.json b/bookshop/package.json index f8d6f799..9d7831b9 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -2,9 +2,20 @@ "name": "@capire/bookshop", "version": "1.0.0", "description": "A simple self-contained bookshop service.", + "dependencies": { + "@sap/cds": "^3.31.1", + "express": "^4.17.1" + }, "scripts": { - "test:genres": "cds serve tests/genres.cds --in-memory", - "start": "cds run --in-memory?", + "genres": "cds serve test/genres.cds", + "start": "cds run", "watch": "cds watch" + }, + "cds": { + "requires": { + "db": { + "kind": "sql" + } + } } } \ No newline at end of file diff --git a/fiori/package.json b/fiori/package.json index 29b65631..f1728b20 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -4,7 +4,9 @@ "dependencies": { "@capire/bookshop": "*", "@capire/orders": "*", - "@capire/common": "*" + "@capire/common": "*", + "@sap/cds": "^3.31.1", + "express": "^4.17.1" }, "scripts": { "start": "cds run --in-memory?", diff --git a/package.json b/package.json index 00841793..867f3cbc 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,7 @@ "@capire/fiori": "file:fiori", "@capire/media": "file:media", "@capire/orders": "file:orders", - "@capire/reviews": "file:reviews", - "@sap/cds": "^3.31.1", - "express": "^4.17.1" + "@capire/reviews": "file:reviews" }, "devDependencies": { "chai": "^4.2.0", diff --git a/reviews/package.json b/reviews/package.json index 74ba2373..e4f73789 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -6,8 +6,13 @@ "srv", "index.cds" ], + "dependencies": { + "@sap/cds": "^3.31.1", + "express": "^4.17.1" + }, "scripts": { - "watch": "PORT=5005 cds watch" + "reviews-service": "PORT=5005 cds watch", + "bookshop": "cds watch test/bookshop" }, "cds": { "requires": { From 84a815e7e6d5d4bdc7bbd669bdf5f956601ef97a Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 12:42:26 +0100 Subject: [PATCH 19/29] Added reviews/test/bookshop --- reviewed/services.cds | 13 ------ reviewed/tests.http | 40 ------------------- reviews/srv/reviews-service.cds | 1 - reviews/srv/reviews-service.js | 8 ++-- .../test/bookshop}/package.json | 9 ++--- reviews/test/bookshop/schema.cds | 13 ++++++ .../test/bookshop/server.js | 29 ++++++++------ reviews/test/messaging.test.js | 2 +- reviews/test/requests.http | 40 +++++++++++-------- samples.md | 10 +---- 10 files changed, 64 insertions(+), 101 deletions(-) delete mode 100644 reviewed/services.cds delete mode 100644 reviewed/tests.http rename {reviewed => reviews/test/bookshop}/package.json (72%) create mode 100644 reviews/test/bookshop/schema.cds rename reviewed/services.js => reviews/test/bookshop/server.js (83%) diff --git a/reviewed/services.cds b/reviewed/services.cds deleted file mode 100644 index 6cf3bd70..00000000 --- a/reviewed/services.cds +++ /dev/null @@ -1,13 +0,0 @@ -namespace sap.capire.bookshop; -using { sap.capire.reviews.ReviewsService as external } from '@capire/reviews'; -using { sap.capire.bookshop.Books } from '@capire/bookshop/db/schema'; - -// Extending Books by Reviews -extend Books with { - reviews : Composition of many external.Reviews on reviews.subject = ID; - rating : external.Reviews.rating; -} - -using from '@capire/bookshop/srv/admin-service'; -using from '@capire/bookshop/srv/cat-service'; -annotate AdminService with @impl:'services.js'; diff --git a/reviewed/tests.http b/reviewed/tests.http deleted file mode 100644 index d1c89504..00000000 --- a/reviewed/tests.http +++ /dev/null @@ -1,40 +0,0 @@ -################################################# -# -# Reviews Service -# - - -### 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 - - - -### ReviewsService mocked in same process -GET http://localhost:4004/reviews/Reviews? - -### -POST http://localhost:4004/reviews/Reviews -Content-Type: application/json;IEEE754Compatible=true - -{"subject":"201", "title":"boo"} - - - - -### ReviewsService running as separate process -GET http://localhost:5005/reviews/Reviews? - -### -POST http://localhost:5005/reviews/Reviews -Content-Type: application/json;IEEE754Compatible=true - -{"subject":"201", "title":"boo"} diff --git a/reviews/srv/reviews-service.cds b/reviews/srv/reviews-service.cds index 9634c183..dafcb0d1 100644 --- a/reviews/srv/reviews-service.cds +++ b/reviews/srv/reviews-service.cds @@ -1,5 +1,4 @@ using { sap.capire.reviews as my } from '../db/schema'; -namespace sap.capire.reviews; service ReviewsService { // Sync API diff --git a/reviews/srv/reviews-service.js b/reviews/srv/reviews-service.js index 2e347a93..33f383d9 100644 --- a/reviews/srv/reviews-service.js +++ b/reviews/srv/reviews-service.js @@ -5,9 +5,9 @@ module.exports = cds.service.impl (function(){ // ( Note: we explicitly specify the namespace to support embedded reuse ) const { Reviews, Likes } = this.entities ('sap.capire.reviews') - // this.before (['CREATE','UPDATE'], 'Reviews', req => { - // if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 - // }) + this.before (['CREATE','UPDATE'], 'Reviews', req => { + if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 + }) // 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 ) @@ -17,7 +17,7 @@ module.exports = cds.service.impl (function(){ SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject}) ) req.on ('succeeded', ()=>{ - console.log ('< emitting:', 'reviewed', { subject, rating }) + global.it || console.log ('< emitting:', 'reviewed', { subject, rating }) this.emit ('reviewed', { subject, rating }) }) }) diff --git a/reviewed/package.json b/reviews/test/bookshop/package.json similarity index 72% rename from reviewed/package.json rename to reviews/test/bookshop/package.json index 55c4f202..f24f3233 100644 --- a/reviewed/package.json +++ b/reviews/test/bookshop/package.json @@ -3,17 +3,16 @@ "version": "1.0.0", "dependencies": { "@capire/bookshop": "*", - "@capire/reviews": "*" - }, - "scripts": { - "watch": "cds watch" + "@capire/reviews": "*", + "@sap/cds": "^3.31.1", + "express": "^4.17.1" }, "cds": { "requires": { "db": { "kind": "sql" }, - "sap.capire.reviews.ReviewsService": { + "ReviewsService": { "kind": "odata" }, "messaging": { diff --git a/reviews/test/bookshop/schema.cds b/reviews/test/bookshop/schema.cds new file mode 100644 index 00000000..39fdfb35 --- /dev/null +++ b/reviews/test/bookshop/schema.cds @@ -0,0 +1,13 @@ +// +// Extending Books with Reviews +// + +using { sap.capire.bookshop.Books } from '@capire/bookshop'; +using { ReviewsService.Reviews } from '@capire/reviews'; + +extend Books with { + /** Access to detailed collection of Reviews */ + reviews : Composition of many Reviews on reviews.subject = $self.ID; + /** Average rating */ + rating : Reviews.rating; +} diff --git a/reviewed/services.js b/reviews/test/bookshop/server.js similarity index 83% rename from reviewed/services.js rename to reviews/test/bookshop/server.js index 261c3e9f..540c6d65 100644 --- a/reviewed/services.js +++ b/reviews/test/bookshop/server.js @@ -1,24 +1,15 @@ const cds = require ('@sap/cds') -module.exports = cds.service.impl (async()=>{ +cds.on('listening', async()=>{ - // connect to requires services - const ReviewsService = await cds.connect.to ('sap.capire.reviews.ReviewsService') + // connect to requires services + const ReviewsService = await cds.connect.to ('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 - - // delegate requests to read reviews to ReviewsService - CatalogService.impl (srv => { - srv.on ('READ', 'Books/reviews', (req) => { - const [ subject ] = req.params - const tx = ReviewsService.transaction (req) - return tx.run (SELECT.from (Reviews) .where ({subject})) - }) - }) + const { Books } = db.entities // react on event messages from reviews service ReviewsService.on ('reviewed', (msg) => { @@ -29,4 +20,16 @@ module.exports = cds.service.impl (async()=>{ // return tx.update (Books, subject) .with ({rating}) }) + console.log (Reviews.name) + // delegate requests to read reviews to ReviewsService + CatalogService.impl (srv => { + srv.on ('READ', 'Books/reviews', (req) => { + const [ subject ] = req.params + const tx = ReviewsService.transaction (req) + return tx.run (SELECT.from (Reviews) .where ({subject})) + }) + }) + }) + +module.exports = cds.server diff --git a/reviews/test/messaging.test.js b/reviews/test/messaging.test.js index 55e758ac..d1ace70a 100644 --- a/reviews/test/messaging.test.js +++ b/reviews/test/messaging.test.js @@ -1,6 +1,6 @@ const _model = __dirname+'/..' const cds = require ('@sap/cds') -const {expect} = require('chai').use(require('chai-subset')) +const {expect} = cds.require.chai describe('messaging tests', ()=>{ diff --git a/reviews/test/requests.http b/reviews/test/requests.http index 564c8789..d1c89504 100644 --- a/reviews/test/requests.http +++ b/reviews/test/requests.http @@ -4,21 +4,6 @@ # -### 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":"4", "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 @@ -28,5 +13,28 @@ GET http://localhost:4004/browse/Books/201/reviews ### GET http://localhost:4004/browse/Books(201)? &$select=ID,title,rating -# &$expand=reviews +&$expand=reviews # Note: the latter only works in case of ReviewsService in same process + + + +### ReviewsService mocked in same process +GET http://localhost:4004/reviews/Reviews? + +### +POST http://localhost:4004/reviews/Reviews +Content-Type: application/json;IEEE754Compatible=true + +{"subject":"201", "title":"boo"} + + + + +### ReviewsService running as separate process +GET http://localhost:5005/reviews/Reviews? + +### +POST http://localhost:5005/reviews/Reviews +Content-Type: application/json;IEEE754Compatible=true + +{"subject":"201", "title":"boo"} diff --git a/samples.md b/samples.md index 7bd1ee81..efa74a61 100644 --- a/samples.md +++ b/samples.md @@ -40,20 +40,14 @@ Each sub directory essentially is a individual npm package arranged in an [all-i ## [reviews](reviews) - Shows how to implement a modular service to manage product reviews, including... +- Consuming other services synchronously and asynchronously - Serving requests synchronously - Emitting events asynchronously -- As well as managed data, input validations and authorization - - -## [reviewed](reviewed) - -- Enhances [bookshop](#bookshop) with [reviews](#reviews), thereby showcasing... -- Consuming other services synchronously -- As well as asynchronously, subscribing to events - Grow as you go, with... - Mocking app services - Running service meshes - Late-cut Micro Services +- As well as managed data, input validations and authorization ## [fiori](fiori) From 48fa640f5b9d30aeebf169d1cfa9926f7e5624ae Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 12:42:33 +0100 Subject: [PATCH 20/29] cleanup --- bookshop/db/schema.cds | 4 ++-- bookshop/index.cds | 3 +++ bookshop/index.js | 1 + bookshop/readme.md | 31 ++++++++++++++++++++++++++++++ bookshop/test/genres.test.js | 2 +- fiori/app/admin/fiori-service.cds | 2 +- fiori/app/browse/fiori-service.cds | 2 +- fiori/app/common.cds | 2 +- fiori/db/schema.cds | 2 +- fiori/srv/admin-service.cds | 2 +- orders/db/schema.cds | 2 +- reviews/readme.md | 21 ++++++++++++++++++++ 12 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 bookshop/index.cds create mode 100644 bookshop/index.js create mode 100644 bookshop/readme.md create mode 100644 reviews/readme.md diff --git a/bookshop/db/schema.cds b/bookshop/db/schema.cds index 23f00497..aaef9ee6 100644 --- a/bookshop/db/schema.cds +++ b/bookshop/db/schema.cds @@ -1,6 +1,6 @@ namespace sap.capire.bookshop; -// using { Currency, managed, sap } from '@sap/cds/common'; -using { Currency, managed, sap } from '@capire/common'; +using { Currency, managed, sap } from '@sap/cds/common'; +// using { Currency, managed, sap } from '@capire/commorn'; entity Books : managed { key ID : Integer; diff --git a/bookshop/index.cds b/bookshop/index.cds new file mode 100644 index 00000000..98605e0b --- /dev/null +++ b/bookshop/index.cds @@ -0,0 +1,3 @@ +using from './db/schema'; +using from './srv/cat-service'; +using from './srv/admin-service'; diff --git a/bookshop/index.js b/bookshop/index.js new file mode 100644 index 00000000..0f7a3ffa --- /dev/null +++ b/bookshop/index.js @@ -0,0 +1 @@ +exports.CatalogService = require('./srv/cat-service') diff --git a/bookshop/readme.md b/bookshop/readme.md new file mode 100644 index 00000000..7bc3af7e --- /dev/null +++ b/bookshop/readme.md @@ -0,0 +1,31 @@ +# Bookshop Getting Started Sample + +This sample introduces the essential tasks in the development of CAP-based services as also covered in the [Getting Started guide in capire](https://cap.cloud.sap/docs/get-started/in-a-nutshell). + +## Hypothetical Use Cases + +1. Build a service that allows to browse _Books_ and _Authors_. +2. Books have assigned _Genres_ which are organized hierarchically. +3. All users may browse books without login. +4. All entries are maintained by Administrators. +5. End users may order books (the actual order mgmt being out of scope) + +## Running the Sample + +```sh +npm run watch +``` + +## Content & Best Practices + +| Links to capire | Sample files / folders | +| --------------------------------------------------------------------------------------------------------- | ------------------------------------ | +| [Project Setup and Layouts](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content) | [`./`](./) | +| [Defining Domain Models](https://cap.cloud.sap/docs/guides/domain-models) | [`./db/schema.cds`](./db/schema.cds) | +| [Defining Services](https://cap.cloud.sap/docs/guides/providing-services) | [`./srv/*.cds`](./srv) | +| [Single-purposed Services](https://cap.cloud.sap/docs/guides/providing-services#single-purposed-services) | [`./srv/*.cds`](./srv) | +| [Generic Providers](https://cap.cloud.sap/docs/guides/generic-providers) | http://localhost:4004 | +| [Using Databases](https://cap.cloud.sap/docs/guides/databases) | [`./db/data/*.csv`](./db/data) | +| [Adding Custom Logic](https://cap.cloud.sap/docs/guides/service-impl) | [`./srv/*.js`](./srv) | +| [Adding Tests](https://cap.cloud.sap/docs/guides/testing) | [`./test`](./test) | +| [Sharing for Reuse](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content) | [`./index.cds`](./index.cds) | diff --git a/bookshop/test/genres.test.js b/bookshop/test/genres.test.js index a3030f57..42fe52af 100644 --- a/bookshop/test/genres.test.js +++ b/bookshop/test/genres.test.js @@ -1,5 +1,5 @@ const cds = require ('@sap/cds') -const { expect } = require('chai') .use (require('chai-subset')) +const {expect} = cds.require.chai describe('reading/writing hierarchies', ()=>{ diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index 55d1b36b..1aeddb9f 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '@capire/bookshop/srv/admin-service'; +using AdminService from '@capire/bookshop'; //////////////////////////////////////////////////////////////////////////// // diff --git a/fiori/app/browse/fiori-service.cds b/fiori/app/browse/fiori-service.cds index 8f45518d..4f947fd4 100644 --- a/fiori/app/browse/fiori-service.cds +++ b/fiori/app/browse/fiori-service.cds @@ -1,4 +1,4 @@ -using CatalogService from '@capire/bookshop/srv/cat-service'; +using CatalogService from '@capire/bookshop'; //////////////////////////////////////////////////////////////////////////// // diff --git a/fiori/app/common.cds b/fiori/app/common.cds index ab1fdd7d..4baf92ca 100644 --- a/fiori/app/common.cds +++ b/fiori/app/common.cds @@ -2,7 +2,7 @@ Common Annotations shared by all apps */ -using { sap.capire.bookshop as my } from '@capire/bookshop/db/schema'; +using { sap.capire.bookshop as my } from '@capire/bookshop'; //////////////////////////////////////////////////////////////////////////// diff --git a/fiori/db/schema.cds b/fiori/db/schema.cds index 2a82f52e..5d4e2e82 100644 --- a/fiori/db/schema.cds +++ b/fiori/db/schema.cds @@ -1,3 +1,3 @@ // Proxy for importing schema from bookshop sample -using from '@capire/bookshop/db/schema'; +using from '@capire/bookshop'; namespace sap.capire.bookshop; diff --git a/fiori/srv/admin-service.cds b/fiori/srv/admin-service.cds index 83bc3a9c..eb518438 100644 --- a/fiori/srv/admin-service.cds +++ b/fiori/srv/admin-service.cds @@ -1,3 +1,3 @@ // Proxy for importing services from bookshop sample -using from '@capire/bookshop/srv/admin-service'; +using from '@capire/bookshop'; annotate AdminService with @impl:'srv/admin-service.js'; diff --git a/orders/db/schema.cds b/orders/db/schema.cds index f64b307a..bcb34f3a 100644 --- a/orders/db/schema.cds +++ b/orders/db/schema.cds @@ -1,4 +1,4 @@ -using { sap.capire.bookshop.Books } from '@capire/bookshop/db/schema'; +using { sap.capire.bookshop.Books } from '@capire/bookshop'; using { Currency, managed, cuid } from '@sap/cds/common'; namespace sap.capire.bookshop; diff --git a/reviews/readme.md b/reviews/readme.md new file mode 100644 index 00000000..5574f752 --- /dev/null +++ b/reviews/readme.md @@ -0,0 +1,21 @@ +# Reviews Service Sample + +## Run all-in-one + +Open a terminal window and run the bookshop in it: +```sh +npm run bookshop +``` + + +## Run as separate services + +Open two terminal windows, and in the first one start the reviews service stand-alone: +```sh +npm run reviews-service +``` + +In the the second one start the bookshop: +```sh +npm run bookshop +``` From d8d3b579290ea07c92ea66d1983849fd190907e6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 14:01:47 +0100 Subject: [PATCH 21/29] Adjusted launch cinfigs for vscode --- .vscode/launch.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c810af37..bdca8db5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ { "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}/${input:sample}", "console": "integratedTerminal", "skipFiles": ["/**"] } @@ -22,14 +22,13 @@ "inputs": [ { "type": "pickString", - "id": "service", - "description": "Which service do you want to start?", + "id": "sample", + "description": "Which sample do you want to start?", "options": [ "bookshop", - "bookstore", - "media-server", - "office-supplies", - "reviews-service" + "fiori", + "reviews", + "reviews/test/bookshop" ], "default": "bookshop" } From 79d624e798b2423a38f93efeb24b4a35e5b80691 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 14:02:33 +0100 Subject: [PATCH 22/29] Added workaround for bug in compiler --- bookshop/readme.md | 2 +- reviews/test/bookshop/schema.cds | 9 +++++++++ reviews/test/bookshop/server.js | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bookshop/readme.md b/bookshop/readme.md index 7bc3af7e..7b568e36 100644 --- a/bookshop/readme.md +++ b/bookshop/readme.md @@ -1,6 +1,6 @@ # Bookshop Getting Started Sample -This sample introduces the essential tasks in the development of CAP-based services as also covered in the [Getting Started guide in capire](https://cap.cloud.sap/docs/get-started/in-a-nutshell). +This stand-alone sample introduces the essential tasks in the development of CAP-based services as also covered in the [Getting Started guide in capire](https://cap.cloud.sap/docs/get-started/in-a-nutshell). ## Hypothetical Use Cases diff --git a/reviews/test/bookshop/schema.cds b/reviews/test/bookshop/schema.cds index 39fdfb35..968a62de 100644 --- a/reviews/test/bookshop/schema.cds +++ b/reviews/test/bookshop/schema.cds @@ -11,3 +11,12 @@ extend Books with { /** Average rating */ rating : Reviews.rating; } + +////////////////////////////////////////////////////////////////////////////// +// BUG in compiler: we have to force-include cat-service after admin-service +// see cap/issues#111; when fixed we can rempve these lines +// + using from '@capire/bookshop/srv/admin-service'; + using from '@capire/bookshop/srv/cat-service'; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/reviews/test/bookshop/server.js b/reviews/test/bookshop/server.js index 540c6d65..369af0f1 100644 --- a/reviews/test/bookshop/server.js +++ b/reviews/test/bookshop/server.js @@ -20,7 +20,6 @@ cds.on('listening', async()=>{ // return tx.update (Books, subject) .with ({rating}) }) - console.log (Reviews.name) // delegate requests to read reviews to ReviewsService CatalogService.impl (srv => { srv.on ('READ', 'Books/reviews', (req) => { From f50e5312c3392610bc6ee696bc8b5d5404c873a9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 14:39:15 +0100 Subject: [PATCH 23/29] Added ref to cap/issues#4112 --- reviews/test/bookshop/schema.cds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reviews/test/bookshop/schema.cds b/reviews/test/bookshop/schema.cds index 968a62de..849890a6 100644 --- a/reviews/test/bookshop/schema.cds +++ b/reviews/test/bookshop/schema.cds @@ -14,7 +14,7 @@ extend Books with { ////////////////////////////////////////////////////////////////////////////// // BUG in compiler: we have to force-include cat-service after admin-service -// see cap/issues#111; when fixed we can rempve these lines +// see cap/issues#4112; when fixed we can rempve these lines // using from '@capire/bookshop/srv/admin-service'; using from '@capire/bookshop/srv/cat-service'; From fb3cf9c3155656ea68a61dff7c94d00d81a53ecd Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 15:02:55 +0100 Subject: [PATCH 24/29] Removed left-over of ./reviewed --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 867f3cbc..710b1589 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "repository": "https://github.com/sap-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", "dependencies": { - "@capire/bookshop-with-reviews": "file:reviewed", "@capire/bookshop": "file:bookshop", "@capire/common": "file:common", "@capire/fiori": "file:fiori", From 8c50d057762b916c7e2ff889f8e73fc6bbaddd53 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 15:22:07 +0100 Subject: [PATCH 25/29] Fixed launch.json --- .vscode/launch.json | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bdca8db5..8ea4c533 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,16 +5,9 @@ "version": "0.2.0", "configurations": [ { - "name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ], - "args": [ "--", "cds", "run", "--in-memory" ], - "cwd": "${workspaceFolder}/packages/bookshop", - "console": "integratedTerminal", - "skipFiles": ["/**"] - }, - { - "name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ], + "name": "cds run ...", "cwd": "${workspaceFolder}/${input:sample}", + "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ], "args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ], - "cwd": "${workspaceFolder}/${input:sample}", "console": "integratedTerminal", "skipFiles": ["/**"] } From 86134759888571484695c8bffde906cca6ccc2c7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 16:16:27 +0100 Subject: [PATCH 26/29] beautified impl --- reviews/test/bookshop/server.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/reviews/test/bookshop/server.js b/reviews/test/bookshop/server.js index 369af0f1..7d17dbb8 100644 --- a/reviews/test/bookshop/server.js +++ b/reviews/test/bookshop/server.js @@ -1,28 +1,25 @@ const cds = require ('@sap/cds') +// Mashup services after bootstrapping... cds.on('listening', async()=>{ - // connect to requires services - const ReviewsService = await cds.connect.to ('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 { Reviews } = ReviewsService.entities - const { Books } = db.entities - // react on event messages from reviews service + const ReviewsService = await cds.connect.to ('ReviewsService') + const db = await cds.connect.to ('db') ReviewsService.on ('reviewed', (msg) => { console.debug ('> received:', msg.event, msg.data) + const { Books } = db.entities('sap.capire.bookshop') 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}) + // return tx.run (UPDATE (Books, subject) .with ({rating})) + return tx.update (Books, subject) .with ({rating}) }) // delegate requests to read reviews to ReviewsService - CatalogService.impl (srv => { - srv.on ('READ', 'Books/reviews', (req) => { + const CatalogService = await cds.connect.to ('CatalogService') + CatalogService.impl (() => { + CatalogService.on ('READ', 'Books/reviews', (req) => { + const { Reviews } = ReviewsService.entities const [ subject ] = req.params const tx = ReviewsService.transaction (req) return tx.run (SELECT.from (Reviews) .where ({subject})) @@ -31,4 +28,5 @@ cds.on('listening', async()=>{ }) +// Delegate bootstrapping to built-in server.js module.exports = cds.server From eefdf6c97638d8050b09aa46428d7245417807c8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 9 Mar 2020 16:34:53 +0100 Subject: [PATCH 27/29] less prominent workaround --- reviews/test/bookshop/schema.cds | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/reviews/test/bookshop/schema.cds b/reviews/test/bookshop/schema.cds index 849890a6..7553b3fa 100644 --- a/reviews/test/bookshop/schema.cds +++ b/reviews/test/bookshop/schema.cds @@ -12,11 +12,5 @@ extend Books with { rating : Reviews.rating; } -////////////////////////////////////////////////////////////////////////////// -// BUG in compiler: we have to force-include cat-service after admin-service -// see cap/issues#4112; when fixed we can rempve these lines -// - using from '@capire/bookshop/srv/admin-service'; - using from '@capire/bookshop/srv/cat-service'; -// -////////////////////////////////////////////////////////////////////////////// +// Temporary workaround for cap/issues#4112: +annotate Reviews with @cds.autoexpose; From e4983b8bde98868cc332e24fdd3d18c565bbc4d8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Mar 2020 12:11:07 +0100 Subject: [PATCH 28/29] Moved managed data annotations --- reviews/db/schema.cds | 7 +++++++ reviews/srv/reviews-service.cds | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reviews/db/schema.cds b/reviews/db/schema.cds index 0183a8fd..e49f90ca 100644 --- a/reviews/db/schema.cds +++ b/reviews/db/schema.cds @@ -29,3 +29,10 @@ entity Likes { key review : Association to Reviews; key user : User; } + +// Auto-fill reviewers and review dates +annotate Reviews with { + reviewer @cds.on.insert:$user; + date @cds.on.insert:$now; + date @cds.on.update:$now; +} diff --git a/reviews/srv/reviews-service.cds b/reviews/srv/reviews-service.cds index dafcb0d1..edd24e0d 100644 --- a/reviews/srv/reviews-service.cds +++ b/reviews/srv/reviews-service.cds @@ -16,13 +16,6 @@ service ReviewsService { 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; - } - } From 4ae16e8fd261082f448e658595e2bafe992b782b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Mar 2020 12:12:18 +0100 Subject: [PATCH 29/29] Cleaned up delegation --- reviews/test/bookshop/server.js | 20 +++++++++----------- reviews/test/requests.http | 6 ++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/reviews/test/bookshop/server.js b/reviews/test/bookshop/server.js index 7d17dbb8..22075d5f 100644 --- a/reviews/test/bookshop/server.js +++ b/reviews/test/bookshop/server.js @@ -10,21 +10,19 @@ cds.on('listening', async()=>{ console.debug ('> received:', msg.event, msg.data) const { Books } = db.entities('sap.capire.bookshop') 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}) + const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented? + return tx.update (Books,subject) .with ({rating}) }) // delegate requests to read reviews to ReviewsService const CatalogService = await cds.connect.to ('CatalogService') - CatalogService.impl (() => { - CatalogService.on ('READ', 'Books/reviews', (req) => { - const { Reviews } = ReviewsService.entities - const [ subject ] = req.params - const tx = ReviewsService.transaction (req) - return tx.run (SELECT.from (Reviews) .where ({subject})) - }) - }) + CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => { + console.debug ('> delegating to ReviewsService') + const { Reviews } = ReviewsService.entities + const [ subject ] = req.params + const tx = ReviewsService.tx (req) + return tx.read (Reviews,{subject}) .columns (req.query.SELECT.columns) + })) }) diff --git a/reviews/test/requests.http b/reviews/test/requests.http index d1c89504..c311be81 100644 --- a/reviews/test/requests.http +++ b/reviews/test/requests.http @@ -5,10 +5,12 @@ ### Request to CatalogService > delegated to ReviewsService -GET http://localhost:4004/browse/Books(201)/reviews +GET http://localhost:4004/browse/Books(201)/reviews? +&$select=rating,date,reviewer,title ### Alternative OData URL -GET http://localhost:4004/browse/Books/201/reviews +GET http://localhost:4004/browse/Books/201/reviews? +&$select=rating,date,reviewer,title ### GET http://localhost:4004/browse/Books(201)?