Cleaned up delegation

This commit is contained in:
Daniel
2020-03-15 12:12:18 +01:00
parent e4983b8bde
commit 4ae16e8fd2
2 changed files with 13 additions and 13 deletions

View File

@@ -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)
}))
})

View File

@@ -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)?