diff --git a/fiori/db/hana/index.cds b/bookstore/db/hana/index.cds similarity index 100% rename from fiori/db/hana/index.cds rename to bookstore/db/hana/index.cds diff --git a/fiori/db/schema.cds b/bookstore/db/schema.cds similarity index 100% rename from fiori/db/schema.cds rename to bookstore/db/schema.cds diff --git a/fiori/db/sqlite/index.cds b/bookstore/db/sqlite/index.cds similarity index 100% rename from fiori/db/sqlite/index.cds rename to bookstore/db/sqlite/index.cds diff --git a/bookstore/package.json b/bookstore/package.json new file mode 100644 index 00000000..d4b2dc02 --- /dev/null +++ b/bookstore/package.json @@ -0,0 +1,28 @@ +{ + "name": "@capire/bookstore", + "version": "1.0.0", + "dependencies": { + "@capire/bookshop": "*", + "@capire/reviews": "*", + "@capire/orders": "*", + "@capire/common": "*", + "@sap/cds": "^5", + "express": "^4.17.1" + }, + "cds": { + "requires": { + "ReviewsService": { + "kind": "odata", + "model": "@capire/reviews" + }, + "messaging": { + "[production]": { "kind": "enterprise-messaging" }, + "[hybrid]": { "kind": "enterprise-messaging-shared" }, + "[local]": { "kind": "file-based-messaging" }, + "kind": "local-messaging" + }, + "db": { "kind": "sql" } + }, + "log": { "service": true } + } +} \ No newline at end of file diff --git a/bookstore/server.js b/bookstore/server.js new file mode 100644 index 00000000..0fe21fcd --- /dev/null +++ b/bookstore/server.js @@ -0,0 +1,17 @@ +const cds = require ('@sap/cds') + +// Add mashup logic +cds.once('served', require('./srv/mashup')) + +// Add routes to UIs from imported packages +cds.once('bootstrap',(app)=>{ + app.serve ('/bookshop') .from ('@capire/bookshop','app/vue') + app.serve ('/reviews') .from ('@capire/reviews','app/vue') + app.serve ('/orders') .from('@capire/orders','app/orders') +}) + +// Add Swagger UI +require('./srv/swagger-ui') + +// Returning cds.server +module.exports = cds.server diff --git a/fiori/srv/mashup.cds b/bookstore/srv/mashup.cds similarity index 74% rename from fiori/srv/mashup.cds rename to bookstore/srv/mashup.cds index 7bc0ff47..109f8a82 100644 --- a/fiori/srv/mashup.cds +++ b/bookstore/srv/mashup.cds @@ -1,6 +1,7 @@ //////////////////////////////////////////////////////////////////////////// // -// Mashing up imported models... +// Enhancing bookshop with Reviews and Orders provided through +// respective reuse packages and services // using { sap.capire.bookshop.Books } from '@capire/bookshop'; @@ -8,19 +9,22 @@ using { sap.capire.bookshop.Books } from '@capire/bookshop'; // // Extend Books with access to Reviews and average ratings // - using { ReviewsService.Reviews } from '@capire/reviews'; extend Books with { reviews : Composition of many Reviews on reviews.subject = $self.ID; - numberOfReviews : Integer; rating : Decimal; + numberOfReviews : Integer; } + // // Extend Orders with Books as Products // - using { sap.capire.orders.Orders_Items } from '@capire/orders'; extend Orders_Items with { book : Association to Books on product.ID = book.ID } + + +// Add orders fiori app (in case of embedded orders service) +using from '@capire/orders/app/fiori'; diff --git a/fiori/srv/mashup.js b/bookstore/srv/mashup.js similarity index 97% rename from fiori/srv/mashup.js rename to bookstore/srv/mashup.js index 6d8aa412..e2fe7388 100644 --- a/fiori/srv/mashup.js +++ b/bookstore/srv/mashup.js @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////// // -// Mashing up provided and required services... +// Mashing up bookshop services with required services... // module.exports = async()=>{ // called by server.js diff --git a/bookstore/srv/swagger-ui.js b/bookstore/srv/swagger-ui.js new file mode 100644 index 00000000..22fe3a18 --- /dev/null +++ b/bookstore/srv/swagger-ui.js @@ -0,0 +1,10 @@ + +// ----------------------------------------------------------------------- +// Adding Swagger UI - see https://cap.cloud.sap/docs/advanced/openapi +const cds = require ('@sap/cds') +try { + const cds_swagger = require ('cds-swagger-ui-express') + cds.once ('bootstrap', app => app.use (cds_swagger()) ) +} catch (err) { + if (err.code !== 'MODULE_NOT_FOUND') throw err +} diff --git a/fiori/test/requests.http b/bookstore/test/requests.http similarity index 97% rename from fiori/test/requests.http rename to bookstore/test/requests.http index d8392583..c42b4bd4 100644 --- a/fiori/test/requests.http +++ b/bookstore/test/requests.http @@ -2,7 +2,7 @@ @bookshop = http://localhost:4004 @reviews-service = {{bookshop}}/reviews # Uncomment this when running a separate reviews service -@reviews-service = http://localhost:4005/reviews +# @reviews-service = http://localhost:4005/reviews diff --git a/fiori/.env b/fiori/.env deleted file mode 100644 index 36644fa6..00000000 --- a/fiori/.env +++ /dev/null @@ -1,2 +0,0 @@ -# cds.requires.messaging.kind = file-based-messaging -PORT = 4004 \ No newline at end of file diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index a721c65a..972c1232 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using { AdminService } from '../../db/schema'; +using { AdminService } from '@capire/bookshop'; using from '../common'; // to help UI linter get the complete annotations //////////////////////////////////////////////////////////////////////////// diff --git a/fiori/app/bookshop.html b/fiori/app/bookshop.html deleted file mode 100644 index e7c07e25..00000000 --- a/fiori/app/bookshop.html +++ /dev/null @@ -1,3 +0,0 @@ -
- - diff --git a/fiori/app/admin-fiori.html b/fiori/app/fiori-apps.html similarity index 100% rename from fiori/app/admin-fiori.html rename to fiori/app/fiori-apps.html diff --git a/fiori/app/reviews.html b/fiori/app/reviews.html deleted file mode 100644 index 75af8860..00000000 --- a/fiori/app/reviews.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/fiori/app/services.cds b/fiori/app/services.cds index 595023e9..e59f69f8 100644 --- a/fiori/app/services.cds +++ b/fiori/app/services.cds @@ -6,7 +6,4 @@ using from './admin/fiori-service'; using from './browse/fiori-service'; using from './common'; -using from '@capire/common'; - -// only works in case of embedded orders service -using from '@capire/orders/app/orders/fiori-service'; +using from '@capire/bookstore/srv/mashup'; diff --git a/fiori/package.json b/fiori/package.json index 0449fb13..50fc25f5 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -2,10 +2,7 @@ "name": "@capire/fiori", "version": "1.0.0", "dependencies": { - "@capire/bookshop": "*", - "@capire/reviews": "*", - "@capire/orders": "*", - "@capire/common": "*", + "@capire/bookstore": "*", "@sap/cds": "^5", "express": "^4.17.1", "passport": "^0.4.1" @@ -15,9 +12,6 @@ "watch": "cds watch" }, "cds": { - "hana": { - "deploy-format": "hdbtable" - }, "requires": { "auth": { "strategy": "dummy" @@ -40,10 +34,20 @@ } }, "messaging": { - "[development]": { "kind": "file-based-messaging" }, - "[hybrid]": { "kind": "enterprise-messaging-shared" }, - "kind": "enterprise-messaging" + "[production]": { + "kind": "enterprise-messaging" + }, + "[hybrid]": { + "kind": "enterprise-messaging-shared" + }, + "[local]": { + "kind": "file-based-messaging" + }, + "kind": "local-messaging" + }, + "hana": { + "deploy-format": "hdbtable" } } } -} +} \ No newline at end of file diff --git a/fiori/server.js b/fiori/server.js index 9a2aec05..f9c211af 100644 --- a/fiori/server.js +++ b/fiori/server.js @@ -1,25 +1 @@ -const cds = require ('@sap/cds') -module.exports = cds.server - -cds.once('bootstrap',(app)=>{ - app.use ('/orders/webapp', _from('@capire/orders/app/orders/webapp/manifest.json')) - app.use ('/bookshop', _from('@capire/bookshop/app/vue/index.html')) - app.use ('/reviews', _from('@capire/reviews/app/vue/index.html')) -}) - -cds.once('served', require('./srv/mashup')) - -// Swagger UI - see https://cap.cloud.sap/docs/advanced/openapi -try { - const cds_swagger = require ('cds-swagger-ui-express') - cds.once ('bootstrap', app => app.use (cds_swagger()) ) -} catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') throw err -} - - -// ----------------------------------------------------------------------- -// Helper for serving static content from npm-installed packages -const {static} = require('express') -const {dirname} = require('path') -const _from = target => static (dirname (require.resolve(target))) +module.exports = require('@capire/bookstore/server.js') diff --git a/package.json b/package.json index 9b425ca9..fbf16378 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "repository": "https://github.com/sap-samples/cloud-cap-samples.git", "author": "daniel.hutzel@sap.com", "dependencies": { + "@capire/bookstore": "./bookstore", "@capire/bookshop": "./bookshop", "@capire/common": "./common", "@capire/fiori": "./fiori", diff --git a/samples.md b/samples.md index e6c8b066..3e435561 100644 --- a/samples.md +++ b/samples.md @@ -51,21 +51,28 @@ Each sub directory essentially is an individual npm package arranged in an [all- - As well as managed data, input validations, and authorization -## [@capire/fiori](fiori) +## [@capire/bookstore](bookstore) - A [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages: - [@capire/bookshop](bookshop) - [@capire/reviews](reviews) - [@capire/orders](orders) - [@capire/common](common) -- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby 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 SAP Fiori apps locally - [The Vue.js app](bookshop/app/vue) imported from bookshop is served as well +- [The Vue.js app](reviews/app/vue) imported from reviews is served as well +- [The Fiori app](orders/app) imported from orders is served as well - [OpenAPI export + Swagger UI](https://cap.cloud.sap/docs/advanced/openapi) + + +## [@capire/fiori](fiori) + +- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby 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 SAP Fiori apps locally +