using {Currency, managed, sap, cuid} from '@sap/cds/common';
namespace my.foodorders;
entity FoodOrder : managed {
key orderid : UUID @(Core.Computed : true);
ordernum : Integer;
status : Integer;
receivedtime : Timestamp;
processor : String;
orderstatus : Association to FoodOrderStatus;
orderprocessor : Association to FoodOrderProcessor;
foodorderitems : Composition of many FoodOrderItems on foodorderitems.order = $self;
}
entity FoodOrderItems : managed {
key itemid : UUID @(Core.Computed : true);
deliver_addr : String;
ord_comment : String;
payment_method : String;
order : Association to FoodOrder;
}
@cds.odata.valuelist
entity FoodOrderStatus : managed {
key status : Integer;
description : String;
}
@cds.odata.valuelist
entity FoodOrderProcessor : managed {
key processor : String;
status : Integer;
}
using {Currency, managed, sap, cuid} from '@sap/cds/common';
status;description
1;Order Received
2;Order processing
3;Out of Deliver
4;Order Delivered
5;Order Finish
processor;status
PR00000001;1
PR00000002;1
PR00000003;3
using my.foodorders as my from '../db/foodorders_db';
@path: 'service/foodorders'
service FoodOrdersService {
entity FoodOrder as projection on my.FoodOrder;
annotate FoodOrder with @odata.draft.enabled;
entity FoodOrderItems as projection on my.FoodOrderItems;
entity FoodOrderStatus as projection on my.FoodOrderStatus;
annotate FoodOrderStatus with @odata.draft.enabled;
entity FoodOrderProcessor as projection on my.FoodOrderProcessor;
annotate FoodOrderProcessor with @odata.draft.enabled;
}
using FoodOrdersService as my from './foodorders_srv';
@path: 'service/foodorders'
annotate my.FoodOrder with {
orderid @(
UI.Hidden
);
status @title: 'Status';
receivedtime @title: 'Received Time';
processor @title : 'Processor';
}
annotate my.FoodOrderItems with {
payment_method @title : 'Payment Method';
deliver_addr @title: 'Deliver Address';
ord_comment @title: 'Order Comment';
}
annotate my.FoodOrderStatus with {
status @title: 'Status';
description @title: 'Status Description';
}
annotate my.FoodOrderProcessor with {
processor @title: 'Processor ID';
name @title: 'Processor Name';
}
annotate my.FoodOrderStatus with @(
UI:
{
LineItem : [
{Value: status},
{Value: description}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Items', Target: '@UI.FieldGroup#Items'}
],
FieldGroup#Items:
{
Data: [
{Value: status},
{Value: description},
]
}
}
){ };
annotate my.FoodOrder with @(
UI: {
LineItem : [
{Value: status},
{Value: receivedtime},
{Value: processor}
],
Facets: [
{$Type: 'UI.CollectionFacet', Label: 'Food Order',
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Header', Target: '@UI.FieldGroup#HeaderMain'},
{$Type: 'UI.ReferenceFacet', Label: 'Items', Target: 'foodorderitems/@UI.LineItem'},
]
}
],
FieldGroup#HeaderMain:
{
Data: [
{Value: status},
{Value: processor},
]
}
}
) {
status @(
Common.ValueListWithFixedValues : false,
Common.ValueListMapping : {
CollectionPath : 'FoodOrderStatus',
Label : 'Food Order Status',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty : 'status',
ValueListProperty : 'status'
},
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty : 'description'
}
]
}
);
processor @(
Common.ValueListWithFixedValues : false,
Common.ValueListMapping : {
CollectionPath : 'FoodOrderProcessor',
Label : 'Food Order Processors',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty : 'processor',
ValueListProperty : 'processor'
},
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty : 'status'
}
]
}
)
};
annotate my.FoodOrderItems with @(
UI: {
LineItem : [
{Value: payment_method},
{Value: deliver_addr}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Header', Target: '@UI.FieldGroup#ItemMain'}
],
FieldGroup#ItemMain:
{
Data: [
{Value: payment_method},
{Value: deliver_addr},
{Value: ord_comment}
]
}
}
) {
};
module.exports = (srv) => {
// Check if the processor is busy with other orders
srv.before ('CREATE', 'FoodOrder', async (req) => {
const { FoodOrderProcessor } = srv.entities
const processor = await SELECT.one(FoodOrderProcessor).where({processor: req.data.processor})
if (processor.status != 1)
return req.error (400, 'Processor is busy with other food order!')
else
UPDATE (FoodOrderProcessor)
.set ({statue: 2})
.where ({processor: req.data.processor})
})
}
cds deploy --to sqlite
Select 'List Report Object Page'.
As the terminal shows, the server is listening on http://localhost:4004 .
foodorderitems : Composition of many FoodOrderItems on foodorderitems.order = $self;
Facets: [
{$Type: 'UI.CollectionFacet', Label: 'Food Order',
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Header', Target: '@UI.FieldGroup#HeaderMain'},
{$Type: 'UI.ReferenceFacet', Label: 'Items', Target: 'foodorderitems/@UI.LineItem'},
]
}
],
orderstatus : Association to FoodOrderStatus;
@cds.odata.valuelist
entity FoodOrderStatus : managed {
key status : Integer;
description : String;
}
status @(
Common.ValueListWithFixedValues : false,
Common.ValueListMapping : {
CollectionPath : 'FoodOrderStatus',
Label : 'Food Order Status',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty : 'status',
ValueListProperty : 'status'
},
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty : 'description'
}
]
}
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
20 | |
11 | |
8 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |