Improved reviews-service

This commit is contained in:
Daniel
2020-03-20 15:29:10 +01:00
parent 76829742d8
commit 3872ac21a3
5 changed files with 41 additions and 30 deletions

View File

@@ -1,13 +1,17 @@
using { sap.capire.reviews as my } from '../db/schema';
service ReviewsService {
// Sync API
entity Reviews as projection on my.Reviews excluding { likes }
action like (review:Reviews.ID); // TODO: can be a bound action in OData
action unlike (review:Reviews.ID); // TODO: can be a bound action in OData
action like (review: type of Reviews:ID);
action unlike (review: type of Reviews:ID);
// Async API
event reviewed : { subject: Reviews.subject; rating: Decimal(2,1) };
event reviewed : {
subject: type of Reviews:subject;
rating: Decimal(2,1)
};
// Input validation
annotate Reviews with {

View File

@@ -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)?
&$select=ID,title,rating
&$expand=reviews
# Note: the latter 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"}
# Note: the $expand only works in case of ReviewsService in same process

13
reviews/test/5005.http Normal file
View 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"}

View File

@@ -13,7 +13,7 @@
"kind": "sql"
},
"ReviewsService": {
"kind": "odata"
"kind": "odata", "model": "@capire/reviews"
},
"messaging": {
"kind": "file-based-messaging"

View File

@@ -21,7 +21,7 @@ cds.on('listening', async()=>{
const { Reviews } = ReviewsService.entities
const [ subject ] = req.params
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)
}))
})