This commit is contained in:
Daniel
2020-03-02 00:08:49 +01:00
parent d9df2930cb
commit 26d7fc767c
71 changed files with 141 additions and 34 deletions

View File

@@ -0,0 +1,16 @@
ID;parent_ID;name
10;;Fiction
11;10;Drama
12;10;Poetry
13;10;Fantasy
14;10;Science Fiction
15;10;Romance
16;10;Mystery
17;10;Thriller
18;10;Dystopia
19;10;Fairy Tale
20;;Non-Fiction
21;20;Biography
22;20;Autobiography
23;20;Essay
24;20;Speech
1 ID parent_ID name
2 10 Fiction
3 11 10 Drama
4 12 10 Poetry
5 13 10 Fantasy
6 14 10 Science Fiction
7 15 10 Romance
8 16 10 Mystery
9 17 10 Thriller
10 18 10 Dystopia
11 19 10 Fairy Tale
12 20 Non-Fiction
13 21 20 Biography
14 22 20 Autobiography
15 23 20 Essay
16 24 20 Speech

View File

@@ -1,11 +1,12 @@
namespace sap.capire.bookshop; namespace sap.capire.bookshop;
using { Currency, managed, cuid } from '@sap/cds/common'; using { Currency, managed, cuid, sap } from '@sap/cds/common';
entity Books : managed { entity Books : managed {
key ID : Integer; key ID : Integer;
title : localized String(111); title : localized String(111);
descr : localized String(1111); descr : localized String(1111);
author : Association to Authors; author : Association to Authors;
genre : Association to Genres;
stock : Integer; stock : Integer;
price : Decimal(9,2); price : Decimal(9,2);
currency : Currency; currency : Currency;
@@ -21,6 +22,12 @@ entity Authors : managed {
books : Association to many Books on books.author = $self; books : Association to many Books on books.author = $self;
} }
entity Genres : sap.common.CodeList {
key ID : Integer;
parent : Association to Genres;
children : Composition of many Genres on children.parent = $self;
}
entity Orders : cuid, managed { entity Orders : cuid, managed {
OrderNo : String @title:'Order Number'; //> readable key OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many OrderItems on Items.parent = $self; Items : Composition of many OrderItems on Items.parent = $self;

View File

@@ -1,16 +1,17 @@
{ {
"name": "@sap/capire-bookshop", "name": "@capire/bookshop",
"version": "1.0.0", "version": "1.0.0",
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
"license": "SAP SAMPLE CODE LICENSE", "license": "SAP SAMPLE CODE LICENSE",
"dependencies": { "dependencies": {
"@sap/capire-common": "*", "@capire/common": "*",
"@sap/cds": "*", "@sap/cds": "*",
"express": "*" "express": "*"
}, },
"scripts": { "scripts": {
"start": "cds run --in-memory?", "start": "cds run --in-memory?",
"watch": "cds watch" "watch": "cds watch",
"test:genres": "cds serve test/genres --in-memory"
}, },
"cds": { "cds": {
"requires": { "requires": {

4
bookshop/test/genres.cds Normal file
View File

@@ -0,0 +1,4 @@
using { sap.capire.bookshop as my } from '../db/schema';
service TestService {
entity Genres as projection on my.Genres;
}

38
bookshop/test/genres.http Normal file
View File

@@ -0,0 +1,38 @@
#################################################
#
# Genres
#
GET http://localhost:4004/test/Genres?
###
GET http://localhost:4004/test/Genres?
&$filter=parent_ID eq null&$select=name
&$expand=children($select=name)
###
POST http://localhost:4004/test/Genres?
Content-Type: application/json
{ "ID":100, "name":"Some Sample Genres...", "children":[
{ "ID":101, "name":"Cat", "children":[
{ "ID":102, "name":"Kitty", "children":[
{ "ID":103, "name":"Kitty Cat", "children":[
{ "ID":104, "name":"Aristocat" } ]},
{ "ID":105, "name":"Kitty Bat" } ]},
{ "ID":106, "name":"Catwoman", "children":[
{ "ID":107, "name":"Catalina" } ]} ]},
{ "ID":108, "name":"Catweazle" }
]}
###
GET http://localhost:4004/test/Genres(100)?
# &$expand=children
# &$expand=children($expand=children($expand=children($expand=children)))
###
DELETE http://localhost:4004/test/Genres(103)
###
DELETE http://localhost:4004/test/Genres(100)
###

View File

@@ -1,18 +0,0 @@
### List Books with their current stocks
GET http://localhost:4004/admin/Books?$select=ID,stock
### List all Orders
GET http://localhost:4004/admin/Orders?
&$expand=Items
### Submit Orders
POST http://localhost:4004/browse/Orders
Content-Type: application/json
{ "OrderNo":"2019-09...", "Items":[
{ "book_ID":201, "amount":5 },
{ "book_ID":207, "amount":3 }
]}
# Sending this three times should result in a 409: 5 exceeds stock for book #201

View File

@@ -1,5 +1,5 @@
{ {
"name": "@sap/capire-common", "name": "@capire/common",
"version": "1.0.0", "version": "1.0.0",
"description": "A reuse package providing common domain models and services for common data.", "description": "A reuse package providing common domain models and services for common data.",
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git", "repository": "https://github.com/SAP-samples/cloud-cap-samples.git",

View File

@@ -1,13 +1,15 @@
using AdminService from '@sap/capire-bookshop/srv/admin-service'; using AdminService from '@capire/bookshop/srv/admin-service';
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
// Books Object Page // Books Object Page
// //
annotate AdminService.Books with @( annotate AdminService.Books with @(
UI: { UI: {
Facets: [ Facets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'}, {$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Translations}', Target: 'texts/@UI.LineItem'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Admin}', Target: '@UI.FieldGroup#Admin'}, {$Type: 'UI.ReferenceFacet', Label: '{i18n>Admin}', Target: '@UI.FieldGroup#Admin'},
], ],
@@ -15,6 +17,7 @@ annotate AdminService.Books with @(
Data: [ Data: [
{Value: title}, {Value: title},
{Value: author_ID}, {Value: author_ID},
{Value: genre_ID},
{Value: descr}, {Value: descr},
] ]
}, },
@@ -35,3 +38,35 @@ annotate AdminService.Books with @(
} }
} }
); );
////////////////////////////////////////////////////////////
//
// Draft for Localized Data
//
annotate sap.capire.bookshop.Books with @fiori.draft.enabled;
annotate AdminService.Books with @odata.draft.enabled;
annotate AdminService.Books_texts with @(
UI: {
Identification: [{Value:title}],
SelectionFields: [ locale, title ],
LineItem: [
{Value: locale, Label: 'Locale'},
{Value: title, Label: 'Title'},
{Value: descr, Label: 'Description'},
]
}
);
// Add Value Help for Locales
annotate AdminService.Books_texts {
locale @ValueList:{entity:'Languages',type:#fixed}
}
// In addition we need to expose Languages through AdminService
using { sap } from '@sap/cds/common';
extend service AdminService {
entity Languages as projection on sap.common.Languages;
}

View File

@@ -1,4 +1,4 @@
using CatalogService from '@sap/capire-bookshop/srv/cat-service'; using CatalogService from '@capire/bookshop/srv/cat-service';
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
@@ -40,6 +40,7 @@ annotate CatalogService.Books with @(
LineItem: [ LineItem: [
{Value: title}, {Value: title},
{Value: author, Label:'{i18n>Author}'}, {Value: author, Label:'{i18n>Author}'},
{Value: genre.name},
{Value: price}, {Value: price},
{Value: currency.symbol, Label:' '}, {Value: currency.symbol, Label:' '},
] ]

View File

@@ -2,7 +2,7 @@
Common Annotations shared by all apps Common Annotations shared by all apps
*/ */
using { sap.capire.bookshop as my } from '@sap/capire-bookshop/db/schema'; using { sap.capire.bookshop as my } from '@capire/bookshop/db/schema';
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@@ -17,6 +17,7 @@ annotate my.Books with @(
{Value: ID}, {Value: ID},
{Value: title}, {Value: title},
{Value: author.name, Label:'{i18n>Author}'}, {Value: author.name, Label:'{i18n>Author}'},
{Value: genre.name},
{Value: stock}, {Value: stock},
{Value: price}, {Value: price},
{Value: currency.symbol, Label:' '}, {Value: currency.symbol, Label:' '},
@@ -57,12 +58,16 @@ annotate my.Books with @(
annotate my.Books with { annotate my.Books with {
ID @title:'{i18n>ID}' @UI.HiddenFilter; ID @title:'{i18n>ID}' @UI.HiddenFilter;
title @title:'{i18n>Title}'; title @title:'{i18n>Title}';
genre @title:'{i18n>Genre}';
author @title:'{i18n>AuthorID}'; author @title:'{i18n>AuthorID}';
price @title:'{i18n>Price}'; price @title:'{i18n>Price}';
stock @title:'{i18n>Stock}'; stock @title:'{i18n>Stock}';
descr @UI.MultiLineText; descr @UI.MultiLineText;
} }
annotate my.Genres with {
name @title: '{i18n>Genre}';
}
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //

View File

@@ -7,4 +7,4 @@ using from './browse/fiori-service';
using from './orders/fiori-service'; using from './orders/fiori-service';
using from './common'; using from './common';
using from '@sap/capire-common'; using from '@capire/common';

View File

@@ -1,4 +1,4 @@
using AdminService from '@sap/capire-bookshop/srv/admin-service'; using AdminService from '@capire/bookshop/srv/admin-service';
annotate AdminService.Books with { annotate AdminService.Books with {
price @Common.FieldControl: #ReadOnly; price @Common.FieldControl: #ReadOnly;

3
fiori/db/schema.cds Normal file
View File

@@ -0,0 +1,3 @@
// Proxy for importing schema from bookshop sample
using from '@capire/bookshop/db/schema';
namespace sap.capire.bookshop;

View File

@@ -1,11 +1,12 @@
{ {
"name": "@sap/capire-fiori", "name": "@capire/fiori",
"version": "1.0.0", "version": "1.0.0",
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.", "description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
"license": "SAP SAMPLE CODE LICENSE", "license": "SAP SAMPLE CODE LICENSE",
"dependencies": { "dependencies": {
"@sap/capire-bookshop": "*", "@capire/bookshop": "*",
"@sap/capire-common": "*", "@capire/genres": "*",
"@capire/common": "*",
"@sap/cds": "*", "@sap/cds": "*",
"express": "*" "express": "*"
}, },

View File

@@ -0,0 +1,5 @@
// Proxy for importing services from bookshop sample
using from '@capire/bookshop/srv/admin-service';
using from '@capire/bookshop/srv/cat-service';
annotate AdminService with @impl:'srv/admin-service.js';

View File

@@ -0,0 +1,8 @@
const cds = require('@sap/cds')
module.exports = cds.service.impl (async function() {
const {Books} = cds.entities
const {ID} = await SELECT.one.from(Books).columns('max(ID) as ID')
let newID = ID - ID % 100 + 100
this.before ('NEW','Books', req => req.data.ID = ++newID)
})

View File

@@ -1,5 +1,5 @@
{ {
"name": "@sap/capire-samples", "name": "@capire/samples",
"description": "The umbrella project for all samples to easily setup for local development and tests.", "description": "The umbrella project for all samples to easily setup for local development and tests.",
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git", "repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
"author": "daniel.hutzel@sap.com", "author": "daniel.hutzel@sap.com",
@@ -8,8 +8,9 @@
"bookshop": "cds watch bookshop" "bookshop": "cds watch bookshop"
}, },
"dependencies": { "dependencies": {
"@sap/capire-bookshop": "./bookshop", "@capire/bookshop": "./bookshop",
"@sap/capire-common": "./common" "@capire/genres": "./genres",
"@capire/common": "./common"
}, },
"--add-these-to-devDependencies-for-tests": { "--add-these-to-devDependencies-for-tests": {
"@types/jest": "*", "@types/jest": "*",