Compare commits
4 Commits
dependabot
...
graphql
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9536a7f34c | ||
|
|
079620463f | ||
|
|
d53d4de105 | ||
|
|
b13ed5cc8d |
2425
.deploy/app-router/package-lock.json
generated
2425
.deploy/app-router/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "approuter",
|
||||
"dependencies": {
|
||||
"@sap/approuter": "^20.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node node_modules/@sap/approuter/approuter.js"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../../bookshop/app/vue
|
||||
@@ -1 +0,0 @@
|
||||
../../../orders/app/orders
|
||||
@@ -1 +0,0 @@
|
||||
../../../reviews/app/vue
|
||||
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"welcomeFile": "app/bookshop/index.html",
|
||||
"routes": [
|
||||
{
|
||||
"source": "^/app/(.*)$",
|
||||
"target": "$1",
|
||||
"localDir": "resources",
|
||||
"cacheControl": "no-cache, no-store, must-revalidate"
|
||||
},
|
||||
{
|
||||
"source": "^/admin/(.*)$",
|
||||
"target": "/admin/$1",
|
||||
"destination": "bookstore-api",
|
||||
"csrfProtection": true
|
||||
},
|
||||
{
|
||||
"source": "^/browse/(.*)$",
|
||||
"target": "/browse/$1",
|
||||
"destination": "bookstore-api",
|
||||
"csrfProtection": true
|
||||
},
|
||||
{
|
||||
"source": "^/user/(.*)$",
|
||||
"target": "/user/$1",
|
||||
"destination": "bookstore-api",
|
||||
"csrfProtection": true
|
||||
},
|
||||
{
|
||||
"source": "^/odata/v4/orders/(.*)$",
|
||||
"target": "/odata/v4/orders/$1",
|
||||
"destination": "orders-api",
|
||||
"csrfProtection": true
|
||||
},
|
||||
{
|
||||
"source": "^/reviews/(.*)$",
|
||||
"target": "/reviews/$1",
|
||||
"destination": "reviews-api",
|
||||
"csrfProtection": true
|
||||
}
|
||||
]
|
||||
}
|
||||
27
.eslintrc
Normal file
27
.eslintrc
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest": true,
|
||||
"mocha": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"globals": {
|
||||
"SELECT": true,
|
||||
"INSERT": true,
|
||||
"UPDATE": true,
|
||||
"DELETE": true,
|
||||
"CREATE": true,
|
||||
"DROP": true,
|
||||
"cds": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "off",
|
||||
"require-atomic-updates": "off",
|
||||
"require-await":"warn"
|
||||
}
|
||||
}
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: This channel is CLOSED.
|
||||
about: Use SAP community instead
|
||||
url: https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce
|
||||
10
.github/ISSUE_TEMPLATE/question--feedback-or-bug-.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/question--feedback-or-bug-.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: This channel is CLOSED.
|
||||
about: Use our community at https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Please use our community on https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce
|
||||
23
.github/dependabot.yml
vendored
23
.github/dependabot.yml
vendored
@@ -1,23 +0,0 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
versioning-strategy: increase-if-necessary
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
production-dependencies:
|
||||
dependency-type: "production"
|
||||
development-dependencies:
|
||||
dependency-type: "development"
|
||||
ignore:
|
||||
- dependency-name: "chai"
|
||||
# chai 5 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
||||
versions: ["5.x"]
|
||||
- dependency-name: "chai-as-promised"
|
||||
# chai-as-promised 8 doesn't work atm w/ cds.test, TODO fix that in cds.test
|
||||
versions: ["8.x"]
|
||||
- dependency-name: "express"
|
||||
# express 5 not supported atm
|
||||
versions: ["5.x"]
|
||||
18
.github/workflows/node.js.yml
vendored
18
.github/workflows/node.js.yml
vendored
@@ -11,28 +11,18 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [22.x, 20.x]
|
||||
node-version: [12.x, 14.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22.x
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -12,14 +12,8 @@ target/
|
||||
*.mtar
|
||||
connection.properties
|
||||
default-env.json
|
||||
.cdsrc-private.json
|
||||
packages/messageBox
|
||||
reviews/msg-box
|
||||
reviews/db/test.db
|
||||
|
||||
*.openapi3.json
|
||||
*.sqlite
|
||||
*.db
|
||||
|
||||
@types/
|
||||
@cds-models/
|
||||
|
||||
3
.npmrc
Normal file
3
.npmrc
Normal file
@@ -0,0 +1,3 @@
|
||||
# Ensure we always use public packages, i.e. avoid using local registries from ~/.npmrc
|
||||
@sap:registry=https://registry.npmjs.org/
|
||||
registry=https://registry.npmjs.org/
|
||||
1
.registry/.gitignore
vendored
Normal file
1
.registry/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.tgz
|
||||
79
.registry/server.js
Normal file
79
.registry/server.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const { exec } = require ('child_process')
|
||||
const isWin = process.platform === 'win32'
|
||||
const express = require ('express')
|
||||
const fs = require ('fs')
|
||||
const app = express()
|
||||
|
||||
const { PORT=4444 } = process.env
|
||||
const [,,port=PORT,scope='@capire'] = process.argv
|
||||
const cwd = __dirname
|
||||
|
||||
// clean up on start (exit handler might not complete on Windows)
|
||||
exec(isWin ? 'del *.tgz' : 'rm *.tgz', {cwd})
|
||||
|
||||
|
||||
app.use('/-/:tarball', (req,res,next) => {
|
||||
console.debug ('GET', req.params)
|
||||
try {
|
||||
const { tarball } = req.params
|
||||
const [, pkg ] = /^\w+-(\w+)/.exec(tarball)
|
||||
fs.lstat(tarball,(err => {
|
||||
if (err) exec(`npm pack ../${pkg}`,{cwd},next)
|
||||
else next()
|
||||
}))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
res.sendStatus(500)
|
||||
}
|
||||
})
|
||||
|
||||
app.use('/-', express.static(__dirname))
|
||||
|
||||
app.get('/*', (req,res)=>{
|
||||
const urlRegex = /^\/(@\w+)\/(\w+)/
|
||||
const url = decodeURIComponent(req.url)
|
||||
console.debug ('GET',url)
|
||||
try {
|
||||
if (!urlRegex.test(url)) return res.sendStatus(404)
|
||||
const [, scpe, pkg ] = urlRegex.exec(url)
|
||||
const package = require (`${scpe}/${pkg}/package.json`)
|
||||
const tarball = `${scpe.slice(1)}-${pkg}-${package.version}.tgz`
|
||||
// https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md
|
||||
res.json({
|
||||
"name": package.name,
|
||||
"dist-tags": {
|
||||
"latest": package.version
|
||||
},
|
||||
"versions": {
|
||||
[package.version]: {
|
||||
"name": package.name,
|
||||
"version": package.version,
|
||||
"dist": {
|
||||
"tarball": `/-/${tarball}`
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
} catch (e) {
|
||||
if (e.code === 'MODULE_NOT_FOUND') return res.sendStatus(404)
|
||||
console.error(e); throw e
|
||||
}
|
||||
})
|
||||
|
||||
const server = app.listen(port, ()=>{
|
||||
const url = `http://localhost:${server.address().port}`
|
||||
console.log (`npm set ${scope}:registry=${url}`)
|
||||
exec(`npm set ${scope}:registry=${url}`)
|
||||
console.log (`${scope} registry listening on ${url}`)
|
||||
})
|
||||
|
||||
|
||||
const _exit = ()=>{
|
||||
server.close()
|
||||
exec(`npm conf rm "${scope}:registry"`, ()=> { process.exit() })
|
||||
}
|
||||
|
||||
process.on ('SIGTERM',_exit)
|
||||
process.on ('SIGHUP',_exit)
|
||||
process.on ('SIGINT',_exit)
|
||||
process.on ('SIGUSR2',_exit)
|
||||
@@ -24,6 +24,6 @@ Disclaimer: The code in this project may include calls to APIs (“API Calls”)
|
||||
you any rights to use or access any SAP External Product, or provide any third
|
||||
parties the right to use of access any SAP External Product, through API Calls.
|
||||
|
||||
Files: *.*
|
||||
Copyright: 2019-2025 SAP SE or an SAP affiliate company and cap-cloud-samples
|
||||
Files: *
|
||||
Copyright: 2019-2020 SAP SE or an SAP affiliate company and cap-cloud-samples
|
||||
License: Apache-2.0
|
||||
|
||||
109
.tours/db-native.tour
Normal file
109
.tours/db-native.tour
Normal file
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"$schema": "https://aka.ms/codetour-schema",
|
||||
"title": "Database Functions",
|
||||
"steps": [
|
||||
{
|
||||
"title": "Introduction",
|
||||
"description": "### Database Functions in CDS Models\n\nIn this tour, you'll learn how to add database-specific functions to CDS models in your application."
|
||||
},
|
||||
{
|
||||
"file": "bookshop/db/schema.cds",
|
||||
"description": "#### Basic Schema\n\nWe want to add two fields to the `Authors` entity, one for the author's age and one for the span of years that she or he lived.\n\nThese two fields can be computed out of the existing `dateOfBirth` and `dateOfDeath` fields.",
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 19,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 21,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Base fields in Author"
|
||||
},
|
||||
{
|
||||
"file": "bookshop/srv/admin-service.cds",
|
||||
"description": "This is how the `Authors` entity gets exposed in an OData or REST service.\n\nIn the next step, you'll see how we extend this projection.",
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Authors service"
|
||||
},
|
||||
{
|
||||
"file": "fiori/db/sqlite/index.cds",
|
||||
"description": "#### SQLite Implementation\n\nHere's the first implementation for SQLite. It computes the two fields `age` and `lifetime` through SQLite's [strftime](https://sqlite.org/lang_datefunc.html) function.\n\nThrough the [`extend projection`](https://cap.cloud.sap/docs/cds/cdl#extend-view) clause you can add additional fields to projection entities. These are deployed as database views, which is why we can integrate the database functions in the first place.\n",
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "SQLite implementation"
|
||||
},
|
||||
{
|
||||
"file": "fiori/db/hana/index.cds",
|
||||
"description": "#### SAP HANA Implementation\n\nThis is the second implementation for SAP HANA. It computes the same two fields `age` and `lifetime` through the [YEARS_BETWEEN](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/7c0d2c161ea34def86de3f5eadd6a0af.html) and [YEAR](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/20f5fac6751910148dabd3c6821f907d.html) functions of SAP HANA.\n\n#### File Layout and Code Structure\n\nNote the path of the `.cds` file we are in: it's in a subfolder of `db`, so that it's _not_ automatically picked up when we start the application. The same is true for the SQLite implementation: it's in a separate `db/sqlite/` folder as well. In the next step, you'll see how these files are loaded.\n\nAlso, we choose to implement all of that as an extension of the original bookshop here in the _fiori_ package. See the first [CAP Samples] code tour for more details on the different packages of this repository.",
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "SAP HANA implementation"
|
||||
},
|
||||
{
|
||||
"file": "fiori/package.json",
|
||||
"description": "#### Configuration\n\nThe `cds` section in `package.json` is a place to configure which of the `db/sqlite` and `db/hana` folders are used for which database.\nWe use [Node.js profiles](https://cap.cloud.sap/docs/node.js/cds-env#profiles) to separate the configuration.\nIn the `development` profile, you can see that `db/sqlite` is set as the model, while the `db/hana` folder is configured in the `production` profile.",
|
||||
"line": 17,
|
||||
"title": "Configuration"
|
||||
},
|
||||
{
|
||||
"file": "fiori/package.json",
|
||||
"description": "#### Run with SQLite\n\nTo run with `development` and an in-memory SQLite database, you don't need to do anything special, because it's activated by default. Just run:\n\n>> cds watch fiori\n\nThen open [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) to see the two new fields.\n",
|
||||
"line": 28,
|
||||
"title": "Run with SQLite"
|
||||
},
|
||||
{
|
||||
"file": "fiori/package.json",
|
||||
"description": "#### Deploy the CDS Model to SAP HANA\n\nTo 'activate' SAP HANA through the `production` profile, you can use the global `--production` flag:\n\n>> cd fiori; cds deploy --to hana --production\n\n[Learn more about SAP HANA deployment](https://cap.cloud.sap/docs/guides/databases#get-hana)\n\n#### Run the Application\n\n>> cd fiori; cds watch --production\n\nThe service on [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) is the same as before, but this time the `Authors` entity is backed by a database view with an SAP HANA function.\n\n#### More\n\nIf you don't see data, you can add some in the next step.",
|
||||
"line": 31,
|
||||
"title": "Run with SAP HANA"
|
||||
},
|
||||
{
|
||||
"file": "fiori/test/requests.http",
|
||||
"description": "### Add More Data\n\nOptionally you can add some `Authors` data by clicking on the _Send Request_ link (provided by the [REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension).",
|
||||
"line": 68,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 67,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 73,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Add Data"
|
||||
},
|
||||
{
|
||||
"title": "Wrap-up",
|
||||
"description": "### Summary\n\nThat's it! You have seen: \n- How to integrate database-specific functions in a CDS model.\n- How to switch between the two implementations for SQLite and SAP HANA."
|
||||
}
|
||||
],
|
||||
"ref": "main"
|
||||
}
|
||||
136
.tours/samples.tour
Normal file
136
.tours/samples.tour
Normal file
@@ -0,0 +1,136 @@
|
||||
{
|
||||
"$schema": "https://aka.ms/codetour-schema",
|
||||
"title": "CAP Samples",
|
||||
"steps": [
|
||||
{
|
||||
"title": "Welcome",
|
||||
"file": "README.md",
|
||||
"description": "### Welcome to CAP Samples!\n\nThis tour leads you through a collection of samples for the [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap).\nYou will learn which features of the programming model are demonstrated in which sample.\n\nLet's start!",
|
||||
"line": 2,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"character": 108
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"file": "hello/world.cds",
|
||||
"description": "### Hello World!\n\nThis is 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).",
|
||||
"line": 2,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Hello World!"
|
||||
},
|
||||
{
|
||||
"file": "bookshop/db/schema.cds",
|
||||
"description": "### A Bookshop!\n\nIntroduces:\n- [Project Setup](https://cap.cloud.sap/docs/get-started/) and [Layouts](https://cap.cloud.sap/docs/get-started/projects)\n- [Domain Modeling](https://cap.cloud.sap/docs/guides/domain-models)\n- [Defining Services](https://cap.cloud.sap/docs/guides/providing-services)\n- [Generic Providers](https://cap.cloud.sap/docs/guides/generic-providers)\n- [Adding Custom Logic](https://cap.cloud.sap/docs/guides/service-impl)\n- [Using Databases](https://cap.cloud.sap/docs/guides/databases)\n",
|
||||
"line": 1,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 32,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Bookshop"
|
||||
},
|
||||
{
|
||||
"file": "common/index.cds",
|
||||
"description": "### Extend and Reuse\n\nShowcases how to extend [@sap/cds/common](https://cap.cloud.sap/docs/cds/common) thereby covering:\n- Building [extension packages](https://cap.cloud.sap/docs/guides/domain-models#aspects-extensibility)\n- Providing [reuse packages](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content)\n- [Verticalization](https://cap.cloud.sap/docs/cds/common#adapting-to-your-needs)\n- Using [Aspects](https://cap.cloud.sap/docs/cds/cdl#aspects)\n- Used in the [fiori app sample](#fiori)\n",
|
||||
"line": 1,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 46,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Common"
|
||||
},
|
||||
{
|
||||
"file": "orders/db/schema.cds",
|
||||
"description": "### Compositions and Serving Documents\n\nA standalone orders management service, demonstrating:\n- Using [Compositions](https://cap.cloud.sap/docs/cds/cdl#compositions) in [Domain Models](https://cap.cloud.sap/docs/guides/domain-models), along with\n- [Serving deeply nested documents](https://cap.cloud.sap/docs/guides/generic-providers#serving-structured-data)\n",
|
||||
"line": 1,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 27,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Orders"
|
||||
},
|
||||
{
|
||||
"file": "reviews/db/schema.cds",
|
||||
"description": "### More Modularity\n\nShows how to implement a modular service to manage product reviews, including:\n- Consuming other services synchronously and asynchronously\n- Serving requests synchronously\n- Emitting events asynchronously\n- Grow as you go, with:\n- Mocking app services\n- Running service meshes\n- Late-cut Micro Services\n- As well as managed data, input validations, and authorization\n",
|
||||
"line": 1,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 39,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Reviews"
|
||||
},
|
||||
{
|
||||
"file": "fiori/app/index.cds",
|
||||
"description": "### Annotations for SAP Fiori Elements\n\nA [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages:\n - [@capire/bookshop](bookshop)\n - [@capire/reviews](reviews)\n - [@capire/orders](orders)\n - [@capire/common](common)\n\n[Adds a SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to:\n - [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files\n - Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)\n - Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help)\n - Serving SAP Fiori apps locally\n\n[The Vue.js app](bookshop/app/vue) imported from bookshop is served as well.\n",
|
||||
"line": 1,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 13,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Fiori"
|
||||
},
|
||||
{
|
||||
"file": "package.json",
|
||||
"description": "### All-in-one Monorepo\n\nEach 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.\n",
|
||||
"line": 8,
|
||||
"selection": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 15,
|
||||
"character": 1
|
||||
}
|
||||
},
|
||||
"title": "Packages"
|
||||
}
|
||||
],
|
||||
"isPrimary": true,
|
||||
"description": "Overview of CAP Samples for Node.js"
|
||||
}
|
||||
6
.vscode/extensions.json
vendored
6
.vscode/extensions.json
vendored
@@ -4,11 +4,15 @@
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"qwtel.sqlite-viewer",
|
||||
"sapse.vscode-cds",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"mechatroner.rainbow-csv",
|
||||
"humao.rest-client",
|
||||
"alexcvzz.vscode-sqlite",
|
||||
"hbenl.vscode-mocha-test-adapter",
|
||||
"sdras.night-owl",
|
||||
"vsls-contrib.codetour"
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
|
||||
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@@ -13,22 +13,31 @@
|
||||
"<node_internals>/**",
|
||||
"**/node_modules/**",
|
||||
"**/cds/lib/lazy.js",
|
||||
"**/cds/lib/req/cds-context.js",
|
||||
"**/cds/lib/req/cls.js",
|
||||
"**/odata-v4/okra/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bookstore",
|
||||
"command": "npx cds watch bookstore",
|
||||
"name": "Fiori App",
|
||||
"command": "npx cds watch fiori",
|
||||
"type": "node-terminal",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**",
|
||||
"**/node_modules/**",
|
||||
"**/cds/lib/lazy.js",
|
||||
"**/cds/lib/req/cds-context.js",
|
||||
"**/cds/lib/req/cls.js",
|
||||
"**/odata-v4/okra/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"type": "pickString",
|
||||
"id": "sample",
|
||||
"description": "Which sample do you want to start?",
|
||||
"options": [ "bookshop", "fiori", "reviews", "reviews" ],
|
||||
"default": "bookshop"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@@ -1,15 +1,16 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/node_modules": true,
|
||||
"LICENSES": true,
|
||||
".reuse": true
|
||||
".reuse/**": true,
|
||||
"**/.gitignore": true,
|
||||
"**/.vscode": true,
|
||||
"LICENSES/**": true
|
||||
},
|
||||
"debug.javascript.terminalOptions": {
|
||||
"skipFiles": [
|
||||
"<node_internals>/**",
|
||||
"**/node_modules/**",
|
||||
"**/cds/lib/lazy.js",
|
||||
"**/cds/lib/req/cds-context.js",
|
||||
"**/cds/lib/req/cls.js",
|
||||
"**/odata-v4/okra/**"
|
||||
]
|
||||
}
|
||||
|
||||
86
README.md
Normal file
86
README.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# Welcome to cap/samples
|
||||
|
||||
Find here a collection of samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) organized in a simplistic [monorepo setup](samples.md#all-in-one-monorepo). → See [**Overview** of contained samples](samples.md)
|
||||
|
||||

|
||||
[](https://api.reuse.software/info/github.com/SAP-samples/cloud-cap-samples)
|
||||
|
||||
### Preliminaries
|
||||
|
||||
1. Install [**@sap/cds-dk**](https://cap.cloud.sap/docs/get-started/) globally:
|
||||
|
||||
```sh
|
||||
npm i -g @sap/cds-dk
|
||||
```
|
||||
|
||||
2. _Optional:_ [Use Visual Studio Code](https://cap.cloud.sap/docs/get-started/tools#vscode)
|
||||
|
||||
### Download
|
||||
|
||||
If you've [Git](https://git-scm.com/downloads) installed, clone this repo as shown below, otherwise [download as ZIP file](archive/main.zip).
|
||||
|
||||
```sh
|
||||
git clone https://github.com/sap-samples/cloud-cap-samples samples
|
||||
cd samples
|
||||
```
|
||||
|
||||
### Setup
|
||||
|
||||
In the samples folder run:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
With that you're ready to run the samples, for example:
|
||||
|
||||
```sh
|
||||
cds watch bookshop
|
||||
```
|
||||
|
||||
After that open this link in your browser: [http://localhost:4004](http://localhost:4004)
|
||||
|
||||
When asked to log in, type `alice` as user and leave the password field blank, which is the [default user](https://cap.cloud.sap/docs/node.js/authentication#mocked).
|
||||
|
||||
### Testing
|
||||
|
||||
Run the provided tests with [_jest_](http://jestjs.io) or [_mocha_](http://mochajs.org), for example:
|
||||
|
||||
```sh
|
||||
npx jest
|
||||
```
|
||||
> While mocha is a bit smaller and faster, jest runs tests in parallel and isolation, which allows to run all tests.
|
||||
|
||||
|
||||
### Serve `npm`
|
||||
|
||||
We've included a simple npm registry mock, which allows you to do an `npm install @capire/<package>` locally. Use it as follows:
|
||||
|
||||
1. Start the @capire registry:
|
||||
```sh
|
||||
npm run registry
|
||||
```
|
||||
> While running this will have `@capire:registry=http://localhost:4444` set with npmrc.
|
||||
|
||||
2. Install one of the @capire packages wherever you like, for example:
|
||||
|
||||
```sh
|
||||
npm add @capire/common @capire/bookshop
|
||||
```
|
||||
|
||||
|
||||
## Code Tours
|
||||
|
||||
Take one of the [guided tours](.tours) in VS Code through our CAP samples and learn which CAP features are showcased by the different parts of the repository. Just install the [CodeTour extension](https://marketplace.visualstudio.com/items?itemName=vsls-contrib.codetour) for VS Code. We'll add more code tours in the future. Stay tuned!
|
||||
|
||||
## Get Support
|
||||
|
||||
Check out the documentation at [https://cap.cloud.sap](https://cap.cloud.sap). <br>
|
||||
In case you've a question, find a bug, or otherwise need support, use our [community](https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce) to get more visibility.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE.txt) file.
|
||||
2
bookshop/app/services.cds
Normal file
2
bookshop/app/services.cds
Normal file
@@ -0,0 +1,2 @@
|
||||
// Incorporate pre-build extensions from...
|
||||
using from '@capire/common';
|
||||
@@ -3,15 +3,14 @@ const $ = sel => document.querySelector(sel)
|
||||
const GET = (url) => axios.get('/browse'+url)
|
||||
const POST = (cmd,data) => axios.post('/browse'+cmd,data)
|
||||
|
||||
const books = Vue.createApp ({
|
||||
const books = new Vue ({
|
||||
|
||||
data() {
|
||||
return {
|
||||
el:'#app',
|
||||
|
||||
data: {
|
||||
list: [],
|
||||
book: undefined,
|
||||
order: { quantity:1, succeeded:'', failed:'' },
|
||||
user: undefined
|
||||
}
|
||||
order: { quantity:1, succeeded:'', failed:'' }
|
||||
},
|
||||
|
||||
methods: {
|
||||
@@ -19,7 +18,7 @@ const books = Vue.createApp ({
|
||||
search: ({target:{value:v}}) => books.fetch(v && '&$search='+v),
|
||||
|
||||
async fetch (etc='') {
|
||||
const {data} = await GET(`/ListOfBooks?$expand=genre($select=name),currency($select=symbol)${etc}`)
|
||||
const {data} = await GET(`/ListOfBooks?$expand=genre,currency${etc}`)
|
||||
books.list = data.value
|
||||
},
|
||||
|
||||
@@ -38,52 +37,12 @@ const books = Vue.createApp ({
|
||||
book.stock = res.data.stock
|
||||
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
|
||||
} catch (e) {
|
||||
books.order = { quantity, failed: e.response.data.error ? e.response.data.error.message : e.response.data }
|
||||
books.order = { quantity, failed: e.response.data.error.message }
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
async login() {
|
||||
try {
|
||||
const { data:user } = await axios.post('/user/login',{})
|
||||
if (user.id !== 'anonymous') books.user = user
|
||||
} catch (err) { books.user = { id: err.message } }
|
||||
},
|
||||
|
||||
async getUserInfo() {
|
||||
try {
|
||||
const { data:user } = await axios.get('/user/me')
|
||||
if (user.id !== 'anonymous') books.user = user
|
||||
} catch (err) { books.user = { id: err.message } }
|
||||
},
|
||||
}
|
||||
}).mount('#app')
|
||||
|
||||
books.getUserInfo()
|
||||
books.fetch() // initially fill list of books
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
// hide user info on request
|
||||
if (event.key === 'u') books.user = undefined
|
||||
})
|
||||
|
||||
axios.interceptors.request.use(csrfToken)
|
||||
function csrfToken (request) {
|
||||
if (request.method === 'head' || request.method === 'get') return request
|
||||
if ('csrfToken' in document) {
|
||||
request.headers['x-csrf-token'] = document.csrfToken
|
||||
return request
|
||||
}
|
||||
return fetchToken().then(token => {
|
||||
document.csrfToken = token
|
||||
request.headers['x-csrf-token'] = document.csrfToken
|
||||
return request
|
||||
}).catch(() => {
|
||||
document.csrfToken = null // set mark to not try again
|
||||
return request
|
||||
})
|
||||
|
||||
function fetchToken() {
|
||||
return axios.get('/', { headers: { 'x-csrf-token': 'fetch' } })
|
||||
.then(res => res.headers['x-csrf-token'])
|
||||
}
|
||||
}
|
||||
// initially fill list of books
|
||||
books.fetch()
|
||||
|
||||
@@ -3,34 +3,21 @@
|
||||
|
||||
<head>
|
||||
<title> Capire Books </title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/primitive-ui/dist/css/main.css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/primitive-ui/dist/css/main.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
||||
<style>
|
||||
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
||||
.rating-stars { color:teal }
|
||||
.succeeded { color:teal }
|
||||
.failed { color:red }
|
||||
.user {text-align: end; color: grey;}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="small-container", style="margin-top: 70px;">
|
||||
<div id='app'>
|
||||
|
||||
<form class="user" @submit.prevent="login">
|
||||
<div v-if="user">
|
||||
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
|
||||
<div> User: {{ user.id }}</div>
|
||||
<div>Locale: {{ user.locale }}</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<input type="submit" value="Login" class="muted-button">
|
||||
<!-- <a href="/user/login()">Login</a> -->
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h1> Capire Books </h1>
|
||||
<h1> {{ document.title }} </h1>
|
||||
|
||||
<input type="text" placeholder="Search..." @input="search">
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
ID,name,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"
|
||||
ID;name;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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
ID,title,descr,author_ID,stock,price,currency_code,genre_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,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
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,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
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,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
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,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
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,150,JPY,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
ID;title;descr;author_ID;stock;price;currency_code;genre_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;11
|
||||
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;11
|
||||
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;16
|
||||
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;16
|
||||
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;150;JPY;13
|
||||
|
@@ -1,5 +0,0 @@
|
||||
ID_texts,ID,locale,title,descr
|
||||
d2a65a27-9f2a-480f-bc38-84ee8ec5c13e,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."
|
||||
8c42c706-a979-41cf-9ffe-91e6cf1383a0,201,fr,Les Hauts de Hurlevent,"Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal."
|
||||
9e1c4c81-dc90-4600-85b1-e9dd4bf12ce0,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"
|
||||
9be0524b-4cb9-4fc1-9dc2-d65b1c13cf53,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."
|
||||
|
5
bookshop/db/data/sap.capire.bookshop-Books_texts.csv
Normal file
5
bookshop/db/data/sap.capire.bookshop-Books_texts.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
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.
|
||||
201;fr;Les Hauts de Hurlevent;Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal.
|
||||
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.
|
||||
|
@@ -1,43 +1,16 @@
|
||||
ID,parent_ID,name
|
||||
10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Fiction
|
||||
11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Drama
|
||||
12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Poetry
|
||||
13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fantasy
|
||||
131aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fairy Tale
|
||||
132aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Epic Fantasy
|
||||
133aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,High Fantasy
|
||||
134aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Gothic
|
||||
14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Science Fiction
|
||||
141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian and Dystopian
|
||||
1411aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian
|
||||
1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Dystopian
|
||||
14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cyberpunk
|
||||
141211aa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Steampunk
|
||||
142aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Space Opera
|
||||
143aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Time Travel
|
||||
144aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tech Noir
|
||||
15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romance
|
||||
151aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Contemporary Romance
|
||||
152aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Historical Romance
|
||||
153aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romantic Suspense
|
||||
16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Mystery
|
||||
161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Crime
|
||||
1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Thriller
|
||||
16111aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Police Procedural
|
||||
16112aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Legal Thriller
|
||||
16113aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Medical Thriller
|
||||
16114aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Spy Thriller
|
||||
1612aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Detective
|
||||
1613aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Suspense
|
||||
162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Noir
|
||||
1621aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Nordic Noir
|
||||
1622aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tart Noir
|
||||
163aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cozy Mystery
|
||||
17aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Adventure
|
||||
18aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Short Story
|
||||
19aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Graphic Novel
|
||||
20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Non-Fiction
|
||||
21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Biography
|
||||
22aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Autobiography
|
||||
23aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Essay
|
||||
24aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Speech
|
||||
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;21;Autobiography
|
||||
23;20;Essay
|
||||
24;20;Speech
|
||||
|
||||
|
@@ -1,21 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
|
||||
/**
|
||||
* In order to keep basic bookshop sample as simple as possible, we don't add
|
||||
* reuse dependencies. This db/init.js ensures we still have a minimum set of
|
||||
* currencies, if not obtained through @capire/common.
|
||||
*/
|
||||
|
||||
// NOTE: We use cds.on('served') to delay the UPSERTs after the db init
|
||||
// to run after all INSERTs from .csv files happened.
|
||||
module.exports = cds.on('served', ()=>
|
||||
UPSERT.into ('sap.common.Currencies') .columns (
|
||||
[ 'code', 'symbol', 'name' ]
|
||||
) .rows (
|
||||
[ 'EUR', '€', 'Euro' ],
|
||||
[ 'USD', '$', 'US Dollar' ],
|
||||
[ 'GBP', '£', 'British Pound' ],
|
||||
[ 'ILS', '₪', 'Shekel' ],
|
||||
[ 'JPY', '¥', 'Yen' ],
|
||||
)
|
||||
)
|
||||
@@ -2,37 +2,30 @@ using { Currency, managed, sap } from '@sap/cds/common';
|
||||
namespace sap.capire.bookshop;
|
||||
|
||||
entity Books : managed {
|
||||
key ID : Integer;
|
||||
title : localized String(111) @mandatory;
|
||||
descr : localized String(1111);
|
||||
author : Association to Authors @mandatory;
|
||||
genre : Association to Genres;
|
||||
stock : Integer;
|
||||
price : Price;
|
||||
key ID : Integer;
|
||||
title : localized String(111);
|
||||
descr : localized String(1111);
|
||||
author : Association to Authors;
|
||||
genre : Association to Genres;
|
||||
stock : Integer;
|
||||
price : Decimal;
|
||||
currency : Currency;
|
||||
image : LargeBinary @Core.MediaType: 'image/png';
|
||||
image : LargeBinary @Core.MediaType : 'image/png';
|
||||
}
|
||||
|
||||
entity Authors : managed {
|
||||
key ID : Integer;
|
||||
name : String(111) @mandatory;
|
||||
key ID : Integer;
|
||||
name : String(111);
|
||||
dateOfBirth : Date;
|
||||
dateOfDeath : Date;
|
||||
placeOfBirth : String;
|
||||
placeOfDeath : String;
|
||||
books : Association to many Books on books.author = $self;
|
||||
books : Association to many Books on books.author = $self;
|
||||
}
|
||||
|
||||
/** Hierarchically organized Code List for Genres */
|
||||
entity Genres : sap.common.CodeList {
|
||||
key ID : UUID;
|
||||
key ID : Integer;
|
||||
parent : Association to Genres;
|
||||
children : Composition of many Genres on children.parent = $self;
|
||||
}
|
||||
|
||||
type Price : Decimal(9,2);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// temporary workaround for reuse in fiori sample and hana deployment
|
||||
annotate Books with @fiori.draft.enabled;
|
||||
|
||||
@@ -2,4 +2,3 @@ namespace sap.capire.bookshop; //> important for reflection
|
||||
using from './db/schema';
|
||||
using from './srv/cat-service';
|
||||
using from './srv/admin-service';
|
||||
using from './srv/user-service';
|
||||
|
||||
2
bookshop/index.js
Normal file
2
bookshop/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const { CatalogService } = require('./srv/cat-service')
|
||||
module.exports = { CatalogService }
|
||||
@@ -2,22 +2,22 @@
|
||||
"name": "@capire/bookshop",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple self-contained bookshop service.",
|
||||
"files": [
|
||||
"app",
|
||||
"srv",
|
||||
"db",
|
||||
"index.cds"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@cap-js/sqlite": ">=1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=7",
|
||||
"express": "^4.17.1"
|
||||
"@capire/common": "*",
|
||||
"@sap/cds": "^5.0.4",
|
||||
"express": "^4.17.1",
|
||||
"passport": "0.4.1"
|
||||
},
|
||||
"scripts": {
|
||||
"genres": "cds serve test/genres.cds",
|
||||
"start": "cds-serve",
|
||||
"start": "cds run",
|
||||
"watch": "cds watch"
|
||||
},
|
||||
"cds": {
|
||||
"requires": {
|
||||
"db": {
|
||||
"kind": "sql"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ npm run watch
|
||||
|
||||
| Links to capire | Sample files / folders |
|
||||
| --------------------------------------------------------------------------------------------------------- | ------------------------------------ |
|
||||
| [Project Setup & Layouts](https://cap.cloud.sap/docs/get-started/jumpstart#project-structure) | [`./`](./) |
|
||||
| [Domain Modeling with CDS](https://cap.cloud.sap/docs/guides/domain-modeling) | [`./db/schema.cds`](./db/schema.cds) |
|
||||
| [Defining Services](https://cap.cloud.sap/docs/guides/providing-services#modeling-services) | [`./srv/*.cds`](./srv) |
|
||||
| [Single-purposed Services](https://cap.cloud.sap/docs/guides/providing-services#single-purposed-services) | [`./srv/*.cds`](./srv) |
|
||||
| [Project Setup & Layouts](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content) | [`./`](./) |
|
||||
| [Domain Modeling with CDS](https://cap.cloud.sap/docs/guides/domain-models) | [`./db/schema.cds`](./db/schema.cds) |
|
||||
| [Defining Services](https://cap.cloud.sap/docs/guides/services#defining-services) | [`./srv/*.cds`](./srv) |
|
||||
| [Single-purposed Services](https://cap.cloud.sap/docs/guides/services#single-purposed-services) | [`./srv/*.cds`](./srv) |
|
||||
| [Providing & Consuming Providers](https://cap.cloud.sap/docs/guides/providing-services) | 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/providing-services#adding-custom-logic) | [`./srv/*.js`](./srv) |
|
||||
| [Adding Custom Logic](https://cap.cloud.sap/docs/guides/service-impl) | [`./srv/*.js`](./srv) |
|
||||
| Adding Tests | [`./test`](./test) |
|
||||
| [Sharing for Reuse](https://cap.cloud.sap/docs/guides/extensibility/composition) | [`./index.cds`](./index.cds) |
|
||||
| [Sharing for Reuse](https://cap.cloud.sap/docs/guides/reuse-and-compose) | [`./index.cds`](./index.cds) |
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
using { AdminService } from './admin-service';
|
||||
annotate AdminService with @requires:'admin';
|
||||
@@ -1,6 +1,5 @@
|
||||
using { sap.capire.bookshop as my } from '../db/schema';
|
||||
service AdminService @(path:'/admin') {
|
||||
entity Authors as projection on my.Authors;
|
||||
service AdminService @(requires:'admin') {
|
||||
entity Books as projection on my.Books;
|
||||
entity Genres as projection on my.Genres;
|
||||
entity Authors as projection on my.Authors;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
const cds = require('@sap/cds')
|
||||
|
||||
module.exports = class AdminService extends cds.ApplicationService { init(){
|
||||
this.before (['NEW','CREATE'],'Authors', genid)
|
||||
this.before (['NEW','CREATE'],'Books', genid)
|
||||
return super.init()
|
||||
}}
|
||||
module.exports = cds.service.impl (function(){
|
||||
this.before ('NEW','Authors', genid)
|
||||
this.before ('NEW','Books', genid)
|
||||
})
|
||||
|
||||
/** Generate primary keys for target entity in request */
|
||||
async function genid (req) {
|
||||
if (req.data.ID) return
|
||||
const {id} = await SELECT.one.from(req.target).columns('max(ID) as id')
|
||||
req.data.ID = id + 4 // Note: that is not safe! ok for this sample only.
|
||||
const {ID} = await cds.tx(req).run (SELECT.one.from(req.target).columns('max(ID) as ID'))
|
||||
req.data.ID = ID - ID % 100 + 100 + 1
|
||||
}
|
||||
|
||||
@@ -1,38 +1,27 @@
|
||||
const cds = require('@sap/cds')
|
||||
|
||||
class CatalogService extends cds.ApplicationService { init() {
|
||||
class CatalogService extends cds.ApplicationService { init(){
|
||||
|
||||
const { Books } = cds.entities('sap.capire.bookshop')
|
||||
const { ListOfBooks } = this.entities
|
||||
|
||||
// Add some discount for overstocked books
|
||||
this.after('each', ListOfBooks, book => {
|
||||
if (book.stock > 111) book.title += ` -- 11% discount!`
|
||||
})
|
||||
const { Books } = cds.entities ('sap.capire.bookshop')
|
||||
|
||||
// Reduce stock of ordered books if available stock suffices
|
||||
this.on('submitOrder', async req => {
|
||||
let { book:id, quantity } = req.data
|
||||
let book = await SELECT.from (Books, id, b => b.stock)
|
||||
|
||||
// Validate input data
|
||||
if (!book) return req.error (404, `Book #${id} doesn't exist`)
|
||||
if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
|
||||
if (quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`)
|
||||
|
||||
// Reduce stock in database and return updated stock value
|
||||
await UPDATE (Books, id) .with ({ stock: book.stock -= quantity })
|
||||
return book
|
||||
this.on ('submitOrder', async req => {
|
||||
const {book,quantity} = req.data
|
||||
let {stock} = await SELECT `stock` .from (Books,book)
|
||||
if (stock >= quantity) {
|
||||
await UPDATE (Books,book) .with (`stock -=`, quantity)
|
||||
await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id })
|
||||
return { stock }
|
||||
}
|
||||
else return req.error (409,`${quantity} exceeds stock for book #${book}`)
|
||||
})
|
||||
|
||||
// Emit event when an order has been submitted
|
||||
this.after('submitOrder', async (_,req) => {
|
||||
let { book, quantity } = req.data
|
||||
await this.emit('OrderedBook', { book, quantity, buyer: req.user.id })
|
||||
// Add some discount for overstocked books
|
||||
this.after ('READ','ListOfBooks', each => {
|
||||
if (each.stock > 111) each.title += ` -- 11% discount!`
|
||||
})
|
||||
|
||||
// Delegate requests to the underlying generic service
|
||||
return super.init()
|
||||
}}
|
||||
|
||||
module.exports = CatalogService
|
||||
module.exports = { CatalogService }
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Exposes user information
|
||||
*/
|
||||
service UserService @(path: '/user') {
|
||||
/**
|
||||
* The current user
|
||||
*/
|
||||
@odata.singleton entity me @cds.persistence.skip {
|
||||
id : String; // user id
|
||||
locale : String;
|
||||
tenant : String;
|
||||
}
|
||||
|
||||
action login() returns me;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
module.exports = class UserService extends cds.Service { init(){
|
||||
this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
|
||||
this.on('login', (req) => {
|
||||
if (req.user._is_anonymous)
|
||||
req._.res.set('WWW-Authenticate','Basic realm="Users"').sendStatus(401)
|
||||
else return this.read('me')
|
||||
})
|
||||
}}
|
||||
@@ -1,53 +0,0 @@
|
||||
const cds = require("@sap/cds");
|
||||
const { expect } = cds.test(
|
||||
"serve",
|
||||
"CatalogService",
|
||||
"--from",
|
||||
"@capire/bookshop,@capire/common",
|
||||
"--in-memory"
|
||||
);
|
||||
|
||||
describe("Consuming actions locally", () => {
|
||||
let cats, CatalogService, Books, stockBefore;
|
||||
const BOOK_ID = 251;
|
||||
const QUANTITY = 1;
|
||||
|
||||
before("bootstrap the database", async () => {
|
||||
CatalogService = cds.services.CatalogService;
|
||||
expect(CatalogService).not.to.be.undefined;
|
||||
|
||||
Books = CatalogService.entities.Books;
|
||||
expect(Books).not.to.be.undefined;
|
||||
|
||||
cats = await cds.connect.to("CatalogService");
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
// Read the stock before the action is called
|
||||
stockBefore = (await cats.get(Books, BOOK_ID)).stock;
|
||||
});
|
||||
|
||||
it("calls unbound actions - basic variant using srv.send", async () => {
|
||||
// Use a managed transaction to create a continuation with an authenticated user
|
||||
const res1 = await cats.tx({ user: "alice" }, () => {
|
||||
return cats.send("submitOrder", { book: BOOK_ID, quantity: QUANTITY });
|
||||
});
|
||||
expect(res1.stock).to.eql(stockBefore - QUANTITY);
|
||||
});
|
||||
|
||||
it("calls unbound actions - named args variant", async () => {
|
||||
// Use a managed transaction to create a continuation with an authenticated user
|
||||
const res2 = await cats.tx({ user: "alice" }, () => {
|
||||
return cats.submitOrder({ book: BOOK_ID, quantity: QUANTITY });
|
||||
});
|
||||
expect(res2.stock).to.eql(stockBefore - QUANTITY);
|
||||
});
|
||||
|
||||
it("calls unbound actions - positional args variant", async () => {
|
||||
// Use a managed transaction to create a continuation with an authenticated user
|
||||
const res3 = await cats.tx({ user: "alice" }, () => {
|
||||
return cats.submitOrder(BOOK_ID, QUANTITY);
|
||||
});
|
||||
expect(res3.stock).to.eql(stockBefore - QUANTITY);
|
||||
});
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
const { GET, POST, expect } = cds.test(__dirname+'/..')
|
||||
cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||
|
||||
describe('cap/samples - Custom Handlers', () => {
|
||||
|
||||
it('should reject out-of-stock orders', async () => {
|
||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
|
||||
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.rejectedWith(
|
||||
/409 - 5 exceeds stock for book #201/)
|
||||
const { data } = await GET`/admin/Books/201/stock/$value`
|
||||
expect(data).to.equal(2)
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
using { sap.capire.bookshop as my } from '../../db/schema';
|
||||
using { sap.capire.bookshop as my } from '../db/schema';
|
||||
service TestService {
|
||||
entity Genres as projection on my.Genres;
|
||||
}
|
||||
38
bookshop/test/genres.http
Normal file
38
bookshop/test/genres.http
Normal file
@@ -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)
|
||||
###
|
||||
@@ -1,123 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
const { expect } = cds.test.in(__dirname,'..','..')
|
||||
|
||||
describe('cap/samples - Hierarchical Data', ()=>{
|
||||
|
||||
const csn = CDL`
|
||||
entity Categories {
|
||||
key ID : Integer;
|
||||
name : String;
|
||||
children : Composition of many Categories on children.parent = $self;
|
||||
parent : Association to Categories;
|
||||
}
|
||||
`
|
||||
const model = cds.compile.for.nodejs(csn)
|
||||
const {Categories:Cats} = model.definitions
|
||||
|
||||
before ('bootstrap sqlite in-memory db...', async()=>{
|
||||
await cds.deploy (csn) .to ('sqlite::memory:') // REVISIT: cds.compile.to.sql should accept cds.compiled.for.nodejs models
|
||||
expect (cds.db) .to.exist
|
||||
expect (cds.db.model) .to.exist
|
||||
})
|
||||
|
||||
it ('supports deeply nested inserts', ()=> INSERT.into (Cats,
|
||||
{ ID:100, name:'Some Cats...', children:[
|
||||
{ ID:101, name:'Cat', children:[
|
||||
{ ID:102, name:'Kitty', children:[
|
||||
{ ID:103, name:'Kitty Cat', children:[
|
||||
{ ID:104, name:'Aristocat' } ]},
|
||||
{ ID:105, name:'Kitty Bat' } ]},
|
||||
{ ID:106, name:'Catwoman', children:[
|
||||
{ ID:107, name:'Catalina' } ]} ]},
|
||||
{ ID:108, name:'Catweazle' }
|
||||
]}
|
||||
))
|
||||
|
||||
it ('should generate correct queries for expands', ()=>{
|
||||
let q = SELECT.from (Cats, c => { c.ID, c.name, c.children (c => c.name) })
|
||||
expect (q) .to.eql ({
|
||||
SELECT: {
|
||||
from: { ref:[ "Categories" ] },
|
||||
columns: [
|
||||
{ ref: [ "ID" ] },
|
||||
{ ref: [ "name" ] },
|
||||
{ ref: [ "children" ], expand: [ {ref:['name']} ] },
|
||||
]
|
||||
}
|
||||
})
|
||||
/* temp skip for release
|
||||
if (q.forSQL) expect (q.forSQL()) .to.eql ({
|
||||
SELECT: {
|
||||
from: { ref:[ "Categories" ], as: "Categories" },
|
||||
columns: [
|
||||
{ ref: [ "Categories", "ID" ] },
|
||||
{ ref: [ "Categories", "name" ] },
|
||||
{ as: "children", SELECT: { expand: true,
|
||||
one: false,
|
||||
columns: [{ ref: [ "children", "name" ]}],
|
||||
from: { ref:["Categories"], as: "children" },
|
||||
where: [
|
||||
{ref:[ "Categories", "ID" ]}, "=", {ref:[ "children", "parent_ID" ]}
|
||||
],
|
||||
}},
|
||||
],
|
||||
}
|
||||
})
|
||||
if (q.toSql) expect (q.toSql()) .to.eql (
|
||||
`SELECT json_insert('{}',` +
|
||||
`'$."ID"',ID,` +
|
||||
`'$."name"',name,` +
|
||||
`'$."children"',children->'$'` +
|
||||
`) as _json_ FROM (` +
|
||||
`SELECT Categories.ID,Categories.name,(` +
|
||||
`SELECT jsonb_group_array(jsonb_insert('{}','$."name"',name)) as _json_ FROM (` +
|
||||
`SELECT children.name FROM Categories as children WHERE Categories.ID = children.parent_ID` +
|
||||
`)` +
|
||||
`) as children FROM Categories as Categories` +
|
||||
`)`
|
||||
)
|
||||
*/
|
||||
})
|
||||
|
||||
it ('supports nested reads', ()=> expect (
|
||||
SELECT.one.from (Cats, c=>{
|
||||
c.ID, c.name.as('parent'), c.children (c=>{
|
||||
c.name.as('child')
|
||||
})
|
||||
}) .where ({name:'Cat'})
|
||||
) .to.eventually.eql (
|
||||
{ ID:101, parent:'Cat', children:[
|
||||
{ child:'Kitty' },
|
||||
{ child:'Catwoman' },
|
||||
]}
|
||||
))
|
||||
|
||||
it ('supports deeply nested reads', ()=> expect (
|
||||
SELECT.one.from (Cats, c=>{
|
||||
c.ID, c.name, c.children (
|
||||
c => { c.name },
|
||||
{levels:3}
|
||||
)
|
||||
}) .where ({name:'Cat'})
|
||||
) .to.eventually.eql (
|
||||
{ ID:101, name:'Cat', children:[
|
||||
{ name:'Kitty', children:[
|
||||
{ name:'Kitty Cat', children:[
|
||||
{ name:'Aristocat' }, ]}, // level 3
|
||||
{ name:'Kitty Bat', children:[] }, ]},
|
||||
{ name:'Catwoman', children:[
|
||||
{ name:'Catalina', children:[] } ]},
|
||||
]}
|
||||
))
|
||||
|
||||
it ('supports cascaded deletes', async()=>{
|
||||
const affectedRows = await DELETE.from (Cats) .where ({ID:[102,106]})
|
||||
expect (affectedRows) .to.be.greaterThan (0)
|
||||
await expect (SELECT`ID,name`.from(Cats) ).to.eventually.eql ([
|
||||
{ ID:100, name:'Some Cats...' },
|
||||
{ ID:101, name:'Cat' },
|
||||
{ ID:108, name:'Catweazle' }
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
@@ -1,37 +0,0 @@
|
||||
#################################################
|
||||
#
|
||||
# Genres
|
||||
#
|
||||
|
||||
GET http://localhost:4004/odata/v4/test/Genres?
|
||||
###
|
||||
|
||||
GET http://localhost:4004/odata/v4/test/Genres?
|
||||
&$filter=parent_ID eq null&$select=name
|
||||
&$expand=children($select=name)
|
||||
###
|
||||
|
||||
POST http://localhost:4004/odata/v4/test/Genres?
|
||||
Content-Type: application/json
|
||||
|
||||
{ "ID":"100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Some Sample Genres...", "children":[
|
||||
{ "ID":"101aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Cat", "children":[
|
||||
{ "ID":"102aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty", "children":[
|
||||
{ "ID":"103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Aristocat" },
|
||||
{ "ID":"104aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty Bat" } ]},
|
||||
{ "ID":"105aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catwoman", "children":[
|
||||
{ "ID":"106aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catalina" } ]} ]},
|
||||
{ "ID":"107aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catweazle" }
|
||||
]}
|
||||
###
|
||||
|
||||
GET http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)?
|
||||
&$expand=children
|
||||
&$expand=children($expand=children($expand=children($expand=children)))
|
||||
###
|
||||
|
||||
DELETE http://localhost:4004/odata/v4/test/Genres(103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
|
||||
###
|
||||
|
||||
DELETE http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
|
||||
###
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@cap-js/sqlite": "*"
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
||||
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
||||
|
||||
describe('cap/samples - Bookshop APIs', () => {
|
||||
|
||||
it('serves $metadata documents in v4', async () => {
|
||||
const { headers, status, data } = await GET `/browse/$metadata`
|
||||
expect(status).to.equal(200)
|
||||
expect(headers).to.contain({
|
||||
// 'content-type': 'application/xml', //> fails with 'application/xml;charset=utf-8', which is set by express
|
||||
'odata-version': '4.0',
|
||||
})
|
||||
expect(headers['content-type']).to.match(/application\/xml/)
|
||||
expect(data).to.contain('<EntitySet Name="Books" EntityType="CatalogService.Books">')
|
||||
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency"/>')
|
||||
})
|
||||
|
||||
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
||||
const Mystery = { name: 'Mystery' }
|
||||
const Romance = { name: 'Romance' }
|
||||
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
|
||||
const { data } = await GET `/browse/ListOfBooks ${{
|
||||
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
||||
}}`
|
||||
expect(data.value).to.containSubset([
|
||||
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
|
||||
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe', genre:Romance, currency:USD },
|
||||
])
|
||||
})
|
||||
|
||||
describe('query options...', () => {
|
||||
|
||||
it('supports $search in multiple fields', async () => {
|
||||
const { data } = await GET `/browse/Books ${{
|
||||
params: { $search: 'Po', $select: `title,author` },
|
||||
}}`
|
||||
expect(data.value).to.containSubset([
|
||||
{ ID: 201, title: 'Wuthering Heights', author: 'Emily Brontë' },
|
||||
{ ID: 207, title: 'Jane Eyre', author: 'Charlotte Brontë' },
|
||||
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe' },
|
||||
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe' },
|
||||
])
|
||||
})
|
||||
|
||||
it('supports $select', async () => {
|
||||
const { data } = await GET(`/browse/Books`, {
|
||||
params: { $select: `ID,title` },
|
||||
})
|
||||
expect(data.value).to.containSubset([
|
||||
{ ID: 201, title: 'Wuthering Heights' },
|
||||
{ ID: 207, title: 'Jane Eyre' },
|
||||
{ ID: 251, title: 'The Raven' },
|
||||
{ ID: 252, title: 'Eleonora' },
|
||||
{ ID: 271, title: 'Catweazle' },
|
||||
])
|
||||
})
|
||||
|
||||
it('supports $expand', async () => {
|
||||
const { data } = await GET(`/admin/Authors`, {
|
||||
params: {
|
||||
$select: `name`,
|
||||
$expand: `books($select=title)`,
|
||||
},
|
||||
})
|
||||
expect(data.value).to.containSubset([
|
||||
{ name: 'Emily Brontë', books: [{ title: 'Wuthering Heights' }] },
|
||||
{ name: 'Charlotte Brontë', books: [{ title: 'Jane Eyre' }] },
|
||||
{ name: 'Edgar Allen Poe', books: [{ title: 'The Raven' }, { title: 'Eleonora' }] },
|
||||
{ name: 'Richard Carpenter', books: [{ title: 'Catweazle' }] },
|
||||
])
|
||||
})
|
||||
|
||||
it('supports $value requests', async () => {
|
||||
const { data } = await GET`/admin/Books/201/stock/$value`
|
||||
expect(data).to.equal(12)
|
||||
})
|
||||
|
||||
it('supports $top/$skip paging', async () => {
|
||||
const { data: p1 } = await GET`/browse/Books?$select=title&$top=3`
|
||||
expect(p1.value).to.containSubset([
|
||||
{ ID: 201, title: 'Wuthering Heights' },
|
||||
{ ID: 207, title: 'Jane Eyre' },
|
||||
{ ID: 251, title: 'The Raven' },
|
||||
])
|
||||
const { data: p2 } = await GET`/browse/Books?$select=title&$skip=3`
|
||||
expect(p2.value).to.containSubset([
|
||||
{ ID: 252, title: 'Eleonora' },
|
||||
{ ID: 271, title: 'Catweazle' },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('serves user info', async () => {
|
||||
const { data: alice } = await GET `/user/me`
|
||||
expect(alice).to.containSubset({ id: 'alice' })
|
||||
const { data: joe } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
||||
expect(joe).to.containSubset({ id: 'joe' })
|
||||
})
|
||||
|
||||
})
|
||||
@@ -1,126 +0,0 @@
|
||||
const cds = require('@sap/cds/lib')
|
||||
const { GET, expect, axios } = cds.test(__dirname)
|
||||
|
||||
// Fetch API disallows GET|HEAD requests with body
|
||||
if (axios.constructor.name === 'Naxios') it = it.skip
|
||||
|
||||
describe ('GET w/ query in body', () => {
|
||||
|
||||
it ('serves CQN query objects in body', async () => {
|
||||
const {data:books} = await GET ('/hcql/admin', {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
data: cds.ql `SELECT from Books`
|
||||
})
|
||||
expect(books).to.be.an('array').of.length(5)
|
||||
})
|
||||
|
||||
it ('serves plain CQL strings in body', async () => {
|
||||
const {data:books} = await GET ('/hcql/admin', {
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
data: `SELECT from Books`
|
||||
})
|
||||
expect(books).to.be.an('array').of.length(5)
|
||||
})
|
||||
|
||||
it ('serves complex and deep queries', async () => {
|
||||
const {data:books} = await GET ('/hcql/admin', {
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
data: `SELECT from Authors {
|
||||
name,
|
||||
books [order by title] {
|
||||
title,
|
||||
genre.name as genre
|
||||
}
|
||||
}`
|
||||
})
|
||||
expect(books).to.deep.equal([
|
||||
{
|
||||
name: "Emily Brontë",
|
||||
books: [
|
||||
{ title: "Wuthering Heights", genre: 'Drama' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Charlotte Brontë",
|
||||
books: [
|
||||
{ title: "Jane Eyre", genre: 'Drama' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Edgar Allen Poe",
|
||||
books: [
|
||||
{ title: "Eleonora", genre: 'Romance' },
|
||||
{ title: "The Raven", genre: 'Mystery' },
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Richard Carpenter",
|
||||
books: [
|
||||
{ title: "Catweazle", genre: 'Fantasy' }
|
||||
]
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
describe ('Sluggified variants', () => {
|
||||
|
||||
test ('GET /Books', async () => {
|
||||
const {data:books} = await GET ('/hcql/admin/Books')
|
||||
expect(books).to.be.an('array').of.length(5)
|
||||
expect(books.length).to.eql(5) //.of.length(5)
|
||||
})
|
||||
|
||||
|
||||
test ('GET /Books/201', async () => {
|
||||
const {data:book} = await GET ('/hcql/admin/Books/201')
|
||||
expect(book).to.be.an('object')
|
||||
expect(book).to.have.property ('title', "Wuthering Heights")
|
||||
})
|
||||
|
||||
test ('GET /Books { title, author.name as author }' , async () => {
|
||||
const {data:books} = await GET ('/hcql/admin/Books { title, author.name as author } order by ID')
|
||||
expect(books).to.deep.equal ([
|
||||
{ title: "Wuthering Heights", author: "Emily Brontë" },
|
||||
{ title: "Jane Eyre", author: "Charlotte Brontë" },
|
||||
{ title: "The Raven", author: "Edgar Allen Poe" },
|
||||
{ title: "Eleonora", author: "Edgar Allen Poe" },
|
||||
{ title: "Catweazle", author: "Richard Carpenter" }
|
||||
])
|
||||
})
|
||||
|
||||
test ('GET /Books/201 w/ CQL tail in URL' , async () => {
|
||||
const {data:book} = await GET ('/hcql/admin/Books/201 { title, author.name as author } order by ID')
|
||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
||||
})
|
||||
|
||||
it ('GET /Books/201 w/ CQL fragment in body' , async () => {
|
||||
const {data:book} = await GET ('/hcql/admin/Books/201', {
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
data: `{ title, author.name as author }`
|
||||
})
|
||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
||||
})
|
||||
|
||||
it ('GET /Books/201 w/ CQN fragment in body' , async () => {
|
||||
const {data:book} = await GET ('/hcql/admin/Books/201', {
|
||||
data: cds.ql `SELECT title, author.name as author` .SELECT
|
||||
})
|
||||
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
||||
})
|
||||
|
||||
it ('GET /Books/201 w/ tail in URL plus CQL/CQN fragments in body' , async () => {
|
||||
const {data:[b1]} = await GET ('/hcql/admin/Books where ID=201', {
|
||||
data: cds.ql `SELECT title, author.name as author` .SELECT
|
||||
})
|
||||
expect(b1).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
||||
const {data:[b2]} = await GET ('/hcql/admin/Books where ID=201', {
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
data: `{ title, author.name as author }`
|
||||
})
|
||||
expect(b2).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
|
||||
})
|
||||
|
||||
})
|
||||
@@ -1,225 +0,0 @@
|
||||
@server = http://localhost:4004
|
||||
|
||||
GET {{server}}/odata/v4/admin/Authors?
|
||||
&$select=ID,name
|
||||
&$expand=books($select=ID,title)
|
||||
&$count=true
|
||||
###
|
||||
|
||||
#
|
||||
# The basic variant expects a CQN object passed as an application/json body
|
||||
# to a POST request. This is also the fastest one, as it doesn't need CQL parsing.
|
||||
# Note: $count is returned in X-Total-Count response header
|
||||
#
|
||||
GET {{server}}/hcql/admin
|
||||
Content-Type: application/json
|
||||
# Accept-Language: de
|
||||
|
||||
{ "SELECT": {
|
||||
"from": { "ref": [ "Authors" ] },
|
||||
"columns": [
|
||||
{ "ref": [ "name" ] },
|
||||
{ "ref": [ "books" ], "expand": [
|
||||
{ "ref": [ "ID" ] },
|
||||
{ "ref": [ "title" ] }
|
||||
]}
|
||||
],
|
||||
"count": true
|
||||
}}
|
||||
###
|
||||
|
||||
POST {{server}}/hcql/browse/submitOrder?book=201&quantity=2
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
POST {{server}}/hcql/browse/submitOrder
|
||||
Authorization: Basic alice:
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"book": 201,
|
||||
"quantity": 2
|
||||
}
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/browse/submitOrder?book=201&quantity=2
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
#
|
||||
# Alternatively you can pass a CQL string as plain/text body
|
||||
#
|
||||
GET {{server}}/hcql/admin
|
||||
Content-Type: text/plain
|
||||
# X-Total-Count: true
|
||||
|
||||
SELECT from Authors { name, books { title }}
|
||||
# SELECT from Books { title, currency }
|
||||
###
|
||||
|
||||
#
|
||||
# In addition we offer convenience slug routes...
|
||||
# .e.g. /srv/entity routes
|
||||
#
|
||||
|
||||
|
||||
GET {{server}}/hcql/admin/Books
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books/201
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books { ID, title, author.name as author }
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books order by stock desc
|
||||
Content-Type: text/plain
|
||||
|
||||
{ title, stock }
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books/201 { ID, title, author.name }
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books/201 { ID, title, author{name} }
|
||||
###
|
||||
|
||||
|
||||
POST {{server}}/hcql/admin/Books?title=The Black Cat&author_ID=101
|
||||
###
|
||||
|
||||
|
||||
POST {{server}}/hcql/admin/Books?title=The Black Cat
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"author_ID": 101
|
||||
}
|
||||
###
|
||||
|
||||
POST {{server}}/hcql/admin/Books
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": "The Black Cat",
|
||||
"author": { "ID": 101 }
|
||||
}
|
||||
###
|
||||
|
||||
PUT {{server}}/hcql/admin/Books/275?title=Catastrophe
|
||||
###
|
||||
|
||||
PATCH {{server}}/hcql/admin/Books/275
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": "Catastrophe"
|
||||
}
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Authors { name, books { ID, title }}
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books { ID, title, author.name as author } order by ID desc
|
||||
###
|
||||
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
POST {{server}}/hcql/admin
|
||||
Content-Type: application/json
|
||||
|
||||
{"SELECT": { "from": { "ref": ["Books"] }}}
|
||||
###
|
||||
|
||||
POST {{server}}/hcql/admin
|
||||
Content-Type: text/plain
|
||||
|
||||
SELECT from Authors {
|
||||
name as author,
|
||||
books {
|
||||
title,
|
||||
stock,
|
||||
price,
|
||||
currency { * }
|
||||
}
|
||||
}
|
||||
where name like '%Bro%'
|
||||
order by name asc
|
||||
###
|
||||
|
||||
|
||||
#
|
||||
# Simple REST-style URLs as supported as well
|
||||
#
|
||||
|
||||
GET {{server}}/hcql/admin/Books
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books/201
|
||||
###
|
||||
|
||||
|
||||
#
|
||||
# REST-style URLs can be combined with trailing CQL in the path, in plain
|
||||
# text body, or with projections sent as application/json array
|
||||
#
|
||||
|
||||
GET {{server}}/hcql/admin/Books order by stock desc
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books { title as book, stock } order by stock desc
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Authors
|
||||
Content-Type: text/plain
|
||||
Accept-Language: fr
|
||||
|
||||
{
|
||||
ID, name as author,
|
||||
books {
|
||||
title,
|
||||
stock,
|
||||
currency { * }
|
||||
}
|
||||
}
|
||||
where name like '%Bro%'
|
||||
order by name asc
|
||||
###
|
||||
|
||||
|
||||
GET {{server}}/hcql/admin/Books/201 { title, stock }
|
||||
###
|
||||
|
||||
GET {{server}}/hcql/admin/Books order by stock desc
|
||||
Content-Type: text/plain
|
||||
|
||||
{ title, stock }
|
||||
###
|
||||
|
||||
|
||||
#
|
||||
# CQL adaptor also provides access to the underlying CSN schema
|
||||
#
|
||||
|
||||
GET {{server}}/hcql/admin/$csn
|
||||
###
|
||||
|
||||
|
||||
|
||||
#
|
||||
# CQL adaptor also supports INSERTs, UPDATEs, DELETEs ...
|
||||
#
|
||||
|
||||
POST {{server}}/hcql/admin
|
||||
Content-Type: application/jsonin wonderland
|
||||
|
||||
{ "INSERT": {
|
||||
"into": "Books",
|
||||
"entries": [{
|
||||
"title": "The Black Cat",
|
||||
"author": { "ID": 150 }
|
||||
}]
|
||||
}}
|
||||
###
|
||||
@@ -1,26 +0,0 @@
|
||||
@server = http://localhost:4004
|
||||
|
||||
GET {{server}}/odata/v2/admin/Authors
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
GET {{server}}/odata/v2/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
GET {{server}}/odata/v4/admin/Authors
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
GET {{server}}/odata/v4/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
|
||||
GET {{server}}/rest/admin/Authors
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
@@ -1,9 +0,0 @@
|
||||
@server = http://localhost:4004
|
||||
|
||||
GET {{server}}/rest/admin/Authors
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
|
||||
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
|
||||
Authorization: Basic alice:
|
||||
###
|
||||
@@ -1,4 +0,0 @@
|
||||
|
||||
using { CatalogService, AdminService } from '@capire/bookstore';
|
||||
annotate CatalogService with @hcql @odata @path:'browse' @requires:[];
|
||||
annotate AdminService with @hcql @odata @path:'admin';
|
||||
@@ -16,9 +16,9 @@ GET {{server}}/browse/$metadata
|
||||
|
||||
### ------------------------------------------------------------------------
|
||||
# Browse Books as any user
|
||||
GET {{server}}/browse/ListOfBooks?
|
||||
GET {{server}}/browse/Books?
|
||||
# &$select=title,stock
|
||||
&$expand=genre
|
||||
# &$expand=currency
|
||||
# &sap-language=de
|
||||
{{me}}
|
||||
|
||||
@@ -32,18 +32,6 @@ GET {{server}}/admin/Authors?
|
||||
# &sap-language=de
|
||||
Authorization: Basic alice:
|
||||
|
||||
### ------------------------------------------------------------------------
|
||||
# Create Author
|
||||
POST {{server}}/admin/Authors
|
||||
Content-Type: application/json;IEEE754Compatible=true
|
||||
Authorization: Basic alice:
|
||||
|
||||
{
|
||||
"ID": 112,
|
||||
"name": "Shakespeeeeere"
|
||||
}
|
||||
|
||||
|
||||
### ------------------------------------------------------------------------
|
||||
# Create book
|
||||
POST {{server}}/admin/Books
|
||||
@@ -55,7 +43,7 @@ Authorization: Basic alice:
|
||||
"title": "Poems : Pocket Poets",
|
||||
"descr": "The Everyman's Library Pocket Poets hardcover series is popular for its compact size and reasonable price which does not compromise content. Poems: Bronte contains poems that demonstrate a sensibility elemental in its force with an imaginative discipline and flexibility of the highest order. Also included are an Editor's Note and an index of first lines.",
|
||||
"author": { "ID": 101 },
|
||||
"genre": { "ID": "12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" },
|
||||
"genre": { "ID": 12 },
|
||||
"stock": 5,
|
||||
"price": "12.05",
|
||||
"currency": { "code": "USD" }
|
||||
@@ -1,20 +0,0 @@
|
||||
Books = Livres
|
||||
Book = Livre
|
||||
Title = Titre
|
||||
Description = Description
|
||||
Stock = Action
|
||||
Image = Image
|
||||
Price = Prix
|
||||
Currency = Devise
|
||||
|
||||
Authors = Auteurs
|
||||
Author = Auteur
|
||||
AuthorID = ID de l''auteur
|
||||
Name = Nom
|
||||
DateOfBirth = Date de naissance
|
||||
DateOfDeath = Date de décès
|
||||
PlaceOfBirth = Lieu de naissance
|
||||
PlaceOfDeath = Lieu de décès
|
||||
|
||||
Genres = Genre
|
||||
Genre = Genre
|
||||
@@ -1,34 +0,0 @@
|
||||
400 = Ungültige Anfrage
|
||||
401 = Nicht autorisiert
|
||||
403 = Verboten
|
||||
404 = Nicht gefunden
|
||||
405 = Methode nicht zulässig
|
||||
406 = Nicht akzeptabel
|
||||
407 = Proxy-Authentifizierung erforderlich
|
||||
408 = Anfrage-Timeout
|
||||
409 = Konflikt
|
||||
410 = Weg
|
||||
411 = Erforderliche Länge
|
||||
412 = Vorbedingung fehlgeschlagen
|
||||
413 = Nutzlast zu groß
|
||||
414 = URI zu lang
|
||||
415 = Nicht unterstützter Medientyp
|
||||
416 = Bereich nicht erfüllbar
|
||||
417 = Erwartung fehlgeschlagen
|
||||
422 = Nicht verarbeitbarer Inhalt
|
||||
424 = Fehlgeschlagene Abhängigkeit
|
||||
428 = Vorbedingung erforderlich
|
||||
429 = Zu viele Anfragen
|
||||
431 = Anfrage-Headerfelder zu groß
|
||||
451 = Aus rechtlichen Gründen nicht verfügbar
|
||||
500 = Interner Serverfehler
|
||||
501 = Der Server unterstützt die zur Erfüllung der Anfrage erforderliche Funktionalität nicht
|
||||
502 = Ungültiges Gateway
|
||||
503 = Dienst nicht verfügbar
|
||||
504 = Gateway-Timeout
|
||||
|
||||
ASSERT_RANGE = Wert {0} liegt nicht im angegebenen Bereich [{1}, {2}]
|
||||
ASSERT_FORMAT = Wert "{0}" liegt nicht im angegebenen Format "{1}"
|
||||
ASSERT_ARRAY = Wert muss ein Array sein
|
||||
ASSERT_ENUM = Wert {0} ist gemäß Enumerationsdeklaration {{1}} ungültig
|
||||
ASSERT_NOT_NULL = Wert ist erforderlich
|
||||
@@ -1,34 +0,0 @@
|
||||
400 = Bad Request
|
||||
401 = Unauthorized
|
||||
403 = Forbidden
|
||||
404 = Not Found
|
||||
405 = Method Not Allowed
|
||||
406 = Not Acceptable
|
||||
407 = Proxy Authentication Required
|
||||
408 = Request Timeout
|
||||
409 = Conflict
|
||||
410 = Gone
|
||||
411 = Length Required
|
||||
412 = Precondition Failed
|
||||
413 = Payload Too Large
|
||||
414 = URI Too Long
|
||||
415 = Unsupported Media Type
|
||||
416 = Range Not Satisfiable
|
||||
417 = Expectation Failed
|
||||
422 = Unprocessable Content
|
||||
424 = Failed Dependency
|
||||
428 = Precondition Required
|
||||
429 = Too Many Requests
|
||||
431 = Request Header Fields Too Large
|
||||
451 = Unavailable For Legal Reasons
|
||||
500 = Internal Server Error
|
||||
501 = The server does not support the functionality required to fulfill the request
|
||||
502 = Bad Gateway
|
||||
503 = Service Unavailable
|
||||
504 = Gateway Timeout
|
||||
|
||||
ASSERT_RANGE = Value {0} is not in specified range [{1}, {2}]
|
||||
ASSERT_FORMAT = Value "{0}" is not in specified format "{1}"
|
||||
ASSERT_ARRAY = Value must be an array
|
||||
ASSERT_ENUM = Value {0} is invalid according to enum declaration {{1}}
|
||||
ASSERT_NOT_NULL = Value is required
|
||||
@@ -1,34 +0,0 @@
|
||||
400 = Requête incorrecte
|
||||
401 = Non autorisée
|
||||
403 = Interdite
|
||||
404 = Introuvable
|
||||
405 = Méthode non autorisée
|
||||
406 = Non acceptable
|
||||
407 = Authentification proxy requise
|
||||
408 = Délai d''expiration de la requête
|
||||
409 = Conflit
|
||||
410 = Disparu
|
||||
411 = Longueur requise
|
||||
412 = Échec de la condition préalable
|
||||
413 = Charge utile trop importante
|
||||
414 = URI trop longue
|
||||
415 = Type de média non pris en charge
|
||||
416 = Plage non satisfaisante
|
||||
417 = Échec de l''attente
|
||||
422 = Contenu non traitable
|
||||
424 = Dépendance échouée
|
||||
428 = Condition préalable requise
|
||||
429 = Trop de requêtes
|
||||
431 = Champs d''en-tête de requête trop importants
|
||||
451 = Indisponible pour des raisons juridiques
|
||||
500 = Erreur interne du serveur
|
||||
501 = Le serveur ne prend pas en charge la fonctionnalité requise pour répondre à la requête
|
||||
502 = Passerelle incorrecte
|
||||
503 = Service indisponible
|
||||
504 = Délai d''attente de la passerelle
|
||||
|
||||
ASSERT_RANGE = La valeur {0} n''est pas dans la plage spécifiée [{1}, {2}]
|
||||
ASSERT_FORMAT = La valeur "{0}" n''est pas au format spécifié "{1}"
|
||||
ASSERT_ARRAY = La valeur doit être un tableau
|
||||
ASSERT_ENUM = La valeur {0} n''est pas valide selon la déclaration d''énumération {{1}}
|
||||
ASSERT_NOT_NULL = La valeur est obligatoire
|
||||
@@ -1,5 +0,0 @@
|
||||
AuthorName = Name des Autors
|
||||
Age = Alter
|
||||
rder = Bestellung
|
||||
Orders = Bestellungen
|
||||
Price = Preis
|
||||
@@ -1,8 +0,0 @@
|
||||
Age = Age
|
||||
Lifetime = Lifetime
|
||||
|
||||
SubGenres = Subgenre
|
||||
|
||||
NumCode = Numeric Code
|
||||
MinorUnit = Minor Unit
|
||||
Exponent = Exponent
|
||||
@@ -1,52 +0,0 @@
|
||||
using {AdminService} from '@capire/bookshop';
|
||||
|
||||
annotate AdminService.Authors with @odata.draft.enabled;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Authors Object Page
|
||||
//
|
||||
annotate AdminService.Authors with @(UI : {
|
||||
HeaderInfo : {
|
||||
TypeName : 'Author',
|
||||
TypeNamePlural : 'Authors',
|
||||
Description : {Value : lifetime}
|
||||
},
|
||||
Facets : [
|
||||
{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Details}',
|
||||
Target : '@UI.FieldGroup#Details'
|
||||
},
|
||||
{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Books}',
|
||||
Target : 'books/@UI.LineItem'
|
||||
},
|
||||
],
|
||||
FieldGroup #Details : {Data : [
|
||||
{Value : placeOfBirth},
|
||||
{Value : placeOfDeath},
|
||||
{Value : dateOfBirth},
|
||||
{Value : dateOfDeath},
|
||||
{
|
||||
Value : age,
|
||||
Label : '{i18n>Age}'
|
||||
},
|
||||
]},
|
||||
});
|
||||
|
||||
|
||||
// Workaround to avoid errors for unknown db-specific calculated fields above
|
||||
extend sap.capire.bookshop.Authors with {
|
||||
virtual age : Integer;
|
||||
virtual lifetime : String;
|
||||
}
|
||||
|
||||
annotate AdminService.Authors with {
|
||||
age @Common.Label : '{i18n>Age}';
|
||||
lifetime @Common.Label : '{i18n>Lifetime}'
|
||||
}
|
||||
|
||||
// Workaround for Fiori popup for asking user to enter a new UUID on Create
|
||||
annotate AdminService.Authors with { ID @Core.Computed; }
|
||||
@@ -1,7 +0,0 @@
|
||||
sap.ui.define(["sap/fe/core/AppComponent"], function (AppComponent) {
|
||||
"use strict";
|
||||
return AppComponent.extend("authors.Component", {
|
||||
metadata: { manifest: "json" },
|
||||
});
|
||||
});
|
||||
/* eslint no-undef:0 */
|
||||
@@ -1,11 +0,0 @@
|
||||
# This is the resource bundle of itelo
|
||||
# __ldi.translation.uuid=c3431418-9caf-11e8-98d0-529269fb1459
|
||||
|
||||
# JCI app descriptor contains lower case TITLE
|
||||
appTitle=Manage Authors
|
||||
|
||||
# JCI app descriptor contains lower case DESCRIPTION
|
||||
appSubTitle=CAP Sample Application
|
||||
|
||||
# JCI app descriptor contains lower case DESCRIPTION
|
||||
appDescription=Bookshop Authors
|
||||
@@ -1,141 +0,0 @@
|
||||
{
|
||||
"_version": "1.28.0",
|
||||
"sap.app": {
|
||||
"id": "authors",
|
||||
"type": "application",
|
||||
"title": "Manage Authors",
|
||||
"description": "Sample Application",
|
||||
"i18n": "i18n/i18n.properties",
|
||||
"applicationVersion": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"dataSources": {
|
||||
"AdminService": {
|
||||
"uri": "admin/",
|
||||
"type": "OData",
|
||||
"settings": {
|
||||
"odataVersion": "4.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceTemplate": {
|
||||
"id": "ui5template.basicSAPUI5ApplicationProject",
|
||||
"-id": "ui5template.smartTemplate",
|
||||
"version": "1.40.12"
|
||||
},
|
||||
"crossNavigation": {
|
||||
"inbounds": {
|
||||
"intent1": {
|
||||
"signature": {
|
||||
"parameters": {
|
||||
"Books.author.ID":{
|
||||
"renameTo": "ID"
|
||||
}
|
||||
},
|
||||
"additionalParameters": "ignored"
|
||||
},
|
||||
"semanticObject": "Authors",
|
||||
"action": "manage",
|
||||
"title": "{{appTitle}}",
|
||||
"info": "{{appInfo}}",
|
||||
"subTitle": "{{appSubTitle}}",
|
||||
"icon": "sap-icon://SAP-icons-TNT/user",
|
||||
"indicatorDataSource": {
|
||||
"dataSource": "AdminService",
|
||||
"path": "Authors/$count",
|
||||
"refresh": 1800
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"sap.ui5": {
|
||||
"dependencies": {
|
||||
"minUI5Version": "1.81.0",
|
||||
"libs": {
|
||||
"sap.fe.templates": {}
|
||||
}
|
||||
},
|
||||
"models": {
|
||||
"i18n": {
|
||||
"type": "sap.ui.model.resource.ResourceModel",
|
||||
"uri": "i18n/i18n.properties"
|
||||
},
|
||||
"": {
|
||||
"dataSource": "AdminService",
|
||||
"settings": {
|
||||
"synchronizationMode": "None",
|
||||
"operationMode": "Server",
|
||||
"autoExpandSelect": true,
|
||||
"earlyRequests": true,
|
||||
"groupProperties": {
|
||||
"default": {
|
||||
"submit": "Auto"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"routing": {
|
||||
"routes": [
|
||||
{
|
||||
"pattern": ":?query:",
|
||||
"name": "AuthorsList",
|
||||
"target": "AuthorsList"
|
||||
},
|
||||
{
|
||||
"pattern": "Authors({key}):?query:",
|
||||
"name": "AuthorsDetails",
|
||||
"target": "AuthorsDetails"
|
||||
}
|
||||
],
|
||||
"targets": {
|
||||
"AuthorsList": {
|
||||
"type": "Component",
|
||||
"id": "AuthorsList",
|
||||
"name": "sap.fe.templates.ListReport",
|
||||
"options": {
|
||||
"settings": {
|
||||
"entitySet": "Authors",
|
||||
"initialLoad": true,
|
||||
"navigation": {
|
||||
"Authors": {
|
||||
"detail": {
|
||||
"route": "AuthorsDetails"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"AuthorsDetails": {
|
||||
"type": "Component",
|
||||
"id": "AuthorsDetailsList",
|
||||
"name": "sap.fe.templates.ObjectPage",
|
||||
"options": {
|
||||
"settings": {
|
||||
"entitySet": "Authors"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contentDensities": {
|
||||
"compact": true,
|
||||
"cozy": true
|
||||
}
|
||||
},
|
||||
"sap.ui": {
|
||||
"technology": "UI5",
|
||||
"fullWidth": false,
|
||||
"deviceTypes":{
|
||||
"desktop": true,
|
||||
"tablet": true,
|
||||
"phone": true
|
||||
}
|
||||
},
|
||||
"sap.fiori": {
|
||||
"registrationIds": [],
|
||||
"archeType": "transactional"
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
{
|
||||
"services": {
|
||||
"LaunchPage": {
|
||||
"adapter": {
|
||||
"config": {
|
||||
"groups": [
|
||||
{
|
||||
"id": "Bookshop",
|
||||
"title": "Bookshop",
|
||||
"isPreset": true,
|
||||
"isVisible": true,
|
||||
"isGroupLocked": false,
|
||||
"tiles": [
|
||||
{
|
||||
"id": "BrowseBooks",
|
||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
||||
"properties": {
|
||||
"title": "Browse Books",
|
||||
"targetURL": "#Books-display"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "BrowseGenres",
|
||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
||||
"properties": {
|
||||
"title": "Browse Genres",
|
||||
"targetURL": "#Genres-display"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "Administration",
|
||||
"title": "Administration",
|
||||
"isPreset": true,
|
||||
"isVisible": true,
|
||||
"isGroupLocked": false,
|
||||
"tiles": [
|
||||
{
|
||||
"id": "ManageBooks",
|
||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
||||
"properties": {
|
||||
"title": "Manage Books",
|
||||
"targetURL": "#Books-manage"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ManageAuthors",
|
||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
||||
"properties": {
|
||||
"title": "Manage Authors",
|
||||
"targetURL": "#Authors-manage"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ManageOrders",
|
||||
"tileType": "sap.ushell.ui.tile.StaticTile",
|
||||
"properties": {
|
||||
"title": "Manage Orders",
|
||||
"targetURL": "#Orders-manage"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"NavTargetResolution": {
|
||||
"config": {
|
||||
"enableClientSideTargetResolution": true
|
||||
}
|
||||
},
|
||||
"ClientSideTargetResolution": {
|
||||
"adapter": {
|
||||
"config": {
|
||||
"inbounds": {
|
||||
"BrowseBooks": {
|
||||
"semanticObject": "Books",
|
||||
"action": "display",
|
||||
"title": "Browse Books",
|
||||
"signature": {
|
||||
"parameters": {
|
||||
"Books.ID": {
|
||||
"renameTo": "ID"
|
||||
},
|
||||
"Authors.books.ID": {
|
||||
"renameTo": "ID"
|
||||
}
|
||||
},
|
||||
"additionalParameters": "ignored"
|
||||
},
|
||||
"resolutionResult": {
|
||||
"applicationType": "SAPUI5",
|
||||
"additionalInformation": "SAPUI5.Component=bookshop",
|
||||
"url": "/browse/webapp"
|
||||
}
|
||||
},
|
||||
"BrowseAuthors": {
|
||||
"semanticObject": "Authors",
|
||||
"action": "manage",
|
||||
"title": "Browse Authors",
|
||||
"signature": {
|
||||
"parameters": {
|
||||
"Books.author.ID":{
|
||||
"renameTo": "ID"
|
||||
}
|
||||
},
|
||||
"additionalParameters": "ignored"
|
||||
},
|
||||
"resolutionResult": {
|
||||
"applicationType": "SAPUI5",
|
||||
"additionalInformation": "SAPUI5.Component=authors",
|
||||
"url": "/admin-authors/webapp"
|
||||
}
|
||||
},
|
||||
"BrowseGenres": {
|
||||
"semanticObject": "Genres",
|
||||
"action": "display",
|
||||
"title": "Browse Genres",
|
||||
"signature": {
|
||||
"parameters": {
|
||||
"Genre.ID": {
|
||||
"renameTo": "ID"
|
||||
}
|
||||
},
|
||||
"additionalParameters": "ignored"
|
||||
},
|
||||
"resolutionResult": {
|
||||
"applicationType": "SAPUI5",
|
||||
"additionalInformation": "SAPUI5.Component=genres",
|
||||
"url": "/genres/webapp"
|
||||
}
|
||||
},
|
||||
"ManageBooks": {
|
||||
"semanticObject": "Books",
|
||||
"action": "manage",
|
||||
"title": "Manage Books",
|
||||
"signature": {
|
||||
"parameters": {},
|
||||
"additionalParameters": "allowed"
|
||||
},
|
||||
"resolutionResult": {
|
||||
"applicationType": "SAPUI5",
|
||||
"additionalInformation": "SAPUI5.Component=books",
|
||||
"url": "/admin-books/webapp"
|
||||
}
|
||||
},
|
||||
"ManageOrders": {
|
||||
"semanticObject": "Orders",
|
||||
"action": "manage",
|
||||
"signature": {
|
||||
"parameters": {},
|
||||
"additionalParameters": "allowed"
|
||||
},
|
||||
"resolutionResult": {
|
||||
"applicationType": "SAPUI5",
|
||||
"additionalInformation": "SAPUI5.Component=orders",
|
||||
"url": "/orders/webapp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using CatalogService from '@capire/bookstore';
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Object Page
|
||||
//
|
||||
annotate CatalogService.Books with @(UI : {
|
||||
HeaderInfo : {
|
||||
TypeName : '{i18n>Book}',
|
||||
TypeNamePlural : '{i18n>Books}',
|
||||
Description : {Value : author}
|
||||
},
|
||||
HeaderFacets : [{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Description}',
|
||||
Target : '@UI.FieldGroup#Descr'
|
||||
}, ],
|
||||
Facets : [{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Details}',
|
||||
Target : '@UI.FieldGroup#Price'
|
||||
}, ],
|
||||
FieldGroup #Descr : {Data : [{Value : descr}, ]},
|
||||
FieldGroup #Price : {Data : [
|
||||
{Value : price},
|
||||
{
|
||||
Value : currency.symbol,
|
||||
Label : '{i18n>Currency}'
|
||||
},
|
||||
]},
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books List Page
|
||||
//
|
||||
annotate CatalogService.Books with @(UI : {
|
||||
SelectionFields : [
|
||||
ID,
|
||||
price,
|
||||
currency_code
|
||||
],
|
||||
LineItem : [
|
||||
{
|
||||
Value : ID,
|
||||
Label : '{i18n>Title}'
|
||||
},
|
||||
{
|
||||
Value : author,
|
||||
Label : '{i18n>Author}'
|
||||
},
|
||||
{Value : genre.name},
|
||||
{Value : price},
|
||||
{Value : currency.symbol},
|
||||
]
|
||||
}, );
|
||||
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
Common Annotations shared by all apps
|
||||
*/
|
||||
|
||||
using { sap.capire.bookshop as my } from '@capire/bookstore';
|
||||
using { sap.common } from '@capire/common';
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Lists
|
||||
//
|
||||
annotate my.Books with @(
|
||||
Common.SemanticKey : [ID],
|
||||
UI : {
|
||||
Identification : [{ Value: title }],
|
||||
SelectionFields : [
|
||||
ID,
|
||||
author_ID,
|
||||
price,
|
||||
currency_code
|
||||
],
|
||||
LineItem : [
|
||||
{ Value: ID, Label: '{i18n>Title}' },
|
||||
{ Value: author.ID, Label: '{i18n>Author}' },
|
||||
{ Value: genre.name },
|
||||
{ Value: stock },
|
||||
{ Value: price },
|
||||
{ Value: currency.symbol },
|
||||
]
|
||||
}
|
||||
) {
|
||||
ID @Common: {
|
||||
SemanticObject : 'Books',
|
||||
Text: title,
|
||||
TextArrangement : #TextOnly
|
||||
};
|
||||
author @ValueList.entity : 'Authors';
|
||||
};
|
||||
|
||||
annotate common.Currencies with {
|
||||
symbol @Common.Label : '{i18n>Currency}';
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Details
|
||||
//
|
||||
annotate my.Books with @(UI : {HeaderInfo : {
|
||||
TypeName : '{i18n>Book}',
|
||||
TypeNamePlural : '{i18n>Books}',
|
||||
Title : { Value: title },
|
||||
Description : { Value: author.name }
|
||||
}, });
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Elements
|
||||
//
|
||||
annotate my.Books with {
|
||||
ID @title: '{i18n>ID}';
|
||||
title @title: '{i18n>Title}';
|
||||
genre @title: '{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly };
|
||||
author @title: '{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly };
|
||||
price @title: '{i18n>Price}' @Measures.ISOCurrency : currency_code;
|
||||
stock @title: '{i18n>Stock}';
|
||||
descr @title: '{i18n>Description}' @UI.MultiLineText;
|
||||
image @title: '{i18n>Image}';
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Authors List
|
||||
//
|
||||
annotate my.Authors with @(
|
||||
Common.SemanticKey : [ID],
|
||||
UI : {
|
||||
Identification : [{ Value: name}],
|
||||
SelectionFields : [name],
|
||||
LineItem : [
|
||||
{ Value: ID },
|
||||
{ Value: dateOfBirth },
|
||||
{ Value: dateOfDeath },
|
||||
{ Value: placeOfBirth },
|
||||
{ Value: placeOfDeath },
|
||||
],
|
||||
}
|
||||
) {
|
||||
ID @Common: {
|
||||
SemanticObject : 'Authors',
|
||||
Text: name,
|
||||
TextArrangement : #TextOnly,
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Author Details
|
||||
//
|
||||
annotate my.Authors with @(UI : {
|
||||
HeaderInfo : {
|
||||
TypeName : '{i18n>Author}',
|
||||
TypeNamePlural : '{i18n>Authors}',
|
||||
Title : { Value: name },
|
||||
Description : { Value: dateOfBirth }
|
||||
},
|
||||
Facets : [{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Target : 'books/@UI.LineItem'
|
||||
}, ],
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Authors Elements
|
||||
//
|
||||
annotate my.Authors with {
|
||||
ID @title: '{i18n>ID}';
|
||||
name @title: '{i18n>Name}';
|
||||
dateOfBirth @title: '{i18n>DateOfBirth}';
|
||||
dateOfDeath @title: '{i18n>DateOfDeath}';
|
||||
placeOfBirth @title: '{i18n>PlaceOfBirth}';
|
||||
placeOfDeath @title: '{i18n>PlaceOfDeath}';
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Languages List
|
||||
//
|
||||
annotate common.Languages with @(
|
||||
Common.SemanticKey : [code],
|
||||
Identification : [{ Value: code}],
|
||||
UI : {
|
||||
SelectionFields : [
|
||||
name,
|
||||
descr
|
||||
],
|
||||
LineItem : [
|
||||
{ Value: code },
|
||||
{ Value: name },
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Language Details
|
||||
//
|
||||
annotate common.Languages with @(UI : {
|
||||
HeaderInfo : {
|
||||
TypeName : '{i18n>Language}',
|
||||
TypeNamePlural : '{i18n>Languages}',
|
||||
Title : { Value: name },
|
||||
Description : { Value: descr }
|
||||
},
|
||||
Facets : [{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Details}',
|
||||
Target : '@UI.FieldGroup#Details'
|
||||
}, ],
|
||||
FieldGroup #Details : {Data : [
|
||||
{ Value: code },
|
||||
{ Value: name },
|
||||
{ Value: descr }
|
||||
]},
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Currencies List
|
||||
//
|
||||
annotate common.Currencies with @(
|
||||
Common.SemanticKey : [code],
|
||||
Identification : [{ Value: code}],
|
||||
UI : {
|
||||
SelectionFields : [
|
||||
name,
|
||||
descr
|
||||
],
|
||||
LineItem : [
|
||||
{ Value: descr },
|
||||
{ Value: symbol },
|
||||
{ Value: code },
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Currency Details
|
||||
//
|
||||
annotate common.Currencies with @(UI : {
|
||||
HeaderInfo : {
|
||||
TypeName : '{i18n>Currency}',
|
||||
TypeNamePlural : '{i18n>Currencies}',
|
||||
Title : { Value: descr },
|
||||
Description : { Value: code }
|
||||
},
|
||||
Facets : [
|
||||
{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Details}',
|
||||
Target : '@UI.FieldGroup#Details'
|
||||
},
|
||||
{
|
||||
$Type : 'UI.ReferenceFacet',
|
||||
Label : '{i18n>Extended}',
|
||||
Target : '@UI.FieldGroup#Extended'
|
||||
},
|
||||
],
|
||||
FieldGroup #Details : {Data : [
|
||||
{ Value: name },
|
||||
{ Value: symbol },
|
||||
{ Value: code },
|
||||
{ Value: descr }
|
||||
]},
|
||||
FieldGroup #Extended : {Data : [
|
||||
{ Value: numcode },
|
||||
{ Value: minor },
|
||||
{ Value: exponent }
|
||||
]},
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Currencies Elements
|
||||
//
|
||||
annotate common.Currencies with {
|
||||
numcode @title: '{i18n>NumCode}';
|
||||
minor @title: '{i18n>MinorUnit}';
|
||||
exponent @title: '{i18n>Exponent}';
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Bookshop</title>
|
||||
|
||||
<script>
|
||||
window["sap-ushell-config"] = {
|
||||
defaultRenderer: "fiori2",
|
||||
applications: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<script id="sap-ushell-bootstrap" src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
||||
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
|
||||
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout" data-sap-ui-compatVersion="edge"
|
||||
data-sap-ui-theme="sap_horizon"></script>
|
||||
<script>
|
||||
sap.ui.getCore().attachInit(() =>
|
||||
sap.ushell.Container.createRenderer().placeAt("content")
|
||||
);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="sapUiBody" id="content">
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,33 +0,0 @@
|
||||
using { sap.capire.bookshop.Genres } from '@capire/bookstore';
|
||||
|
||||
annotate Genres with @cds.search: {name};
|
||||
annotate Genres with @readonly;
|
||||
annotate Genres with {
|
||||
name @title: '{i18n>Genre}';
|
||||
}
|
||||
|
||||
// Lists
|
||||
annotate Genres with @(
|
||||
Common.SemanticKey : [name],
|
||||
UI.SelectionFields : [name],
|
||||
UI.LineItem : [
|
||||
{ Value: name, Label: '{i18n>Name}' },
|
||||
],
|
||||
);
|
||||
|
||||
// Details
|
||||
annotate Genres with @(UI : {
|
||||
Identification : [{ Value: name }],
|
||||
HeaderInfo : {
|
||||
TypeName : '{i18n>Genre}',
|
||||
TypeNamePlural : '{i18n>Genres}',
|
||||
Title : { Value: name },
|
||||
Description : { Value: ID }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Tree Views
|
||||
// annotate AdminService.Genres with @hierarchy; // upcomming simplification
|
||||
using from './tree-view';
|
||||
using from './value-help';
|
||||
@@ -1,42 +0,0 @@
|
||||
using { AdminService } from '@capire/bookstore';
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Genres Tree View
|
||||
//
|
||||
|
||||
// Tell Fiori about the structure of the hierarchy
|
||||
annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : {
|
||||
ParentNavigationProperty : parent, // navigates to a node's parent
|
||||
NodeProperty : ID, // identifies a node, usually the key
|
||||
};
|
||||
|
||||
// Fiori expects the following to be defined explicitly, even though they're always the same
|
||||
extend AdminService.Genres with @(
|
||||
// The columns expected by Fiori to be present in hierarchy entities
|
||||
Hierarchy.RecursiveHierarchy #GenresHierarchy : {
|
||||
LimitedDescendantCount : LimitedDescendantCount,
|
||||
DistanceFromRoot : DistanceFromRoot,
|
||||
DrillState : DrillState,
|
||||
LimitedRank : LimitedRank
|
||||
},
|
||||
// Disallow filtering on these properties from Fiori UIs
|
||||
Capabilities.FilterRestrictions.NonFilterableProperties: [
|
||||
'LimitedDescendantCount',
|
||||
'DistanceFromRoot',
|
||||
'DrillState',
|
||||
'LimitedRank'
|
||||
],
|
||||
// Disallow sorting on these properties from Fiori UIs
|
||||
Capabilities.SortRestrictions.NonSortableProperties : [
|
||||
'LimitedDescendantCount',
|
||||
'DistanceFromRoot',
|
||||
'DrillState',
|
||||
'LimitedRank'
|
||||
],
|
||||
) columns { // Ensure we can query these fields from database
|
||||
null as LimitedDescendantCount : Int16,
|
||||
null as DistanceFromRoot : Int16,
|
||||
null as DrillState : String,
|
||||
null as LimitedRank : Int16,
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
// Value help with Tree View
|
||||
using from '../admin-books/fiori-service';
|
||||
annotate AdminService.Books:genre with @Common.ValueList.PresentationVariantQualifier: 'VH';
|
||||
annotate AdminService.Genres with @UI.PresentationVariant #VH: {
|
||||
RecursiveHierarchyQualifier : 'GenresHierarchy',
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("genres.Component", {
|
||||
metadata:{ manifest:'json' }
|
||||
}))
|
||||
@@ -1,4 +0,0 @@
|
||||
#XTIT
|
||||
appTitle=Browse Genres
|
||||
#XTXT
|
||||
appDescription=Genres as Tree View
|
||||
@@ -1,2 +0,0 @@
|
||||
appTitle=Zeige Genres
|
||||
appDescription=Genres als Baumansicht
|
||||
@@ -1,124 +0,0 @@
|
||||
{
|
||||
"_version": "1.8.0",
|
||||
"sap.app": {
|
||||
"id": "genres",
|
||||
"type": "application",
|
||||
"title": "{{appTitle}}",
|
||||
"description": "{{appDescription}}",
|
||||
"applicationVersion": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"dataSources": {
|
||||
"AdminService": {
|
||||
"uri": "admin/",
|
||||
"type": "OData",
|
||||
"settings": {
|
||||
"odataVersion": "4.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"crossNavigation": {
|
||||
"inbounds": {
|
||||
"Genres-display": {
|
||||
"signature": {
|
||||
"parameters": {},
|
||||
"additionalParameters": "allowed"
|
||||
},
|
||||
"semanticObject": "Genres",
|
||||
"action": "display"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"sap.ui5": {
|
||||
"dependencies": {
|
||||
"minUI5Version": "1.122.0",
|
||||
"libs": {
|
||||
"sap.fe.templates": {}
|
||||
}
|
||||
},
|
||||
"models": {
|
||||
"i18n": {
|
||||
"type": "sap.ui.model.resource.ResourceModel",
|
||||
"uri": "i18n/i18n.properties"
|
||||
},
|
||||
"": {
|
||||
"dataSource": "AdminService",
|
||||
"settings": {
|
||||
"synchronizationMode": "None",
|
||||
"operationMode": "Server",
|
||||
"autoExpandSelect": true,
|
||||
"earlyRequests": true,
|
||||
"groupProperties": {
|
||||
"default": {
|
||||
"submit": "Auto"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"routing": {
|
||||
"routes": [
|
||||
{
|
||||
"pattern": ":?query:",
|
||||
"name": "GenresList",
|
||||
"target": "GenresList"
|
||||
},
|
||||
{
|
||||
"pattern": "Genres({key}):?query:",
|
||||
"name": "GenresDetails",
|
||||
"target": "GenresDetails"
|
||||
}
|
||||
],
|
||||
"targets": {
|
||||
"GenresList": {
|
||||
"type": "Component",
|
||||
"id": "GenresList",
|
||||
"name": "sap.fe.templates.ListReport",
|
||||
"options": {
|
||||
"settings": {
|
||||
"contextPath": "/Genres",
|
||||
"navigation": {
|
||||
"Genres": {
|
||||
"detail": {
|
||||
"route": "GenresDetails"
|
||||
}
|
||||
}
|
||||
},
|
||||
"controlConfiguration": {
|
||||
"@com.sap.vocabularies.UI.v1.LineItem": {
|
||||
"tableSettings": {
|
||||
"hierarchyQualifier": "GenresHierarchy",
|
||||
"type": "TreeTable"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"GenresDetails": {
|
||||
"type": "Component",
|
||||
"id": "GenresDetails",
|
||||
"name": "sap.fe.templates.ObjectPage",
|
||||
"options": {
|
||||
"settings": {
|
||||
"contextPath": "/Genres"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contentDensities": {
|
||||
"compact": true,
|
||||
"cozy": true
|
||||
}
|
||||
},
|
||||
"sap.ui": {
|
||||
"technology": "UI5",
|
||||
"fullWidth": false
|
||||
},
|
||||
"sap.fiori": {
|
||||
"registrationIds": [],
|
||||
"archeType": "transactional"
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Add Author.age and .lifetime with a DB-specific function
|
||||
//
|
||||
|
||||
using { AdminService } from '@capire/bookshop';
|
||||
using { AdminService } from '../schema';
|
||||
|
||||
extend projection AdminService.Authors with {
|
||||
YEARS_BETWEEN(dateOfBirth, dateOfDeath) as age: Integer,
|
||||
|
||||
8
bookstore/db/schema.cds
Normal file
8
bookstore/db/schema.cds
Normal file
@@ -0,0 +1,8 @@
|
||||
using { sap.capire.bookshop } from '@capire/bookshop';
|
||||
|
||||
// Forward-declare calculated fields to be filled in database-specific ways
|
||||
// TODO find a better way to have 'default' fields that still can be overwritten.
|
||||
extend bookshop.Authors with {
|
||||
virtual age: Integer;
|
||||
virtual lifetime: String;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Add Author.age and .lifetime with a DB-specific function
|
||||
//
|
||||
|
||||
using { AdminService } from '@capire/bookshop';
|
||||
using { AdminService } from '../schema';
|
||||
|
||||
extend projection AdminService.Authors with {
|
||||
strftime('%Y',dateOfDeath)-strftime('%Y',dateOfBirth) as age: Integer,
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
namespace sap.capire.bookshop; //> important for reflection
|
||||
using from './srv/mashup';
|
||||
@@ -6,20 +6,9 @@
|
||||
"@capire/reviews": "*",
|
||||
"@capire/orders": "*",
|
||||
"@capire/common": "*",
|
||||
"@capire/data-viewer": "*",
|
||||
"@cap-js/hana": ">=1",
|
||||
"@sap-cloud-sdk/http-client": "^4",
|
||||
"@sap-cloud-sdk/resilience": "^4",
|
||||
"@sap/cds": ">=5",
|
||||
"@sap/cds": "^5",
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cap-js/sqlite": ">=1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cds-serve",
|
||||
"watch": "cds watch"
|
||||
},
|
||||
"cds": {
|
||||
"requires": {
|
||||
"ReviewsService": {
|
||||
@@ -30,9 +19,13 @@
|
||||
"kind": "odata",
|
||||
"model": "@capire/orders"
|
||||
},
|
||||
"messaging": true,
|
||||
"db": true,
|
||||
"db-ext": {
|
||||
"messaging": {
|
||||
"[development]": { "kind": "file-based-messaging" },
|
||||
"[hybrid]": { "kind": "enterprise-messaging-shared" },
|
||||
"[production]": { "kind": "enterprise-messaging" }
|
||||
},
|
||||
"db": {
|
||||
"kind": "sql",
|
||||
"[development]": {
|
||||
"model": "db/sqlite"
|
||||
},
|
||||
@@ -42,10 +35,5 @@
|
||||
}
|
||||
},
|
||||
"log": { "service": true }
|
||||
},
|
||||
"sapux": [
|
||||
"app/admin-authors",
|
||||
"app/admin-books",
|
||||
"app/browse"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,21 @@
|
||||
require('./srv/mashup')
|
||||
require('./srv/trees')
|
||||
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
|
||||
|
||||
// For didactic reasons in capire
|
||||
const { ReviewsService, OrdersService } = cds.requires
|
||||
if (!ReviewsService.credentials && !OrdersService.credentials) cds.requires.messaging = false
|
||||
|
||||
@@ -4,28 +4,27 @@
|
||||
// respective reuse packages and services
|
||||
//
|
||||
|
||||
using { sap.capire.bookshop.Books } from '@capire/bookshop';
|
||||
|
||||
//
|
||||
// Extend Books with access to Reviews and average ratings
|
||||
//
|
||||
using { sap.capire.bookshop.Books } from '@capire/bookshop';
|
||||
using { ReviewsService.Reviews } from '@capire/reviews';
|
||||
extend Books with {
|
||||
reviews : Composition of many Reviews on reviews.subject = $self.ID;
|
||||
rating : type of Reviews:rating; // average rating
|
||||
numberOfReviews : Integer @title : '{i18n>NumberOfReviews}';
|
||||
rating : Decimal;
|
||||
numberOfReviews : Integer;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Extend Orders with Books as Products
|
||||
//
|
||||
using { sap.capire.orders.Orders } from '@capire/orders';
|
||||
extend Orders:Items with {
|
||||
using { sap.capire.orders.Orders_Items } from '@capire/orders';
|
||||
extend Orders_Items with {
|
||||
book : Association to Books on product.ID = book.ID
|
||||
}
|
||||
|
||||
// Ensure models from all imported packages are loaded
|
||||
|
||||
// Add orders fiori app (in case of embedded orders service)
|
||||
using from '@capire/orders/app/fiori';
|
||||
using from '@capire/data-viewer';
|
||||
using from '@capire/common';
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
const cds = require ('@sap/cds')
|
||||
|
||||
|
||||
// Add routes to UIs from imported packages
|
||||
if (!cds.env.production) 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')
|
||||
})
|
||||
|
||||
|
||||
// Mashing up bookshop services with required services...
|
||||
cds.once ('served', async ()=>{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Mashing up bookshop services with required services...
|
||||
//
|
||||
module.exports = async()=>{ // called by server.js
|
||||
|
||||
const cds = require('@sap/cds')
|
||||
const CatalogService = await cds.connect.to ('CatalogService')
|
||||
const ReviewsService = await cds.connect.to ('ReviewsService')
|
||||
const OrdersService = await cds.connect.to ('OrdersService')
|
||||
@@ -25,7 +18,7 @@ cds.once ('served', async ()=>{
|
||||
// Note: prepend is neccessary to intercept generic default handler
|
||||
//
|
||||
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||
console.debug ('> delegating request to ReviewsService') // eslint-disable-line no-console
|
||||
console.debug ('> delegating request to ReviewsService')
|
||||
const [id] = req.params, { columns, limit } = req.query.SELECT
|
||||
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
|
||||
}))
|
||||
@@ -35,8 +28,8 @@ cds.once ('served', async ()=>{
|
||||
//
|
||||
CatalogService.on ('OrderedBook', async (msg) => {
|
||||
const { book, quantity, buyer } = msg.data
|
||||
const { title, price } = await db.read (Books, book, b => { b.title, b.price })
|
||||
return OrdersService.create ('OrdersNoDraft').entries({
|
||||
const { title, price } = await db.tx(msg).read (Books, book, b => { b.title, b.price })
|
||||
return OrdersService.tx(msg).create ('Orders').entries({
|
||||
OrderNo: 'Order at '+ (new Date).toLocaleString(),
|
||||
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
|
||||
buyer, createdBy: buyer
|
||||
@@ -47,7 +40,7 @@ cds.once ('served', async ()=>{
|
||||
// Update Books' average ratings when ReviewsService signals updated reviews
|
||||
//
|
||||
ReviewsService.on ('reviewed', (msg) => {
|
||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
||||
console.debug ('> received:', msg.event, msg.data)
|
||||
const { subject, count, rating } = msg.data
|
||||
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
|
||||
})
|
||||
@@ -56,10 +49,10 @@ cds.once ('served', async ()=>{
|
||||
// Reduce stock of ordered books for orders are created from Orders admin UI
|
||||
//
|
||||
OrdersService.on ('OrderChanged', (msg) => {
|
||||
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
|
||||
console.debug ('> received:', msg.event, msg.data)
|
||||
const { product, deltaQuantity } = msg.data
|
||||
return UPDATE (Books) .where ('ID =', product)
|
||||
.and ('stock >=', deltaQuantity)
|
||||
.set ('stock -=', deltaQuantity)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
10
bookstore/srv/swagger-ui.js
Normal file
10
bookstore/srv/swagger-ui.js
Normal file
@@ -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
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
const cds = require('@sap/cds/lib')
|
||||
|
||||
// PoC for simplified Fiori Tree Views
|
||||
cds.on('compile.for.runtime', csn => {
|
||||
for (let each of cds.linked(csn).definitions) {
|
||||
if (each.is_entity && each._service && each['@hierarchy']) _hierarchy (each)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const _hierarchy = entity => {
|
||||
|
||||
// Add annotations explaining the hierarchy structure to Fiori
|
||||
const Qualifier = entity.name.slice (entity._service.name.length+1) + 'Hierarchy'
|
||||
const parent = _parent4(entity)
|
||||
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.ParentNavigationProperty`] ??= {'=': parent.name }
|
||||
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.NodeProperty`] ??= {'=': parent.keys[0].ref[0] }
|
||||
|
||||
// Add expected hierarchy elements to the entity
|
||||
const columns = entity.projection.columns ??= ['*']
|
||||
const elements = entity.elements
|
||||
for (let e of Hierarchy.elements) {
|
||||
entity[`@Hierarchy.RecursiveHierarchy#${Qualifier}.${e.name}`] = {'=': e.name }
|
||||
if (e.name in elements) continue
|
||||
const { name, value, ...rest } = e
|
||||
elements[e.name] = Object.defineProperty ({ __proto__:e, ...rest }, 'parent', { value: entity })
|
||||
columns.push ({ ...value, as: name, cast: { type: e.type } })
|
||||
}
|
||||
|
||||
// Disable filter and sort for hierarchy elements
|
||||
entity['@Capabilities.FilterRestrictions.NonFilterableProperties'] =
|
||||
entity['@Capabilities.SortRestrictions.NonSortableProperties'] =
|
||||
Object.keys (Hierarchy.elements)
|
||||
}
|
||||
|
||||
|
||||
const _parent4 = entity => {
|
||||
const parent = entity['@hierarchy.parent'] || entity['@hierarchy.via']
|
||||
if (parent) return entity.elements [parent['=']||parent]
|
||||
else for (let e of entity.elements) // use first recursive uplink association
|
||||
if (e.is2one && e._target === entity) return e
|
||||
}
|
||||
|
||||
|
||||
const { Hierarchy } = cds.linked `aspect Hierarchy {
|
||||
LimitedDescendantCount : Int16 = null;
|
||||
DistanceFromRoot : Int16 = null;
|
||||
DrillState : String = null;
|
||||
LimitedRank : Int16 = null;
|
||||
}`.definitions
|
||||
@@ -12,12 +12,11 @@
|
||||
#
|
||||
|
||||
GET {{reviews-service}}/Reviews
|
||||
Authorization: Basic me:
|
||||
|
||||
###
|
||||
|
||||
POST {{reviews-service}}/Reviews
|
||||
Authorization: Basic me:
|
||||
Authorization: Basic {{$processEnv USER}}:
|
||||
Content-Type: application/json
|
||||
|
||||
{"subject":"201", "title":"boo", "rating":3 }
|
||||
@@ -42,7 +41,7 @@ GET {{bookshop}}/browse/Books(201)?
|
||||
###
|
||||
|
||||
GET {{bookshop}}/browse/Books?
|
||||
&$select=title,author&$expand=currency
|
||||
&$select=title,author&$expand=currency
|
||||
Accept-Language: de
|
||||
|
||||
#################################################
|
||||
@@ -51,23 +50,23 @@ Accept-Language: de
|
||||
#
|
||||
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
|
||||
|
||||
GET {{bookshop}}/odata/v4/orders/Orders
|
||||
GET {{bookshop}}/orders/Orders
|
||||
|
||||
### Create order, still inactive
|
||||
POST {{bookshop}}/odata/v4/orders/Orders
|
||||
POST {{bookshop}}/orders/Orders
|
||||
Content-Type: application/json
|
||||
|
||||
{"ID": "{{newOrderID}}"}
|
||||
|
||||
### Get inactive order. We have to specify `IsActiveEntity`.
|
||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
|
||||
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
|
||||
|
||||
### Activate order using `.../<servicename>.draftActivate`
|
||||
POST {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
|
||||
POST {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
|
||||
Content-Type: application/json
|
||||
|
||||
### Get active order
|
||||
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
|
||||
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
|
||||
|
||||
### Create author
|
||||
POST {{bookshop}}/admin/Authors
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
// dummy to auto-load the plugin
|
||||
@@ -1,13 +0,0 @@
|
||||
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'
|
||||
}
|
||||
@@ -1,2 +1,45 @@
|
||||
using from './currencies';
|
||||
using from './regions';
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,5 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@sap/cds": "*"
|
||||
},
|
||||
"cds": {
|
||||
"requires": {
|
||||
"@capire/common/data": {
|
||||
"model": "@capire/common"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using { sap.common } from '@sap/cds/common';
|
||||
namespace sap.common.countries;
|
||||
|
||||
extend common.Countries {
|
||||
regions : Composition of many Regions on regions._parent = $self.code;
|
||||
}
|
||||
|
||||
entity Regions : 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 : common.CodeList {
|
||||
key code : String(11);
|
||||
region : Association to Regions;
|
||||
districts : Composition of many Districts on districts.city = $self;
|
||||
}
|
||||
entity Districts : common.CodeList {
|
||||
key code : String(11);
|
||||
city : Association to Cities;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import cds from '@sap/cds/eslint.config.mjs'
|
||||
export default [ ...cds.recommended ]
|
||||
|
||||
//
|
||||
// The above is the recommended minimalistic eslint config, just using
|
||||
// recommended defaults provided by cds. Alternatively, go for enhanced
|
||||
// project-specific options, but only if really required, like this:
|
||||
//
|
||||
// export default [ ...cds.recommended, {
|
||||
// rules: {
|
||||
// 'complexity': [ 'warn', 66 ],
|
||||
// 'require-await': 'warn',
|
||||
// 'no-await-in-loop': 'warn',
|
||||
// },
|
||||
// }, {
|
||||
// ignores: [
|
||||
// '**/webapp/**'
|
||||
// ]
|
||||
// }]
|
||||
//
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"version": "1.1.0",
|
||||
"options": {
|
||||
"management": true,
|
||||
"messagingrest": true,
|
||||
"messaging": true
|
||||
},
|
||||
"rules": {
|
||||
"topicRules": {
|
||||
"publishFilter": [
|
||||
"*"
|
||||
],
|
||||
"subscribeFilter": [
|
||||
"*"
|
||||
]
|
||||
},
|
||||
"queueRules": {
|
||||
"publishFilter": [
|
||||
"*"
|
||||
],
|
||||
"subscribeFilter": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"authorities": [
|
||||
"$ACCEPT_GRANTED_AUTHORITIES"
|
||||
]
|
||||
}
|
||||
@@ -2,20 +2,25 @@ Books = Books
|
||||
Book = Book
|
||||
ID = ID
|
||||
Title = Title
|
||||
Description = Description
|
||||
Stock = Stock
|
||||
Image = Image
|
||||
Price = Price
|
||||
Currency = Currency
|
||||
|
||||
Authors = Authors
|
||||
Author = Author
|
||||
AuthorID = Author''s ID
|
||||
AuthorID = Author ID
|
||||
Stock = Stock
|
||||
Name = Name
|
||||
AuthorName = Author's Name
|
||||
DateOfBirth = Date of Birth
|
||||
DateOfDeath = Date of Death
|
||||
PlaceOfBirth = Place of Birth
|
||||
PlaceOfDeath = Place of Death
|
||||
Age = Age
|
||||
Authors = Authors
|
||||
Order = Order
|
||||
Orders = Orders
|
||||
Price = Price
|
||||
|
||||
Genres = Genres
|
||||
Genre = Genre
|
||||
Genres = Genres
|
||||
SubGenres = Sub Genres
|
||||
|
||||
NumCode = Numeric Code
|
||||
MinorUnit = Minor Unit
|
||||
Exponent = Exponent
|
||||
@@ -1,12 +1,14 @@
|
||||
Books = Bücher
|
||||
Book = Buch
|
||||
ID = ID
|
||||
Title = Titel
|
||||
Description = Beschreibung
|
||||
Stock = Bestand
|
||||
Image = Bild
|
||||
Price = Preis
|
||||
Currency = Währung
|
||||
|
||||
Authors = Autoren
|
||||
Author = Autor
|
||||
AuthorID = ID des Autors
|
||||
AuthorName = Name des Autors
|
||||
Age = Alter
|
||||
Name = Name
|
||||
Stock = Bestand
|
||||
Order = Bestellung
|
||||
Orders = Bestellungen
|
||||
Price = Preis
|
||||
@@ -1,8 +1,6 @@
|
||||
using { AdminService } from '@capire/bookstore';
|
||||
using { AdminService } from '@capire/bookshop';
|
||||
using from '../common'; // to help UI linter get the complete annotations
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Object Page
|
||||
@@ -42,34 +40,28 @@ annotate AdminService.Books with @(
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Value Help for Tree Table
|
||||
//
|
||||
annotate AdminService.Books with {
|
||||
genre @(Common: {
|
||||
Label : 'Genre',
|
||||
ValueList: {
|
||||
CollectionPath : 'Genres',
|
||||
Parameters : [
|
||||
{
|
||||
$Type : 'Common.ValueListParameterDisplayOnly',
|
||||
ValueListProperty: 'name',
|
||||
},
|
||||
{
|
||||
$Type : 'Common.ValueListParameterInOut',
|
||||
LocalDataProperty: genre_ID,
|
||||
ValueListProperty: 'ID',
|
||||
}
|
||||
],
|
||||
}
|
||||
});
|
||||
}
|
||||
annotate AdminService.Authors with @(
|
||||
UI: {
|
||||
HeaderInfo: {
|
||||
Description: {Value: lifetime}
|
||||
},
|
||||
Facets: [
|
||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
|
||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Books}', Target: 'books/@UI.LineItem'},
|
||||
],
|
||||
FieldGroup#Details: {
|
||||
Data: [
|
||||
{Value: placeOfBirth},
|
||||
{Value: placeOfDeath},
|
||||
{Value: dateOfBirth},
|
||||
{Value: dateOfDeath},
|
||||
{Value: age, Label: '{i18n>Age}'},
|
||||
]
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Hide ID because of the ValueHelp
|
||||
annotate AdminService.Genres with {
|
||||
ID @UI.Hidden;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -91,22 +83,12 @@ annotate AdminService.Books.texts with @(
|
||||
}
|
||||
);
|
||||
|
||||
annotate AdminService.Books.texts with {
|
||||
ID @UI.Hidden;
|
||||
ID_texts @UI.Hidden;
|
||||
};
|
||||
|
||||
// Add Value Help for Locales
|
||||
annotate AdminService.Books.texts {
|
||||
locale @(
|
||||
ValueList.entity:'Languages', Common.ValueListWithFixedValues, //show as drop down, not a dialog
|
||||
)
|
||||
locale @ValueList:{entity:'Languages',type:#fixed}
|
||||
}
|
||||
// In addition we need to expose Languages through AdminService as a target for ValueList
|
||||
using { sap } from '@sap/cds/common';
|
||||
extend service AdminService {
|
||||
@readonly entity Languages as projection on sap.common.Languages;
|
||||
}
|
||||
|
||||
// Workaround for Fiori popup for asking user to enter a new UUID on Create
|
||||
annotate AdminService.Books with { ID @Core.Computed; }
|
||||
@@ -1,6 +1,6 @@
|
||||
sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) {
|
||||
"use strict";
|
||||
return AppComponent.extend("books.Component", {
|
||||
return AppComponent.extend("admin.Component", {
|
||||
metadata: { manifest: "json" }
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user