Using bookstore as composite app

This commit is contained in:
Daniel
2021-10-19 15:28:25 +02:00
committed by Daniel Hutzel
parent 680a6ae68f
commit 5c3cec973e
8 changed files with 8 additions and 2701 deletions

2634
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,2 @@
cds.requires.messaging.kind = file-based-messaging
# cds.requires.messaging.kind = file-based-messaging
PORT = 4005

View File

@@ -16,9 +16,13 @@
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
"messaging": {
"[production]": { "kind": "enterprise-messaging" },
"[hybrid]": { "kind": "enterprise-messaging-shared" },
"[local]": { "kind": "file-based-messaging" },
"kind": "local-messaging"
},
"db": { "kind": "sql" }
}
}
}

View File

@@ -1,3 +0,0 @@
<head>
<meta http-equiv="refresh" content="0;url=app/bookshop/index.html">
</head>

View File

@@ -1,3 +0,0 @@
<head>
<meta http-equiv="refresh" content="0;url=app/reviews/index.html">
</head>

View File

@@ -1,17 +0,0 @@
{
"name": "@capire/bookshop-with-reviews",
"version": "1.0.0",
"dependencies": {
"@capire/bookshop": "*",
"@capire/reviews": "*",
"@sap/cds": "^5",
"express": "^4.17.1"
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
}
}
}

View File

@@ -1,13 +0,0 @@
// Use enhanced implementation for CatalogService
using { CatalogService } from '@capire/bookshop';
annotate CatalogService with @impl:'srv/bookshop.js';
// 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 : Decimal;
numberOfReviews : Integer;
}

View File

@@ -1,27 +0,0 @@
const { CatalogService } = require('@capire/bookshop')
const cds = require ('@sap/cds')
module.exports = class extends CatalogService {async init(){
const { Books } = cds.entities('sap.capire.bookshop')
// Connect to ReviewsService to receive `reviewed` events from it
const ReviewsService = await cds.connect.to ('ReviewsService')
ReviewsService.on ('reviewed', (msg) => {
console.debug ('> received:', msg.event, msg.data)
const { subject, count, rating } = msg.data
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
})
return super.init()
}}
// -----------------------------------------------------------------------
// Helper for serving static content from npm-installed packages
const {dirname,resolve} = require('path')
const {static} = require('express')
cds.once('listening',()=>{
cds.app.use ('/app/bookshop', static (dirname (require.resolve('@capire/bookshop'))+'/app/vue'))
cds.app.use ('/app/reviews', static (resolve (__dirname, '../../app/vue')))
})