Merge branch 'main' into add/customBuildTask

This commit is contained in:
Lothar Bender
2021-11-24 11:51:03 +01:00
60 changed files with 12040 additions and 8703 deletions

View File

@@ -34,7 +34,7 @@
<td>{{ book.author }}</td>
<td>{{ book.genre.name }}</td>
<td class="rating-stars">
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }}
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} ({{ book.numberOfReviews }})
</td>
<td>{{ book.currency && book.currency.symbol }} {{ book.price }}</td>
</tr>

View File

@@ -1 +1,2 @@
exports.CatalogService = require('./srv/cat-service')
const { CatalogService } = require('./srv/cat-service')
module.exports = { CatalogService }

View File

@@ -3,3 +3,7 @@ service AdminService @(requires:'admin') {
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
}
//Since ID is computed, we can hide the popup for ID on Create
annotate AdminService.Books with { ID @Core.Computed; }
annotate AdminService.Authors with { ID @Core.Computed; }

View File

@@ -1,16 +1,42 @@
using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') {
using {sap.capire.bookshop as my} from '../db/schema';
/** For displaying lists of Books */
@readonly entity ListOfBooks as projection on Books
excluding { descr };
service CatalogService @(path : '/browse') {
/** For display in details pages */
@readonly entity Books as projection on my.Books { *,
author.name as author
} excluding { createdBy, modifiedBy };
/**
* For displaying lists of Books
*/
@readonly
entity ListOfBooks as projection on Books excluding {
descr
};
@requires: 'authenticated-user'
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
/**
* For display in details pages
*/
@readonly
entity Books as projection on my.Books {
* , author.name as authorName
} excluding {
createdBy,
modifiedBy
};
@readonly
entity Authors as projection on my.Authors {
* , books : redirected to Books
} excluding {
createdBy,
modifiedBy
};
@requires : 'authenticated-user'
action submitOrder(book : Books:ID, quantity : Integer) returns {
stock : Integer
};
event OrderedBook : {
book : Books:ID;
quantity : Integer;
buyer : String
};
}

View File

@@ -1,8 +1,9 @@
const cds = require('@sap/cds')
const { Books } = cds.entities ('sap.capire.bookshop')
class CatalogService extends cds.ApplicationService { init(){
const { Books } = cds.entities ('sap.capire.bookshop')
// Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => {
const {book,quantity} = req.data