Improved reviews-service
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
using { sap.capire.reviews as my } from '../db/schema';
|
using { sap.capire.reviews as my } from '../db/schema';
|
||||||
|
|
||||||
service ReviewsService {
|
service ReviewsService {
|
||||||
|
|
||||||
// Sync API
|
// Sync API
|
||||||
entity Reviews as projection on my.Reviews excluding { likes }
|
entity Reviews as projection on my.Reviews excluding { likes }
|
||||||
action like (review:Reviews.ID); // TODO: can be a bound action in OData
|
action like (review: type of Reviews:ID);
|
||||||
action unlike (review:Reviews.ID); // TODO: can be a bound action in OData
|
action unlike (review: type of Reviews:ID);
|
||||||
|
|
||||||
// Async API
|
// Async API
|
||||||
event reviewed : { subject: Reviews.subject; rating: Decimal(2,1) };
|
event reviewed : {
|
||||||
|
subject: type of Reviews:subject;
|
||||||
|
rating: Decimal(2,1)
|
||||||
|
};
|
||||||
|
|
||||||
// Input validation
|
// Input validation
|
||||||
annotate Reviews with {
|
annotate Reviews with {
|
||||||
|
|||||||
@@ -1,6 +1,23 @@
|
|||||||
#################################################
|
#################################################
|
||||||
#
|
#
|
||||||
# Reviews Service
|
# To ReviewsService mocked in bookshop process
|
||||||
|
#
|
||||||
|
|
||||||
|
GET http://localhost:4004/reviews/Reviews?
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
POST http://localhost:4004/reviews/Reviews
|
||||||
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
|
|
||||||
|
{"subject":"201", "title":"boo"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
#
|
||||||
|
# Bookshop Requests involving reviews
|
||||||
|
# (both in-process as well as separate one)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@@ -16,27 +33,4 @@ GET http://localhost:4004/browse/Books/201/reviews?
|
|||||||
GET http://localhost:4004/browse/Books(201)?
|
GET http://localhost:4004/browse/Books(201)?
|
||||||
&$select=ID,title,rating
|
&$select=ID,title,rating
|
||||||
&$expand=reviews
|
&$expand=reviews
|
||||||
# Note: the latter only works in case of ReviewsService in same process
|
# Note: the $expand only works in case of ReviewsService in same process
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### ReviewsService mocked in same process
|
|
||||||
GET http://localhost:4004/reviews/Reviews?
|
|
||||||
|
|
||||||
###
|
|
||||||
POST http://localhost:4004/reviews/Reviews
|
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
|
||||||
|
|
||||||
{"subject":"201", "title":"boo"}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 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"}
|
|
||||||
13
reviews/test/5005.http
Normal file
13
reviews/test/5005.http
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#################################################
|
||||||
|
#
|
||||||
|
# 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"}
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"kind": "sql"
|
"kind": "sql"
|
||||||
},
|
},
|
||||||
"ReviewsService": {
|
"ReviewsService": {
|
||||||
"kind": "odata"
|
"kind": "odata", "model": "@capire/reviews"
|
||||||
},
|
},
|
||||||
"messaging": {
|
"messaging": {
|
||||||
"kind": "file-based-messaging"
|
"kind": "file-based-messaging"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ cds.on('listening', async()=>{
|
|||||||
const { Reviews } = ReviewsService.entities
|
const { Reviews } = ReviewsService.entities
|
||||||
const [ subject ] = req.params
|
const [ subject ] = req.params
|
||||||
const tx = ReviewsService.tx (req)
|
const tx = ReviewsService.tx (req)
|
||||||
return tx.read (Reviews,{subject}) .columns (req.query.SELECT.columns)
|
return tx.read (Reviews) .where({subject}) .columns (req.query.SELECT.columns)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user