diff --git a/fiori/app/_i18n/i18n.properties b/fiori/app/_i18n/i18n.properties index c1d0293f..83681bcf 100644 --- a/fiori/app/_i18n/i18n.properties +++ b/fiori/app/_i18n/i18n.properties @@ -11,6 +11,7 @@ DateOfBirth = Date of Birth DateOfDeath = Date of Death PlaceOfBirth = Place of Birth PlaceOfDeath = Place of Death +Age = Age Authors = Authors Order = Order Orders = Orders diff --git a/fiori/app/_i18n/i18n_de.properties b/fiori/app/_i18n/i18n_de.properties index 365b45df..7724f685 100644 --- a/fiori/app/_i18n/i18n_de.properties +++ b/fiori/app/_i18n/i18n_de.properties @@ -6,6 +6,7 @@ Authors = Autoren Author = Autor AuthorID = ID des Autors AuthorName = Name des Autors +Age = Alter Name = Name Stock = Bestand Order = Bestellung diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index 1aeddb9f..83ff758a 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '@capire/bookshop'; +using { AdminService } from '../../db'; //////////////////////////////////////////////////////////////////////////// // @@ -39,6 +39,27 @@ annotate AdminService.Books with @( } ); +annotate AdminService.Authors with @( + UI: { + HeaderInfo: { + Description: {Value: lifetime} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Books}', Target: 'books/@UI.LineItem'}, + ], + FieldGroup#Details: { + Data: [ + {Value: placeOfBirth}, + {Value: placeOfDeath}, + {Value: dateOfBirth}, + {Value: dateOfDeath}, + {Value: age, Label: '{i18n>Age}'}, + ] + }, + } +); + //////////////////////////////////////////////////////////// diff --git a/fiori/db/hana/index.cds b/fiori/db/hana/index.cds new file mode 100644 index 00000000..db46e6d5 --- /dev/null +++ b/fiori/db/hana/index.cds @@ -0,0 +1,10 @@ +// +// Add Author.age and .lifetime with a DB-specific function +// + +using { AdminService } from '..'; + +extend projection AdminService.Authors with { + YEARS_BETWEEN(dateOfBirth, dateOfDeath) as age: Integer, + YEAR(dateOfBirth) || ' – ' || YEAR(dateOfDeath) as lifetime : String +} diff --git a/fiori/db/index.cds b/fiori/db/index.cds new file mode 100644 index 00000000..479fdbfb --- /dev/null +++ b/fiori/db/index.cds @@ -0,0 +1,8 @@ +using { sap.capire.bookshop } from '@capire/bookshop'; + +// Forward-declare calculated fields to be filled in database-specific ways +// TODO find a better way to have 'default' fields that still can be overwritten. +extend bookshop.Authors with { + virtual age: Integer; + virtual lifetime: String; +} diff --git a/fiori/db/sqlite/index.cds b/fiori/db/sqlite/index.cds new file mode 100644 index 00000000..9f2cc3b5 --- /dev/null +++ b/fiori/db/sqlite/index.cds @@ -0,0 +1,10 @@ +// +// Add Author.age and .lifetime with a DB-specific function +// + +using { AdminService } from '..'; + +extend projection AdminService.Authors with { + strftime('%Y',dateOfDeath)-strftime('%Y',dateOfBirth) as age: Integer, + strftime('%Y',dateOfBirth) || ' – ' || strftime('%Y',dateOfDeath) as lifetime : String +} diff --git a/fiori/package.json b/fiori/package.json index a4028d2e..7cbf5f3b 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -8,7 +8,7 @@ "@capire/common": "*", "@sap/cds": "^4", "express": "^4.17.1", - "passport": "0.4.1" + "passport": "^0.4.1" }, "scripts": { "start": "cds run --in-memory?", @@ -23,8 +23,14 @@ "kind": "odata", "model": "@capire/orders" }, "db": { - "kind": "sql" + "kind": "sql", + "[development]": { + "model": "db/sqlite" + }, + "[production]": { + "model": "db/hana" + } } } } -} \ No newline at end of file +} diff --git a/fiori/test/requests.http b/fiori/test/requests.http index 95076ce3..badacbfe 100644 --- a/fiori/test/requests.http +++ b/fiori/test/requests.http @@ -63,3 +63,15 @@ Content-Type: application/json ### Get active order GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=true) + +### Create author +POST {{bookshop}}/admin/Authors +Content-Type: application/json +Authorization: Basic alice: + +{ + "ID": 200, + "name": "William Shakespeare", + "dateOfBirth": "1564-04-26", + "dateOfDeath": "1616-04-23" +}