Cleaned up delegation
This commit is contained in:
@@ -10,21 +10,19 @@ cds.on('listening', async()=>{
|
||||
console.debug ('> received:', msg.event, msg.data)
|
||||
const { Books } = db.entities('sap.capire.bookshop')
|
||||
const { subject, rating } = msg.data
|
||||
const tx = db // TODO: db.transaction (msg)
|
||||
// return tx.run (UPDATE (Books, subject) .with ({rating}))
|
||||
return tx.update (Books, subject) .with ({rating})
|
||||
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
|
||||
return tx.update (Books,subject) .with ({rating})
|
||||
})
|
||||
|
||||
// delegate requests to read reviews to ReviewsService
|
||||
const CatalogService = await cds.connect.to ('CatalogService')
|
||||
CatalogService.impl (() => {
|
||||
CatalogService.on ('READ', 'Books/reviews', (req) => {
|
||||
const { Reviews } = ReviewsService.entities
|
||||
const [ subject ] = req.params
|
||||
const tx = ReviewsService.transaction (req)
|
||||
return tx.run (SELECT.from (Reviews) .where ({subject}))
|
||||
})
|
||||
})
|
||||
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,{subject}) .columns (req.query.SELECT.columns)
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
|
||||
### Request to CatalogService > delegated to ReviewsService
|
||||
GET http://localhost:4004/browse/Books(201)/reviews
|
||||
GET http://localhost:4004/browse/Books(201)/reviews?
|
||||
&$select=rating,date,reviewer,title
|
||||
|
||||
### Alternative OData URL
|
||||
GET http://localhost:4004/browse/Books/201/reviews
|
||||
GET http://localhost:4004/browse/Books/201/reviews?
|
||||
&$select=rating,date,reviewer,title
|
||||
|
||||
###
|
||||
GET http://localhost:4004/browse/Books(201)?
|
||||
|
||||
Reference in New Issue
Block a user