Compare commits

..

40 Commits

Author SHA1 Message Date
Elena Oresharova
7b31657f69 Update 2020-04-07 11:29:11 +02:00
Christian Georgi
2f52cbd918 Add package-lock.json, fix readme, remove hana-client 2020-04-02 16:07:58 +02:00
Christian Georgi
71742e1e35 Update readme 2020-03-23 17:09:38 +01:00
Elena Oresharova
25e3d5261c Update package.json 2020-02-09 13:14:08 +01:00
Elena Oresharova
edc2fdae91 Update for unit 6 2020-02-09 13:13:02 +01:00
Christian Georgi
13480ad99e Added issue URL again 2020-02-04 09:11:28 +01:00
Daniel
8071faa62d Adding requires.db: {kind:'sql'} 2020-02-03 07:55:56 +01:00
johannes-vogel
9ea294586a remove link 2020-01-31 08:49:54 +01:00
Lakshmi C Rajeev
a56a11ff3e Create index.cds 2020-01-28 10:58:24 +05:30
Matthias Bühl
b4084b45cb rollback change in master 2020-01-27 15:33:14 +01:00
Matthias Bühl
26e3c0d753 check autthorization in cat service 2020-01-27 15:29:43 +01:00
Lakshmi C Rajeev
6d0194acc0 Merge pull request #12 from LakshmiCR/master
Media-server implementation
2020-01-17 15:02:15 +05:30
Lakshmi C Rajeev
db75a99808 Merge branch 'master' into master 2020-01-17 15:01:59 +05:30
Volker Buzek
a04755efed feat(npm): add .npmrc for @sap-scope
- `npm set @sap...` is unnecessary
- update README.md accordingly
2020-01-14 14:55:36 +01:00
Daniel
6a9a1bc4d6 cleaned up dot files 2020-01-04 07:27:19 +01:00
Daniel
a0847e603f settings.json restored 2020-01-04 07:24:11 +01:00
Daniel
b1270bc0eb fixed launch scripts 2020-01-04 07:16:05 +01:00
Lakshmi C Rajeev
ba72d7f478 Update package.json 2020-01-03 14:29:53 +05:30
Lakshmi C Rajeev
cd808c76dd Update media-service.js 2020-01-03 14:07:17 +05:30
Daniel
3a77707f49 Merge pull request #17 from SAP-samples/cleanup
cleaned up start scripts
2020-01-03 03:03:23 +01:00
Daniel
583c97a494 cleaned up start scripts 2020-01-03 02:59:27 +01:00
Daniel
eb7431afed fixed: dev dependency to sqlite3 2019-12-30 13:32:02 +01:00
Lakshmi C Rajeev
630bb2b19c Update package.json 2019-12-19 10:59:57 +05:30
Lakshmi C Rajeev
f9a7aa59de Update media-service.js 2019-12-19 10:43:22 +05:30
Daniel
c0bce5ae5b Merge pull request #14 from SAP-samples/new-fiori-theme
using sap_fiori_3 theme
2019-12-13 20:09:49 +01:00
Daniel
ad05e2b9db using sap_fiori_3 theme 2019-12-13 20:08:41 +01:00
Christian Georgi
b7c2eee961 Fix broken link to VS Code plugin
Fixes #13
2019-12-13 11:55:52 +01:00
Lakshmi C Rajeev
9205e0893a Update media-service.js 2019-12-02 15:27:38 +05:30
Lakshmi C Rajeev
7137bf227e Media-server 2019-11-29 12:30:07 +05:30
Daniel
c2d0fba1d8 Merge pull request #9 from SAP-samples/cleanup
removed total and netAmount
2019-11-22 17:13:03 +01:00
Daniel
345d7fa37b removed total and netAmount 2019-11-18 14:50:45 +01:00
Daniel
88c1aa0282 Delete .cdsrc.json 2019-11-06 16:31:52 +01:00
Heiko Witteborg
c4cd02dbe9 Merge pull request #7 from SAP-samples/samples-revisited
samples revisited after teched
2019-10-29 09:53:55 +01:00
Christian Georgi
b9269ad437 Fix postman collection 2019-10-25 17:18:09 +02:00
Christian Georgi
2783197f1c Fix typo in sample data 2019-10-25 17:01:00 +02:00
Christian Georgi
3238b8b045 Readme improved
Install instructions, more links
2019-10-25 16:52:50 +02:00
D065023
dcac8fe7d2 added .cdsrc.json 2019-10-25 09:49:34 +02:00
d049904
cc3aca29ef samples revisited after teched 2019-10-24 12:03:37 +02:00
indusankar89
baaa5ef7d7 github repo, license corrrection 2019-09-17 11:54:21 +05:30
Stephen Cherian
e657683322 Fix broken link 2019-09-07 18:31:17 +05:30
61 changed files with 2311 additions and 1087 deletions

View File

@@ -6,7 +6,7 @@
"jest": true
},
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"globals": {
"SELECT": true,

3
.npmrc
View File

@@ -1,2 +1 @@
@sap:registry=https://npm.sap.com
package-lock=false
@sap:registry=https://npm.sap.com

37
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,37 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
"args": [ "--", "cds", "run", "--in-memory" ],
"cwd": "${workspaceFolder}/packages/bookshop",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
},
{
"name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
"args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ],
"cwd": "${workspaceFolder}/packages/${input:service}",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}
],
"inputs": [
{
"type": "pickString",
"id": "service",
"description": "Which service do you want to start?",
"options": [
"bookshop",
"bookstore",
"media-server",
"office-supplies",
"reviews-service"
],
"default": "bookshop"
}
]
}

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"files.exclude": {
"**/.gitignore": true,
"**/.vscode": true
}
}

17
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm", "script": "watch", "path": "packages/bookshop/",
"options": { "env": { "PORT": "4004" }},
"presentation": { "group": "A" }
},
{
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
"options": { "env": { "PORT": "5005" }},
"presentation": { "group": "A" }
}
]
}

View File

@@ -1,3 +1,42 @@
# Final state of exercise 4 for CAA265 - Rapid Service Development with SAP Cloud Application Programming Model
# Welcome to SAP Cloud Application Programming model samples
**DO NOT MERGE IN MASTER**
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
## Get Access to SAP Business Application Studio
The recommended environment for the course is SAP Business Application Studio. Watch [unit 2 of week 1](https://open.sap.com/courses/cp7/items/51pzQUzbXHr2kdbOmVs6jI) for how to get access.
## Setup
In SAP Business Application Studio, open a terminal.
Then clone the repo with this specific branch:
```sh
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit6
cd projects/cloud-cap-samples
```
In the `cloud-cap-samples` folder run:
```sh
npm install
```
## Run
Now you're ready to run the samples, for example:
```sh
cd packages/bookshop
cds watch
```
After that, watch out for the little popup in the lower right corner of SAP Business Application Studio that asks you to open the application in your browser.
## Get Support
Check out the cap docs at https://cap.cloud.sap. <br>
In case you find a bug or need support, please [open an issue in here](https://github.com/SAP-samples/cloud-cap-samples/issues/new).
## License
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.

View File

@@ -1,7 +1 @@
{
"packages": [
"packages/*",
"shared/*"
],
"version": "0.0.0"
}
{"packages":["packages/*"],"version":"1.0.0"}

2064
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,25 @@
{
"name": "@sap/capire-samples",
"description": "The umbrella project for all samples to easily setup for local development and tests.",
"repository": "https://github.wdf.sap.corp/capire/samples.git",
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
"author": "daniel.hutzel@sap.com",
"private": true,
"scripts": {
"install": "(npx --no-install lerna -v || npm i lerna --no-save) && lerna bootstrap --hoist --ignore tests-env --loglevel warn",
"reset": "lerna clean -y && rm -fr node_modules",
"test": "jest",
"bookstore": "cds run packages/bookstore --in-memory",
"products-service": "cds run packages/products-service --in-memory",
"reviews-service": "cds run packages/reviews-service --in-memory"
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
"cleanup": "lerna clean -y && rm -fr node_modules",
"bookshop": "cds watch packages/bookshop"
},
"license": "ISC"
"dependencies": {
"@sap/cds": "^3",
"express": "^4"
},
"devDependencies": {
"sqlite3": "*"
},
"--add-these-to-devDependencies-for-tests": {
"@types/jest": "*",
"jest": "*"
},
"license": "SAP SAMPLE CODE LICENSE"
}

View File

@@ -1,3 +0,0 @@
{
"cds_version": "^3.17.4"
}

View File

@@ -0,0 +1,23 @@
namespace sap.capire.bookshop;
@cds.persistence.exists
entity Books {
key ID: Integer;
title : String(111);
descr : String(1111);
author : String(50);
rating : Integer;
}
@cds.persistence.exists
entity BooksDescr {
key id : Integer;
book_descr : String(2000);
}
@cds.persistence.exists
entity BooksInfo (REQ_RATING : Integer) {
key id : Integer;
rating : Integer;
book_author_info : String;
}

View File

@@ -0,0 +1,10 @@
{
"file_suffixes": {
"hdbtable": { "plugin_name": "com.sap.hana.di.table", "plugin_version": "11.1.0" },
"hdbview": { "plugin_name": "com.sap.hana.di.view" },
"hdbfunction": { "plugin_name": "com.sap.hana.di.function" },
"hdbtabletype": { "plugin_name": "com.sap.hana.di.tabletype", "plugin_version": "11.1.0" },
"hdbtabledata": { "plugin_name": "com.sap.hana.di.tabledata", "plugin_version": "11.1.0" },
"csv": { "plugin_name" : "com.sap.hana.di.tabledata.source" }
}
}

View File

@@ -0,0 +1,4 @@
{
"name": "",
"subfolder": "ignore"
}

View File

@@ -0,0 +1,4 @@
ID;TITLE;DESCR;AUTHOR;RATING
301;Anna Karenina;"Anna Karenina (Russian: «Анна Каренина», IPA: [ˈanːə kɐˈrʲenʲɪnə])[1] is a novel by the Russian author Leo Tolstoy, first published in book form in 1878. Many writers consider Anna Karenina the greatest work of literature ever,[2] and Tolstoy himself called it his first true novel. It was initially released in serial installments from 1873 to 1877 in the periodical The Russian Messenger.";Leo Tolstoy;4
307;The Great Gatsby;"The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional towns of West Egg and East Egg on prosperous Long Island in the summer of 1922. The story primarily concerns the young and mysterious millionaire Jay Gatsby and his quixotic passion and obsession with the beautiful former debutante Daisy Buchanan. Considered to be Fitzgerald's magnum opus, The Great Gatsby explores themes of decadence, idealism, resistance to change, social upheaval and excess, creating a portrait of the Roaring Twenties that has been described as a cautionary[a] tale regarding the American Dream.";F. Scott Fitzgerald;4
406;Harry Potter;"Harry Potter is a series of fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).";J. K. Rowling;5
1 ID TITLE DESCR AUTHOR RATING
2 301 Anna Karenina Anna Karenina (Russian: «Анна Каренина», IPA: [ˈanːə kɐˈrʲenʲɪnə])[1] is a novel by the Russian author Leo Tolstoy, first published in book form in 1878. Many writers consider Anna Karenina the greatest work of literature ever,[2] and Tolstoy himself called it his first true novel. It was initially released in serial installments from 1873 to 1877 in the periodical The Russian Messenger. Leo Tolstoy 4
3 307 The Great Gatsby The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional towns of West Egg and East Egg on prosperous Long Island in the summer of 1922. The story primarily concerns the young and mysterious millionaire Jay Gatsby and his quixotic passion and obsession with the beautiful former debutante Daisy Buchanan. Considered to be Fitzgerald's magnum opus, The Great Gatsby explores themes of decadence, idealism, resistance to change, social upheaval and excess, creating a portrait of the Roaring Twenties that has been described as a cautionary[a] tale regarding the American Dream. F. Scott Fitzgerald 4
4 406 Harry Potter Harry Potter is a series of fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people). J. K. Rowling 5

View File

@@ -0,0 +1,8 @@
COLUMN TABLE SAP_CAPIRE_BOOKSHOP_BOOKS (
ID INTEGER NOT NULL,
TITLE NVARCHAR(111),
DESCR NVARCHAR(1111),
AUTHOR NVARCHAR(50),
RATING INTEGER,
PRIMARY KEY(ID)
)

View File

@@ -0,0 +1,19 @@
{
"format_version": 1,
"imports": [
{
"target_table": "SAP_CAPIRE_BOOKSHOP_BOOKS",
"source_data": {
"data_type": "CSV",
"file_name": "Books.csv",
"has_header": true,
"no_data_import": false,
"delete_existing_foreign_data": false,
"dialect": "HANA",
"type_config": {
"delimiter": ";"
}
}
}
]
}

View File

@@ -0,0 +1,10 @@
FUNCTION SAP_CAPIRE_BOOKSHOP_BOOKSDESCR
RETURNS TABLE (ID integer, BOOK_DESCR nvarchar(2000))
LANGUAGE SQLSCRIPT
AS
BEGIN
RETURN SELECT
100 + ID AS ID,
'From my HANA function: A summary for the book ' || TITLE || ': ' || DESCR AS BOOK_DESCR
FROM SAP_CAPIRE_BOOKSHOP_BOOKS;
END

View File

@@ -0,0 +1,6 @@
VIEW SAP_CAPIRE_BOOKSHOP_BOOKSINFO (in REQ_RATING integer) AS SELECT
ID,
RATING,
'From my HANA view: The book ' || TITLE || ' is authored by ' || AUTHOR AS BOOK_AUTHOR_INFO
FROM SAP_CAPIRE_BOOKSHOP_BOOKS
WHERE RATING = :REQ_RATING;

View File

@@ -0,0 +1,25 @@
{
"name": "@sap/capire-bookshop",
"version": "1.0.0",
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
"license": "SAP SAMPLE CODE LICENSE",
"dependencies": {
"@sap/cds": "^3",
"express": "^4",
"hdb": "^0.17.1"
},
"scripts": {
"start": "cds run --in-memory?",
"watch": "cds watch"
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
}
},
"devDependencies": {
"@sap/hdi-deploy": "3.7.0"
}
}

View File

@@ -0,0 +1,9 @@
using { sap.capire.bookshop as db } from '../db/schema';
service CatalogService {
entity Books as projection on db.Books;
entity BooksInfo (RATING : Integer) as select from db.BooksInfo(REQ_RATING: :RATING) {*};
entity BooksDescr as select from db.BooksDescr;
}

View File

@@ -0,0 +1,8 @@
# Get all books
GET http://localhost:4004/catalog/Books
# Get books description from the HANA function
GET http://localhost:4004/catalog/BooksDescr
# Get books with rating 4 via the HANA view
GET http://localhost:4004/catalog/BooksInfo(RATING=4)/Set

View File

@@ -1,6 +0,0 @@
{
"build": {
"target": ".",
"tasks": []
}
}

View File

@@ -1,15 +0,0 @@
.che/
.gen/
gen/
mta_archives/
node_modules/
target/
.cds_gen.log
connection.properties
*.db
.DS_Store
*.orig
_out
default-*.json
package-lock.json

View File

@@ -1,12 +0,0 @@
/* global hasher */
sap.ui.define([
"sap/fe/AppComponent"
], function (AppComponent) {
"use strict";
return AppComponent.extend("ns.bookList.Component", {
metadata: {
"manifest": "json"
}
});
});

View File

@@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<display-name>OData v4</display-name>
<!-- ============================================================== -->
<!-- UI5 resource servlet used to handle application resources -->
<!-- ============================================================== -->
<servlet>
<display-name>ResourceServlet</display-name>
<servlet-name>ResourceServlet</servlet-name>
<servlet-class>com.sap.ui5.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ResourceServlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ResourceServlet</servlet-name>
<url-pattern>/test-resources/*</url-pattern>
</servlet-mapping>
<!-- enable CORS -->
<context-param>
<param-name>com.sap.ui5.resource.ACCEPTED_ORIGINS</param-name>
<param-value>*</param-value>
</context-param>
<!-- BEGIN: DEV MODE -->
<!-- DEV MODE switched off by default and can be switched on during development -->
<!-- but has to be switched off for productive use on a Java server! -->
<context-param>
<param-name>com.sap.ui5.resource.DEV_MODE</param-name>
<param-value>true</param-value>
</context-param>
<!-- END: DEV MODE -->
<!-- ============================================================== -->
<!-- Cache Control Filter to prevent caching of any resource -->
<!-- ============================================================== -->
<filter>
<display-name>CacheControlFilter</display-name>
<filter-name>CacheControlFilter</filter-name>
<filter-class>com.sap.ui5.resource.CacheControlFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.css</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.json</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.xml</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.png</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.properties</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>*.tmpl</url-pattern>
</filter-mapping>
<!-- ============================================================== -->
<!-- UI5 proxy servlet -->
<!-- ============================================================== -->
<servlet>
<servlet-name>SimpleProxyServlet</servlet-name>
<servlet-class>com.sap.ui5.proxy.SimpleProxyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleProxyServlet</servlet-name>
<url-pattern>/proxy/*</url-pattern>
</servlet-mapping>
<!-- ============================================================== -->
<!-- Welcome file list -->
<!-- ============================================================== -->
<welcome-file-list>
<welcome-file>test.html</welcome-file>
</welcome-file-list>
</web-app>

View File

@@ -1,7 +0,0 @@
# This is the resource bundle for bookList#Texts for manifest.json
#XTIT: Application name
appTitle=bookList
#YDES: Application description
appDescription=bookList

View File

@@ -1,39 +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>{{appTitle}}</title>
<script>
window["sap-ushell-config"] = {
defaultRenderer: "fiori2",
applications: {
"fe-lrop-v4": {
title: "bookList",
description: "bookList",
additionalInformation: "SAPUI5.Component=ns.bookList",
applicationType : "URL",
url: "./",
navigationMode: "embedded"
}
}
};
</script>
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell"
data-sap-ui-compatVersion="edge"
data-sap-ui-theme="sap_belize"
data-sap-ui-frameOptions="allow"
></script>
<script>
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
</script>
</head>
<body class="sapUiBody" id="content"></body>
</html>

View File

@@ -1,134 +0,0 @@
{
"_version": "1.15.0",
"sap.app": {
"id": "ns.bookList",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"ach": "CA-UI5-FE",
"dataSources": {
"mainService": {
"uri": "catalog/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
}
}
},
"offline": false,
"resources": "resources.json",
"sourceTemplate": {
"id": "ui5template.fiorielements.v4.lrop",
"version": "1.0.0"
}
},
"sap.ui": {
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
}
},
"sap.ui5": {
"resources": {
"js": [],
"css": []
},
"dependencies": {
"minUI5Version": "1.60.1",
"libs": {
"sap.fe": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"uri": "i18n/i18n.properties"
},
"": {
"dataSource": "mainService",
"settings": {
"synchronizationMode": "None",
"operationMode": "Server",
"autoExpandSelect": true,
"earlyRequests": true
}
}
},
"routing": {
"routes": [
{
"pattern": "",
"name": "BooksList",
"target": "BooksList"
},
{
"pattern": "Books({key})",
"name": "BooksObjectPage",
"target": "BooksObjectPage"
}
],
"targets": {
"BooksList": {
"type": "Component",
"id": "BooksList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings" : {
"entitySet" : "Books",
"variantManagement": "Page",
"navigation" : {
"Books" : {
"detail" : {
"route" : "BooksObjectPage"
}
}
}
}
}
},
"BooksObjectPage": {
"type": "Component",
"id": "BooksObjectPage",
"name": "sap.fe.templates.ObjectPage",
"options": {
"settings" : {
"entitySet" : "Books"
}
}
}
}
},
"contentDensities": {
"compact": true,
"cozy": true
}
},
"sap.platform.abap": {
"_version": "1.1.0",
"uri": ""
},
"sap.platform.hcp": {
"_version": "1.1.0",
"uri": ""
},
"sap.fiori": {
"_version": "1.1.0",
"registrationIds": [],
"archeType": "transactional"
}
}

View File

@@ -1,23 +0,0 @@
{
"welcomeFile": "/index.html",
"authenticationMethod": "none",
"logout": {
"logoutEndpoint": "/do/logout"
},
"routes": [
{
"source": "^/catalog/(.*)$",
"target": "$1",
"destination": "srv-api",
"csrfProtection": false,
"authenticationType": "none"
},
{
"source": "^(.*)$",
"target": "$1",
"service": "html5-apps-repo-rt",
"authenticationType": "xsuaa"
}
]
}

View File

@@ -1,66 +0,0 @@
using sap.capire.bookstore.CatalogService as CatalogService from '../srv/services';
////////////////////////////////////////////////////////////////////////////
//
// Books Lists
//
annotate CatalogService.Books with @(
UI: {
HeaderFacets: [
{$Type: 'UI.ReferenceFacet', Label: 'Description', Target: '@UI.FieldGroup#Descr'},
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Details', Target: '@UI.FieldGroup#Price'},
],
FieldGroup#Descr: {
Data: [
{Value: descr},
]
},
FieldGroup#Price: {
Data: [
{Value: price},
{Value: currency.symbol, Label: 'Currency'},
]
},
Identification: [{Value:title}],
SelectionFields: [ ID, price, currency_code ],
LineItem: [
{Value: ID},
{Value: title},
{Value: author_ID, Label:'Author ID'},
{Value: stock},
{Value: price},
{Value: currency.symbol, Label:''},
]
}
);
////////////////////////////////////////////////////////////////////////////
//
// Books Details
//
annotate CatalogService.Books with @(
UI: {
HeaderInfo: {
TypeName: 'Book',
TypeNamePlural: 'Books',
Title: {Value: title},
},
}
);
////////////////////////////////////////////////////////////////////////////
//
// Books Elements
//
annotate CatalogService.Books with {
ID @title:'ID' @UI.HiddenFilter;
title @title:'Title';
author @title:'Author ID';
price @title:'Price';
stock @title:'Stock';
descr @UI.MultiLineText;
}

View File

@@ -1,5 +0,0 @@
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;Kings Lynn, Norfolk;2012-02-26;Hertfordshire, England
1 ID name dateOfBirth placeOfBirth dateOfDeath placeOfDeath
2 101 Emily Brontë 1818-07-30 Thornton, Yorkshire 1848-12-19 Haworth, Yorkshire
3 107 Charlotte Brontë 1818-04-21 Thornton, Yorkshire 1855-03-31 Haworth, Yorkshire
4 150 Edgar Allen Poe 1809-01-19 Boston, Massachusetts 1849-10-07 Baltimore, Maryland
5 170 Richard Carpenter 1929-08-14 King’s Lynn, Norfolk 2012-02-26 Hertfordshire, England

View File

@@ -1,4 +0,0 @@
ID;amount;parent_ID;book_ID;netAmount
301;1;401;201;11.11
302;1;401;271;15
303;2;402;252;28
1 ID amount parent_ID book_ID netAmount
2 301 1 401 201 11.11
3 302 1 401 271 15
4 303 2 402 252 28

View File

@@ -1,3 +0,0 @@
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
401;;2019-01-31;john.doe@test.com;;1;EUR
402;;2019-01-30;christian.georgi@sap.com;;2;EUR
1 ID modifiedAt createdAt createdBy modifiedBy OrderNo currency_code
2 401 2019-01-31 john.doe@test.com 1 EUR
3 402 2019-01-30 christian.georgi@sap.com 2 EUR

View File

@@ -1,11 +0,0 @@
ID;parent_ID;name
1;;Poetry
2;;Biography
3;;Fantasy
4;;Science Fiction
5;;Romance
6;;Mystery
7;;Thriller
8;;Dystopia
9;;Tragedy
10;;Novel
1 ID parent_ID name
2 1 Poetry
3 2 Biography
4 3 Fantasy
5 4 Science Fiction
6 5 Romance
7 6 Mystery
8 7 Thriller
9 8 Dystopia
10 9 Tragedy
11 10 Novel

View File

@@ -1,6 +0,0 @@
ID;title;descr;author_ID;stock;price;currency_code;category_ID
201;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;12;11.11;GBP;9
207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP;10
251;The Raven;"“The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD;1
252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD;5
271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;15;EUR;3
1 ID title descr author_ID stock price currency_code category_ID
2 201 Wuthering Heights Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym "Ellis Bell". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850. 101 12 11.11 GBP 9
3 207 Jane Eyre Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name "Currer Bell", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism. 107 11 12.34 GBP 10
4 251 The Raven “The Raven" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word "Nevermore". The poem makes use of folk, mythological, religious, and classical references. 150 333 13.13 USD 1
5 252 Eleonora "Eleonora" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively "happy" ending. 150 555 14 USD 5
6 271 Catweazle Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts. 170 22 15 EUR 3

View File

@@ -1,4 +0,0 @@
ID;locale;title;descr
201;de;Sturmhöhe;Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (18181848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts.
207;de;Jane Eyre;Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte
252;de;Eleonora;“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit.
1 ID locale title descr
2 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.
3 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
4 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.

View File

@@ -1,7 +0,0 @@
code;symbol;name;descr
EUR;€;Euro;European Euro
USD;$;US Dollar;United States Dollar
CAD;$;Canadian Dollar;Canadian Dollar
AUD;$;Australian Dollar;Australian Dollar
GBP;£;Pound;Great Britian Pound
ILS;₪;Shekel;Israeli New Shekel
1 code symbol name descr
2 EUR Euro European Euro
3 USD $ US Dollar United States Dollar
4 CAD $ Canadian Dollar Canadian Dollar
5 AUD $ Australian Dollar Australian Dollar
6 GBP £ Pound Great Britian Pound
7 ILS Shekel Israeli New Shekel

View File

@@ -1,13 +0,0 @@
code;locale;name;descr
EUR;de;Euro;European Euro
USD;de;US-Dollar;United States Dollar
CAD;de;Kanadischer Dollar;Kanadischer Dollar
AUD;de;Australischer Dollar;Australischer Dollar
GBP;de;Pfund;Britische Pfund
ILS;de;Schekel;Israelische Schekel
EUR;fr;euro;de la Zone euro
USD;fr;dollar;dollar des États-Unis
CAD;fr;dollar canadien;dollar canadien
AUD;fr;dollar australien;dollar australien
GBP;fr;livre sterling;pound sterling
ILS;fr;Shekel;shekel israelien
1 code locale name descr
2 EUR de Euro European Euro
3 USD de US-Dollar United States Dollar
4 CAD de Kanadischer Dollar Kanadischer Dollar
5 AUD de Australischer Dollar Australischer Dollar
6 GBP de Pfund Britische Pfund
7 ILS de Schekel Israelische Schekel
8 EUR fr euro de la Zone euro
9 USD fr dollar dollar des États-Unis
10 CAD fr dollar canadien dollar canadien
11 AUD fr dollar australien dollar australien
12 GBP fr livre sterling pound sterling
13 ILS fr Shekel shekel israelien

View File

@@ -1,35 +0,0 @@
namespace sap.capire.bookstore;
// We reuse Products, which are Books in our domain
using { sap.capire.products.Products as Books } from '@sap/capire-products';
using { Currency, managed } from '@sap/cds/common';
extend Books with {
author : Association to Authors;
}
entity Authors : managed {
key ID : Integer;
name : String(111);
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;
}
entity Orders : managed {
key ID : Integer;
OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many OrderItems on Items.parent = $self;
total : Decimal(9,2) @readonly;
currency : Currency;
}
entity OrderItems {
key ID : Integer;
parent : Association to Orders;
book : Association to Books;
amount : Integer;
netAmount : Decimal(9,2);
}

View File

@@ -1,32 +0,0 @@
{
"name": "bookstore",
"description": "Generated by cds init",
"repository": "<Add your repository here>",
"license": "ISC",
"version": "1.0.0",
"engines": {
"node": "^8.9"
},
"dependencies": {
"@sap/capire-products": "^1.0.0",
"reviews-service": "file:packages/reviews-service-1.0.0.tgz",
"@sap/cds": "^3.17.4",
"express": "^4.17.1"
},
"scripts": {
"build": "cds build/all --clean",
"deploy": "cds deploy",
"start": "cds run"
},
"cds": {
"requires": {
"sap.capire.reviews.ReviewsService": {
"model": "reviews-service",
"kind": "odata",
"credentials": {
"file": "default"
}
}
}
}
}

View File

@@ -1,24 +0,0 @@
namespace sap.capire.bookstore;
using { sap.capire.products.Products, sap.capire.bookstore as my } from '../db/schema';
service CatalogService {
@readonly entity Books as projection on Products {
*, category.name as category, author.name
} excluding { createdBy, modifiedBy };
@insertonly entity Orders as projection on my.Orders;
}
// Reuse services from @sap/capire-products...
using { sap.capire.products.AdminService } from '@sap/capire-products';
extend service AdminService with {
entity Authors as projection on my.Authors;
}
// Adding reviews via capire-reviews service
using { sap.capire.reviews.ReviewsService as external} from 'reviews-service';
extend service CatalogService {
@readonly entity Reviews @(cds.persistence.skip) as projection on external.Reviews;
}

View File

@@ -1,35 +0,0 @@
const cds = require('@sap/cds')
module.exports = async (srv) => {
const { Books } = srv.entities
// Check all amounts against stock before activating
srv.before(['CREATE', 'UPDATE'], 'Orders', (req) => {
const tx = cds.transaction(req), order = req.data
return Promise.all(order.Items.map(each => tx.run(
UPDATE(Books).where({ ID: each.book_ID })
.and(`stock >=`, each.amount)
.set(`stock -=`, each.amount)
).then(affectedRows => {
if (!affectedRows) {
req.error(409, `${each.amount} exceeds stock for book #${each.book_ID}`)
}
})))
})
const reviews_srv = await cds.connect.to('sap.capire.reviews.ReviewsService')
// react on event messages from reviews service
reviews_srv.on('reviewed', (msg) => {
console.debug('> received', msg)
})
// delegate requests to reviews service
srv.on('READ', 'Reviews', async (req) => {
const { Reviews } = reviews_srv.entities
const tx = reviews_srv.transaction(req)
const results = await tx.read(Reviews)
return results
})
}

View File

@@ -1,12 +0,0 @@
gen/
.gen/
node_modules/
target/
*.db
.DS_Store
_out
.che/
.cds_gen.log
package-lock.json
*.orig
mta_archives/

View File

@@ -1,19 +0,0 @@
namespace sap.capire.products;
using { Currency, cuid, managed, sap.common.CodeList } from '@sap/cds/common';
entity Products : cuid, managed {
key ID : String(36);
title : localized String(111);
descr : localized String(1111);
stock : Integer;
price : Decimal(9,2);
currency : Currency;
category : Association to Categories;
}
entity Categories : CodeList {
key ID : Integer;
parent : Association to Categories;
children : Composition of many Categories on children.parent = $self;
}

View File

@@ -1,2 +0,0 @@
using from './db/schema';
using from './srv/admin-service';

View File

@@ -1,16 +0,0 @@
{
"name": "@sap/capire-products",
"version": "1.0.0",
"description": "A reuse package providing domain models and services to manage product catalogs.",
"repository": "https://github.wdf.sap.corp/caps/products-service.git",
"license": "ISC",
"dependencies": {
"@sap/cds": "^3.17.4",
"express": "^4.17.1"
},
"files": [
"db",
"srv",
"index.cds"
]
}

View File

@@ -1,7 +0,0 @@
using { sap.capire.products as db } from '../db/schema';
namespace sap.capire.products;
service AdminService @(_requires:'admin') {
entity Products as projection on db.Products;
entity Categories as projection on db.Categories;
}

View File

@@ -1,68 +0,0 @@
const cds = require ('@sap/cds')
describe('reading/writing hierarchies', ()=>{
it ('should prepare to sqlite in-memory', async()=>{
await cds.deploy (__dirname+'/../db') .to ('sqlite::memory:')
expect (cds.model) .toBeDefined()
})
it ('should insert hierarchy of categories', ()=>{
const { Categories } = cds.entities
return INSERT.into (Categories) .entries (
{ ID:100, name:'Some Sample Categories...', children:[
{ ID:101, name:'Cat', children:[
{ ID:102, name:'Kitty', children:[
{ ID:103, name:'Kitty Cat', children:[
{ ID:104, name:'Aristocat' } ]},
{ ID:105, name:'Kitty Bat' } ]},
{ ID:106, name:'Catwoman', children:[
{ ID:107, name:'Catalina' } ]} ]},
{ ID:108, name:'Catweazle' }
]}
)
})
it ('should read categories with children', async()=>{
const { Categories } = cds.entities
expect (await
SELECT.one.from (Categories, c=>{
c.ID, c.name.as('parent'), c.children (c=>{
c.name.as('child')
})
}) .where ({name:'Cat'})
) .toMatchObject (
{ ID:101, parent:'Cat', children:[
{ child:'Kitty' },
{ child:'Catwoman' },
]}
)
})
it ('should read hierarchy of categories', async()=>{
const { Categories } = cds.entities
expect (await
SELECT.one.from (Categories, c=>{
c.ID, c.name, c.children (c=>{ c.name },{levels:3})
}) .where ({name:'Cat'})
) .toMatchObject (
{ ID:101, name:'Cat', children:[
{ name:'Kitty', children:[
{ name:'Kitty Cat', children:[
{ name:'Aristocat' }, ]},
{ name:'Kitty Bat' }, ]},
{ name:'Catwoman', children:[
{ name:'Catalina' } ]},
]}
)
})
})

View File

@@ -1,10 +0,0 @@
ID;parent_ID;name
0;;Some Sample Categories...
1;;Cat
2;1;Kitty
3;2;Kitty Cat
4;3;Aristocat
5;2;Kitty Bat
6;1;Catwoman
7;6;Catalina
8;;Catweazle
1 ID parent_ID name
2 0 Some Sample Categories...
3 1 Cat
4 2 1 Kitty
5 3 2 Kitty Cat
6 4 3 Aristocat
7 5 2 Kitty Bat
8 6 1 Catwoman
9 7 6 Catalina
10 8 Catweazle

View File

@@ -1,157 +0,0 @@
{
"info": {
"_postman_id": "0f8d4e79-a1c2-47fe-aeab-0319fb4ce180",
"name": "@sap/capire-products",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Categories",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{ \"ID\":0, \"name\":\"Some Sample Categories...\", \"children\":[\n { \"ID\":1, \"name\":\"Cat\", \"children\":[\n { \"ID\":2, \"name\":\"Kitty\", \"children\":[\n { \"ID\":3, \"name\":\"Kitty Cat\", \"children\":[\n { \"ID\":4, \"name\":\"Aristocat\" }\n ]},\n { \"ID\":5, \"name\":\"Kitty Bat\" }\n ]},\n { \"ID\":6, \"name\":\"Catwoman\", \"children\":[\n { \"ID\":7, \"name\":\"Catalina\" }\n ]}\n ] },\n { \"ID\":8, \"name\":\"Catweazle\" }\n]}\n"
},
"url": {
"raw": "http://localhost:4004/admin/cats",
"protocol": "http",
"host": [
"localhost"
],
"port": "4004",
"path": [
"admin",
"cats"
]
}
},
"response": []
},
{
"name": "Categories",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
"protocol": "http",
"host": [
"localhost"
],
"port": "4004",
"path": [
"admin",
"cats",
"0"
],
"query": [
{
"key": "$expand",
"value": "children($expand=children($expand=children($expand=children)))"
}
]
}
},
"response": [
{
"name": "Categories",
"originalRequest": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
"protocol": "http",
"host": [
"localhost"
],
"port": "4004",
"path": [
"admin",
"cats",
"0"
],
"query": [
{
"key": "$expand",
"value": "children($expand=children($expand=children($expand=children)))"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "X-Powered-By",
"value": "Express"
},
{
"key": "OData-Version",
"value": "4.0"
},
{
"key": "content-type",
"value": "application/json;odata.metadata=minimal"
},
{
"key": "Date",
"value": "Tue, 21 May 2019 19:20:24 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Content-Length",
"value": "767"
}
],
"cookie": [],
"body": "{\n \"@odata.context\": \"$metadata#cats(children(children(children(children()))))/$entity\",\n \"@odata.metadataEtag\": \"W/\\\"+AAp4JKNOcr+OusjrdQo55RCfM+UHKpTh8EbhsxyPhM=\\\"\",\n \"name\": \"Some Sample Categories...\",\n \"descr\": null,\n \"ID\": 0,\n \"parent_ID\": null,\n \"children\": [\n {\n \"name\": \"Cat\",\n \"descr\": null,\n \"ID\": 1,\n \"parent_ID\": 0,\n \"children\": [\n {\n \"name\": \"Kitty\",\n \"descr\": null,\n \"ID\": 2,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Kitty Cat\",\n \"descr\": null,\n \"ID\": 3,\n \"parent_ID\": 2,\n \"children\": [\n {\n \"name\": \"Aristocat\",\n \"descr\": null,\n \"ID\": 4,\n \"parent_ID\": 3\n }\n ]\n },\n {\n \"name\": \"Kitty Bat\",\n \"descr\": null,\n \"ID\": 5,\n \"parent_ID\": 2,\n \"children\": []\n }\n ]\n },\n {\n \"name\": \"Catwoman\",\n \"descr\": null,\n \"ID\": 6,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Catalina\",\n \"descr\": null,\n \"ID\": 7,\n \"parent_ID\": 6,\n \"children\": []\n }\n ]\n }\n ]\n },\n {\n \"name\": \"Catweazle\",\n \"descr\": null,\n \"ID\": 8,\n \"parent_ID\": 0,\n \"children\": []\n }\n ]\n}"
}
]
},
{
"name": "Categories",
"request": {
"method": "DELETE",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:4004/admin/cats/0",
"protocol": "http",
"host": [
"localhost"
],
"port": "4004",
"path": [
"admin",
"cats",
"0"
]
}
},
"response": []
}
]
}

Binary file not shown.

View File

@@ -1,6 +0,0 @@
{
"build": {
"target": ".",
"tasks": []
}
}

View File

@@ -1,15 +0,0 @@
.che/
.gen/
gen/
mta_archives/
node_modules/
target/
.cds_gen.log
connection.properties
*.db
.DS_Store
*.orig
_out
default-*.json
package-lock.json

View File

@@ -1,16 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cds run",
"request": "launch",
"type": "node", "runtimeExecutable": "npx","runtimeArgs": [ "-n" ],
"args": [ "--","cds","run","--in-memory?" ], // the leading "--" arg ensures it works with as well as without debugging
"console": "integratedTerminal",
"skipFiles": [ "<node_internals>/**" ]
}
]
}

View File

@@ -1,30 +0,0 @@
namespace sap.capire.reviews;
using { User } from '@sap/cds/common';
// Reviewed subjects can be any entity that is uniquely identified
type ReviewedSubject : String(111);
entity Reviews {
key ID : String(36);
subject : ReviewedSubject;
reviewer : User;
rating : Rating;
title : String(111);
text : String(1111);
date : DateTime;
likes : Composition of many Likes on likes.review = $self;
liked : Integer default 0; // counter for likes as helpful review (count of all _likes belonging to this review)
}
type Rating : Integer enum {
Best = 5;
Good = 4;
Avg = 3;
Poor = 2;
Worst = 1;
}
entity Likes {
key review : Association to Reviews;
key user : User;
}

View File

@@ -1 +0,0 @@
using from './srv/reviews-service';

View File

@@ -1,19 +0,0 @@
{
"name": "reviews-service",
"version": "1.0.0",
"description": "Generated by cds init",
"repository": "<Add your repository here>",
"license": "ISC",
"dependencies": {
"@sap/cds": "^3.17.4",
"express": "^4.17.1"
},
"engines": {
"node": "^8.9"
},
"scripts": {
"build": "cds build/all --clean",
"deploy": "cds deploy",
"start": "cds run"
}
}

View File

@@ -1,26 +0,0 @@
namespace sap.capire.reviews;
using { sap.capire.reviews as my } from '../db/schema';
service ReviewsService {
event reviewed : { subject:String; rating: Decimal(2,1) };
// API
entity Reviews as projection on my.Reviews excluding { likes }
action like (review:Reviews.ID);
action unlike (review:Reviews.ID);
// Input validation
annotate Reviews with {
subject @mandatory;
title @mandatory;
rating @mandatory @assert.enum;
}
// Auto-fill reviewers and review dates
annotate Reviews with {
reviewer @cds.on.insert:$user;
date @cds.on.insert:$now;
date @cds.on.update:$now;
}
}

View File

@@ -1,40 +0,0 @@
const cds = require('@sap/cds')
module.exports = cds.service.impl((srv) => {
// Get the CSN definition for Reviews from the db schema for sub-sequent queries
// ( Note: we explicitly specify the namespace to support embedded reuse )
const { Reviews, Likes } = cds.entities('sap.capire.reviews')
// Increment counter for reviews considered helpful
srv.on ('like', (req) => {
if (!req.user) return req.reject(400, 'You must be identified to like a review')
const {review} = req.data, {user} = req
const tx = cds.transaction(req)
return tx.run ([
INSERT.into (Likes) .entries ({review_ID: review, user: user.id}),
UPDATE (Reviews) .set({liked: {'+=': 1}}) .where({ID:review})
]).catch(() => req.reject(400, 'You already liked that review'))
})
// Delete a former like by the same user
srv.on('unlike', async (req) => {
if (!req.user) return req.reject(400, 'You must be identified to remove a former like of yours')
const { review } = req.data, { user } = req
const tx = cds.transaction(req)
const affectedRows = await tx.run(DELETE.from(Likes).where({ review_ID: review, user: user.id }))
if (affectedRows === 1) return tx.run(UPDATE(Reviews).set({ liked: { '-=': 1 } }).where({ ID: review }))
})
// Emit an event to inform subscribers about new avg ratings for reviewed subjects
// ( Note: req.on.succeeded ensures we only do that if there's no error )
srv.after(['CREATE', 'UPDATE', 'DELETE'], 'Reviews', async (_, req) => {
const { subject } = req.data
const { rating } = await cds.transaction(req).run(
SELECT.one(['avg(rating) as rating']).from(Reviews).where({ subject })
)
req.on('succeeded', () => {
srv.emit('reviewed', { subject, rating })
console.log(`Reviewed event was emitted for book "${subject}" with rating ${rating}.`)
})
})
})

View File

@@ -1,11 +0,0 @@
{
"name": "dev-env",
"author": "daniel.hutzel@sap.com",
"dependencies": {
"@sap/cds": "^3.17.4"
},
"devDependencies": {
"sqlite3": "^4.0.7"
},
"license": "ISC"
}

View File

@@ -1,10 +0,0 @@
{
"name": "tests-env",
"author": "daniel.hutzel@sap.com",
"devDependencies": {
"@types/jest": "*",
"jest": "^24.8.0",
"supertest": "^4.0.2"
},
"license": "ISC"
}