Merge branch 'main' into add/customBuildTask

This commit is contained in:
Lothar Bender
2021-12-06 10:10:14 +01:00
25 changed files with 174 additions and 184 deletions

View File

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

View File

@@ -7,13 +7,12 @@ class CatalogService extends cds.ApplicationService { init(){
// Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => {
const {book,quantity} = req.data
if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`)
let {stock} = await SELECT `stock` .from (Books,book)
if (stock >= quantity) {
await UPDATE (Books,book) .with (`stock -=`, quantity)
await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id })
return { stock }
}
else return req.error (409,`${quantity} exceeds stock for book #${book}`)
if (quantity > stock) return req.reject (409,`${quantity} exceeds stock for book #${book}`)
await UPDATE (Books,book) .with ({ stock: stock -= quantity })
await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id })
return { stock }
})
// Add some discount for overstocked books

View File

@@ -32,6 +32,19 @@ GET {{server}}/admin/Authors?
# &sap-language=de
Authorization: Basic alice:
### ------------------------------------------------------------------------
# Create Author
POST {{server}}/admin/Authors
Content-Type: application/json;IEEE754Compatible=true
Authorization: Basic alice:
{
"ID": 112,
"name": "Shakespeeeeere",
"age": 22
}
### ------------------------------------------------------------------------
# Create book
POST {{server}}/admin/Books