Simplifying samples
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
<head>
|
|
||||||
<meta http-equiv="refresh" content="0;url=bookshop/index.html">
|
|
||||||
</head>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<head>
|
|
||||||
<meta http-equiv="refresh" content="0;url=reviews/index.html">
|
|
||||||
</head>
|
|
||||||
@@ -9,19 +9,12 @@ cds.emit = function (event,...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cds.once('bootstrap',(app)=>{
|
cds.once('bootstrap',(app)=>{
|
||||||
app.use ('/orders/webapp', _from('@capire/orders/app/orders/webapp/manifest.json'))
|
app.serve ('/orders/webapp').from('@capire/orders','app/orders/webapp')
|
||||||
app.use ('/bookshop', _from('@capire/bookshop/app/vue/index.html'))
|
app.serve ('/bookshop').from('@capire/bookshop','app/vue')
|
||||||
app.use ('/reviews', _from('@capire/reviews/app/vue/index.html'))
|
app.serve ('/reviews').from('@capire/reviews','app/vue')
|
||||||
})
|
})
|
||||||
|
|
||||||
cds.once('served', require('./srv/mashup'))
|
cds.once('served', require('./srv/mashup'))
|
||||||
cds.once('served', require('@capire/suppliers/srv/mashup'))
|
cds.once('served', require('@capire/suppliers/srv/mashup'))
|
||||||
|
|
||||||
module.exports = cds.server
|
module.exports = cds.server
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// Helper for serving static content from npm-installed packages
|
|
||||||
const {static} = require('express')
|
|
||||||
const {dirname} = require('path')
|
|
||||||
const _from = target => static (dirname (require.resolve(target)))
|
|
||||||
|
|||||||
@@ -3,17 +3,17 @@
|
|||||||
// Mashing up imported models...
|
// Mashing up imported models...
|
||||||
//
|
//
|
||||||
|
|
||||||
using { sap.capire.bookshop.Books } from '@capire/bookshop';
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Extend Books with access to Reviews and average ratings
|
// Extend Books with access to Reviews and average ratings
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using { CatalogService.ListOfBooks, sap.capire.bookshop.Books } from '@capire/bookshop';
|
||||||
using { ReviewsService.Reviews } from '@capire/reviews';
|
using { ReviewsService.Reviews } from '@capire/reviews';
|
||||||
extend Books with {
|
extend Books with {
|
||||||
reviews : Composition of many Reviews on reviews.subject = $self.ID;
|
reviews : Composition of many Reviews on reviews.subject = $self.ID;
|
||||||
rating : Decimal;
|
rating : Reviews:rating;
|
||||||
}
|
}
|
||||||
|
extend projection ListOfBooks with { rating }
|
||||||
|
|
||||||
//
|
//
|
||||||
// Extend Orders with Books as Products
|
// Extend Orders with Books as Products
|
||||||
|
|||||||
2
reviews/test/bookshop/.env
Normal file
2
reviews/test/bookshop/.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cds.requires.messaging.kind = file-based-messaging
|
||||||
|
PORT = 4004
|
||||||
19
reviews/test/bookshop/package.json
Normal file
19
reviews/test/bookshop/package.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "@capire/fiori",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@capire/bookshop": "*",
|
||||||
|
"@capire/reviews": "*",
|
||||||
|
"@sap/cds": "^5",
|
||||||
|
"express": "^4.17.1"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"auth": { "strategy": "dummy" },
|
||||||
|
"ReviewsService": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "@capire/reviews"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
reviews/test/bookshop/server.js
Normal file
20
reviews/test/bookshop/server.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
cds.once('bootstrap',(app)=>{
|
||||||
|
// Delegate to imported apps (reviews only when mocked)
|
||||||
|
app.serve ('/bookshop').from ('@capire/bookshop','app/vue')
|
||||||
|
app.serve ('/reviews',).from ('@capire/reviews','app/vue')
|
||||||
|
})
|
||||||
|
|
||||||
|
cds.once('served', async ()=>{
|
||||||
|
// Update Books' average ratings when ReviewsService signals updated reviews
|
||||||
|
const ReviewsService = await cds.connect.to ('ReviewsService')
|
||||||
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
|
const { subject, rating } = msg.data
|
||||||
|
return UPDATE('Books',subject).with({rating})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = cds.server
|
||||||
11
reviews/test/bookshop/services.cds
Normal file
11
reviews/test/bookshop/services.cds
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace sap.capire.bookshop; //> allows UPDATE('Books')...
|
||||||
|
//
|
||||||
|
// Extend Books with access to Reviews and average ratings
|
||||||
|
//
|
||||||
|
using { CatalogService.ListOfBooks, 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 : Reviews:rating;
|
||||||
|
}
|
||||||
|
extend projection ListOfBooks with { rating }
|
||||||
Reference in New Issue
Block a user