From 48fa640f5b9d30aeebf169d1cfa9926f7e5624ae Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Mar 2020 12:42:33 +0100 Subject: [PATCH] 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 +```