Improved samples for new capire

This commit is contained in:
Daniel Hutzel
2024-11-19 12:29:19 +01:00
parent 33b7691f51
commit 22709b8cdb
10 changed files with 48 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(requires:'admin', path:'/admin') {
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
// entity Authors as projection on my.Authors;
}

View File

@@ -2,15 +2,20 @@ using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') {
/** For displaying lists of Books */
@readonly entity ListOfBooks as projection on Books
excluding { descr };
@readonly entity Books as projection on Book excluding { descr };
/** For display in details pages */
@readonly entity Books as projection on my.Books { *,
author.name as author
} excluding { createdBy, modifiedBy };
@readonly entity Book as projection on my.Books { *,
currency.name as currencyName, // flattened
currency.symbol as currency, // flattened
author.name as author, // flattened
genre.name as genre, // flattened
} excluding {
createdBy, modifiedBy, // as end users shouldn't see them
localized, texts, // as end users don't need them
};
@requires: 'authenticated-user'
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
action submitOrder ( book: Book:ID, quantity: Integer ) returns { stock: Integer };
event OrderedBook : { book: Book:ID; quantity: Integer; buyer: String };
}

View File

@@ -3,10 +3,10 @@ const cds = require('@sap/cds')
class CatalogService extends cds.ApplicationService { init() {
const { Books } = cds.entities('sap.capire.bookshop')
const { ListOfBooks } = this.entities
const { Books:Book } = this.entities
// Add some discount for overstocked books
this.after('each', ListOfBooks, book => {
this.after('each', Book, book => {
if (book.stock > 111) book.title += ` -- 11% discount!`
})