Separated reviewed and reviews
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
"name": "@capire/bookshop-with-reviews",
|
"name": "@capire/bookshop-with-reviews",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capire/bookshop": "../../../bookshop",
|
"@capire/bookshop": "../bookshop",
|
||||||
"@capire/reviews": "..",
|
"@capire/reviews": "../reviews",
|
||||||
"@sap/cds": "^3.33.1",
|
"@sap/cds": "^3.33.1",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
},
|
},
|
||||||
@@ -20,4 +20,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,9 +12,13 @@ cds.once('served', async()=>{
|
|||||||
// react on event messages from reviews service
|
// react on event messages from reviews service
|
||||||
const ReviewsService = await cds.connect.to ('ReviewsService')
|
const ReviewsService = await cds.connect.to ('ReviewsService')
|
||||||
const db = await cds.connect.to ('db')
|
const db = await cds.connect.to ('db')
|
||||||
|
|
||||||
|
// reflect entities required below...
|
||||||
|
const { Books } = db.entities('sap.capire.bookshop')
|
||||||
|
const { Reviews } = ReviewsService.entities
|
||||||
|
|
||||||
ReviewsService.on ('reviewed', (msg) => {
|
ReviewsService.on ('reviewed', (msg) => {
|
||||||
console.debug ('> received:', msg.event, msg.data)
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
const { Books } = db.entities('sap.capire.bookshop')
|
|
||||||
const { subject, rating } = msg.data
|
const { subject, rating } = msg.data
|
||||||
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
|
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
|
||||||
return tx.update (Books,subject) .with ({rating})
|
return tx.update (Books,subject) .with ({rating})
|
||||||
@@ -24,10 +28,10 @@ cds.once('served', async()=>{
|
|||||||
const CatalogService = await cds.connect.to ('CatalogService')
|
const CatalogService = await cds.connect.to ('CatalogService')
|
||||||
CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
console.debug ('> delegating to ReviewsService')
|
console.debug ('> delegating to ReviewsService')
|
||||||
const { Reviews } = ReviewsService.entities
|
const [ id ] = req.params
|
||||||
const [ subject ] = req.params
|
const tx = ReviewsService.tx(req)
|
||||||
const tx = ReviewsService.tx (req)
|
return tx.read (Reviews) .where ({ subject: String(id) })
|
||||||
return tx.read (Reviews) .where({subject}) .columns (req.query.SELECT.columns)
|
.columns (req.query.SELECT.columns)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
#################################################
|
#################################################
|
||||||
#
|
#
|
||||||
# To ReviewsService mocked in bookshop process
|
# To ReviewsService
|
||||||
#
|
#
|
||||||
|
# move the right down:
|
||||||
|
@reviews-service = http://localhost:4004/reviews
|
||||||
|
@reviews-service = http://localhost:5005/reviews
|
||||||
|
|
||||||
GET http://localhost:4004/reviews/Reviews?
|
### Get all reviews
|
||||||
|
GET {{reviews-service}}/Reviews
|
||||||
|
|
||||||
###
|
### Add a new review (with random rating)
|
||||||
|
POST {{reviews-service}}/Reviews
|
||||||
POST http://localhost:4004/reviews/Reviews
|
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
|
|
||||||
{"subject":"201", "title":"boo"}
|
{"subject":"201", "title":"boo"}
|
||||||
@@ -20,17 +23,18 @@ Content-Type: application/json;IEEE754Compatible=true
|
|||||||
# (both in-process as well as separate one)
|
# (both in-process as well as separate one)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@bookshop = http://localhost:4004
|
||||||
|
|
||||||
### Request to CatalogService > delegated to ReviewsService
|
### Request to CatalogService > delegated to ReviewsService
|
||||||
GET http://localhost:4004/browse/Books(201)/reviews?
|
GET {{bookshop}}/browse/Books(201)/reviews?
|
||||||
&$select=rating,date,reviewer,title
|
&$select=rating,date,reviewer,title
|
||||||
|
|
||||||
### Alternative OData URL
|
### Alternative OData URL
|
||||||
GET http://localhost:4004/browse/Books/201/reviews?
|
GET {{bookshop}}/browse/Books/201/reviews?
|
||||||
&$select=rating,date,reviewer,title
|
&$select=rating,date,reviewer,title
|
||||||
|
|
||||||
###
|
###
|
||||||
GET http://localhost:4004/browse/Books(201)?
|
GET {{bookshop}}/browse/Books(201)?
|
||||||
&$select=ID,title,rating
|
&$select=ID,title,rating
|
||||||
&$expand=reviews
|
&$expand=reviews
|
||||||
# Note: the $expand only works in case of ReviewsService in same process
|
# Note: the $expand only works in case of ReviewsService in same process
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"reviews-service": "cds watch",
|
"reviews-service": "cds watch",
|
||||||
"bookshop": "cds watch test/bookshop"
|
"books-reviewed": "cds watch ../reviewed"
|
||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
#################################################
|
|
||||||
#
|
|
||||||
# To ReviewsService running as separate process
|
|
||||||
#
|
|
||||||
|
|
||||||
GET http://localhost:5005/reviews/Reviews?
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:5005/reviews/Reviews
|
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
|
||||||
|
|
||||||
{"subject":"201", "title":"boo"}
|
|
||||||
Reference in New Issue
Block a user