Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel
9c49454f44 . 2021-06-18 17:59:54 +02:00
Daniel
d570ad20b2 ... 2021-06-18 17:59:27 +02:00
Daniel
d891a1b905 .. 2021-06-18 17:15:59 +02:00
Daniel
9f604b9d13 . 2021-06-18 16:57:15 +02:00
8 changed files with 54 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ extend Books with {
// Extend Orders with Books as Products
//
using { sap.capire.orders.Orders_Items } from '@capire/orders';
extend Orders_Items with {
using { sap.capire.orders.Orders } from '@capire/orders';
extend Orders.Items with {
book : Association to Books on product.ID = book.ID
}

View File

@@ -1,2 +1,3 @@
cds.requires.messaging.kind = file-based-messaging
PORT = 4006
# cds.odata.flavor = x4

View File

@@ -11,6 +11,7 @@
using { OrdersService } from '../../srv/orders-service';
using { sap.common } from '@capire/common';
@odata.draft.enabled
@@ -68,7 +69,7 @@ annotate OrdersService.Orders with @(
annotate OrdersService.Orders_Items with @(
annotate OrdersService.Orders.Items with @(
UI: {
LineItem: [
{Value: product_ID, Label:'Product ID'},
@@ -77,13 +78,22 @@ annotate OrdersService.Orders_Items with @(
{Value: amount, Label:'Quantity'},
],
Identification: [ //Is the main field group
{Value: product_ID, Label:'Product ID'},
{Value: title, Label:'Product Title'},
{Value: amount, Label:'Amount'},
{Value: title, Label:'Product'},
{Value: price, Label:'Unit Price'},
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: '@UI.Identification'},
],
HeaderInfo: {
TypeName: 'Order Item', TypeNamePlural: 'Order Items',
Title: {
Label: 'Product ID ', //A label is possible but it is not considered on the ObjectPage yet
Value: product_ID
},
Description: {Value: createdBy}
},
},
) {
amount @(

View File

@@ -3,17 +3,17 @@ namespace sap.capire.orders;
entity Orders : cuid, managed {
OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many Orders_Items on Items.up_ = $self;
Items : Composition of many Orders.Items on Items.up_ = $self;
buyer : User;
currency : Currency;
}
entity Orders_Items {
entity Orders.Items {
/*key*/ up_ : Association to Orders; // REVISIT: 'key' doesn't work due to bug in runtime
key ID : UUID;
up_ : Association to Orders;
product : Association to Products @assert.integrity:false; // REVISIT: this is a temporary workaround for a glitch in cds-runtime
product : Association to Products;
amount : Integer;
title : String; //> intentionally replicated as snapshot from product.title
title : String; //> intentionally replicated as snapshot from product.title or alike
price : Double;
}

View File

@@ -2,6 +2,7 @@
"name": "@capire/orders",
"version": "1.0.0",
"dependencies": {
"@capire/common": "*",
"@sap/cds": "^5"
}
}

31
orders/requests.http Normal file
View File

@@ -0,0 +1,31 @@
@Orders = http://localhost:4006/orders/Orders
### Read Orders
GET {{Orders}}?
###
GET {{Orders}}?$expand=Items
###
GET {{Orders}}(ID={{Order1}},IsActiveEntity=true)/Items
@Order1 = 64e718c9-ff99-47f1-8ca3-950c850777d4
@Order3 = e939604c-ab83-4d4f-bdb6-95fe30b3773e
### Create order, still inactive
POST {{Orders}}
Content-Type: application/json
{"ID": "{{Order3}}"}
### Get inactive order. We have to specify `IsActiveEntity`.
GET {{Orders}}(ID={{Order3}},IsActiveEntity=false)
### Activate order using `.../<servicename>.draftActivate`
POST {{Orders}}(ID={{Order3}},IsActiveEntity=false)/OrdersService.draftActivate
Content-Type: application/json
### Get active order
GET {{Orders}}(ID={{Order3}},IsActiveEntity=true)

View File

@@ -3,7 +3,7 @@ class OrdersService extends cds.ApplicationService {
/** register custom handlers */
init(){
const { Orders_Items:OrderItems } = this.entities
const { 'Orders.Items':OrderItems } = this.entities
this.before ('UPDATE', 'Orders', async function(req) {
const { ID, Items } = req.data