Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bookshop/db/data/sap.capire.bookshop-Books.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ ID,title,descr,author_ID,stock,price,currency_code,genre_ID
251,The Raven,"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.",150,333,13.13,USD,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
252,Eleonora,"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.",150,555,14,USD,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
271,Catweazle,"Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.",170,22,150,JPY,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
301,Wuthering Heights,"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.",101,12,11.11,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
307,Jane Eyre,"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.",107,11,12.34,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
351,The Raven,"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.",150,333,13.13,USD,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
352,Eleonora,"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.",150,555,14,USD,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
371,Catweazle,"Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.",170,22,150,JPY,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
401,Wuthering Heights,"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.",101,12,11.11,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
407,Jane Eyre,"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.",107,11,12.34,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
451,The Raven,"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.",150,333,13.13,USD,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
452,Eleonora,"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.",150,555,14,USD,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
471,Catweazle,"Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.",170,22,150,JPY,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
501,Wuthering Heights,"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.",101,12,11.11,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
507,Jane Eyre,"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.",107,11,12.34,GBP,11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
551,The Raven,"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.",150,333,13.13,USD,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
552,Eleonora,"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.",150,555,14,USD,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
571,Catweazle,"Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.",170,22,150,JPY,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
25 changes: 25 additions & 0 deletions bookshop/db/data/sap.capire.bookshop-Pages.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parent_ID,number,content
201,1,Hello World
201,2,Lorem ipsum dolor sit amet
201,3,Consectetur adipiscing elit
201,4,Sed do eiusmod tempor incididunt
201,5,Ut labore et dolore magna aliqua
201,6,Ut enim ad minim veniam
201,7,Quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
201,8,Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
201,9,Excepteur sint occaecat cupidatat non proident
201,10,Sunt in culpa qui officia deserunt mollit anim id est laborum
207,1,Hello World
251,1,Hello World
252,1,Hello World
271,1,Hello World
301,1,Hello World
301,2,Lorem ipsum dolor sit amet
301,3,Consectetur adipiscing elit
301,4,Sed do eiusmod tempor incididunt
301,5,Ut labore et dolore magna aliqua
301,6,Ut enim ad minim veniam
301,7,Quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
301,8,Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
301,9,Excepteur sint occaecat cupidatat non proident
301,10,Sunt in culpa qui officia deserunt mollit anim id est laborum
59 changes: 38 additions & 21 deletions bookshop/db/schema.cds
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
using { Currency, managed, sap } from '@sap/cds/common';
using {
Currency,
managed,
sap
} from '@sap/cds/common';

namespace sap.capire.bookshop;

@Capabilities.ExpandRestrictions.MaxLevels: 1
entity Books : managed {
key ID : Integer;
title : localized String(111) @mandatory;
descr : localized String(1111);
author : Association to Authors @mandatory;
genre : Association to Genres;
stock : Integer;
price : Price;
currency : Currency;
image : LargeBinary @Core.MediaType: 'image/png';
key ID : Integer;
title : localized String(111) @mandatory;
descr : localized String(1111);
author : Association to Authors @mandatory;
genre : Association to Genres;
stock : Integer;
price : Price;
currency : Currency;
image : LargeBinary @Core.MediaType: 'image/png';
pages : Composition of many Pages
on pages.parent = $self;
}

@Capabilities.ExpandRestrictions.MaxLevels: 1
entity Pages {
key parent : Association to Books;
key number : Integer;
content : String(1111);
}

entity Authors : managed {
key ID : Integer;
name : String(111) @mandatory;
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;
key ID : Integer;
name : String(111) @mandatory;
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books
on books.author = $self;
}

/** Hierarchically organized Code List for Genres */
entity Genres : sap.common.CodeList {
key ID : UUID;
parent : Association to Genres;
children : Composition of many Genres on children.parent = $self;
key ID : UUID;
parent : Association to Genres;
children : Composition of many Genres
on children.parent = $self;
}

type Price : Decimal(9,2);
type Price : Decimal(9, 2);


// ------------------------------------------------------------------
Expand Down
37 changes: 28 additions & 9 deletions bookshop/srv/cat-service.cds
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') {
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 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 };
@readonly
entity Books as
projection on my.Books {
*,
author.name as author
}
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 };
action submitOrder(book : Books:ID, quantity : Integer) returns {
stock : Integer
};

event OrderedBook : {
book : Books:ID;
quantity : Integer;
buyer : String
};
}
77 changes: 39 additions & 38 deletions bookshop/srv/cat-service.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
const cds = require('@sap/cds')

class CatalogService extends cds.ApplicationService { init() {

const { Books } = cds.entities('sap.capire.bookshop')
const { ListOfBooks } = this.entities

// Add some discount for overstocked books
this.after('each', ListOfBooks, book => {
if (book.stock > 111) book.title += ` -- 11% discount!`
})

// Reduce stock of ordered books if available stock suffices
this.on('submitOrder', async req => {
let { book:id, quantity } = req.data
let book = await SELECT.from (Books, id, b => b.stock)

// Validate input data
if (!book) return req.error (404, `Book #${id} doesn't exist`)
if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
if (quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`)

// Reduce stock in database and return updated stock value
await UPDATE (Books, id) .with ({ stock: book.stock -= quantity })
return book
})

// Emit event when an order has been submitted
this.after('submitOrder', async (_,req) => {
let { book, quantity } = req.data
await this.emit('OrderedBook', { book, quantity, buyer: req.user.id })
})

// Delegate requests to the underlying generic service
return super.init()
}}

module.exports = CatalogService
const cds = require("@sap/cds");

class CatalogService extends cds.ApplicationService {
init() {
const { Books } = cds.entities("sap.capire.bookshop");
const { ListOfBooks } = this.entities;

// Add some discount for overstocked books
this.after("each", ListOfBooks, (book) => {
if (book.stock > 111) book.title += ` -- 11% discount!`;
});

// Reduce stock of ordered books if available stock suffices
this.on("submitOrder", async (req) => {
let { book: id, quantity } = req.data;
let book = await SELECT.from(Books, id, (b) => b.stock);

// Validate input data
if (!book) return req.error(404, `Book #${id} doesn't exist`);
if (quantity < 1) return req.error(400, `quantity has to be 1 or more`);
if (quantity > book.stock) return req.error(409, `${quantity} exceeds stock for book #${id}`);

// Reduce stock in database and return updated stock value
await UPDATE(Books, id).with({ stock: (book.stock -= quantity) });
return book;
});

// Emit event when an order has been submitted
this.after("submitOrder", async (_, req) => {
let { book, quantity } = req.data;
await this.emit("OrderedBook", { book, quantity, buyer: req.user.id });
});

// Delegate requests to the underlying generic service
return super.init();
}
}

module.exports = CatalogService;
Loading
Loading