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