Creating CAP-Based Services
This commit is contained in:
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
node_modules/
|
||||
target/
|
||||
_out/
|
||||
gen/
|
||||
|
||||
.cdsrc-private.json
|
||||
default-*.json
|
||||
*.sqlite
|
||||
|
||||
# MTA
|
||||
mta_archives/
|
||||
*_mta_build_tmp
|
||||
*.mtar
|
||||
|
||||
# Other
|
||||
.DS_Store
|
||||
|
||||
# @cap-js/cds-typer
|
||||
@cds-models
|
||||
4
db/data/sap.capire.incidents-Addresses.csv
Normal file
4
db/data/sap.capire.incidents-Addresses.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
ID,customer_ID,city,postCode,streetAddress
|
||||
17e00347-dc7e-4ca9-9c5d-06ccef69f064,1004155,Rome,00164,Piazza Adriana
|
||||
d8e797d9-6507-4aaa-b43f-5d2301df5135,1004161,Munich,80809,Olympia Park
|
||||
ff13d2fa-e00f-4ee5-951c-3303f490777b,1004100,Walldorf,69190,Dietmar-Hopp-Allee
|
||||
|
4
db/data/sap.capire.incidents-Customers.csv
Normal file
4
db/data/sap.capire.incidents-Customers.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
ID,firstName,lastName,email,phone
|
||||
1004155,Daniel,Watts,daniel.watts@demo.com,+39-555-123
|
||||
1004161,Stormy,Weathers,stormy.weathers@demo.com,+49-020-022
|
||||
1004100,Sunny,Sunshine,sunny.sunshine@demo.com,+49-555-789
|
||||
|
5
db/data/sap.capire.incidents-Incidents.conversation.csv
Normal file
5
db/data/sap.capire.incidents-Incidents.conversation.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
ID,up__ID,timestamp,author,message
|
||||
2b23bb4b-4ac7-4a24-ac02-aa10cabd842c,3b23bb4b-4ac7-4a24-ac02-aa10cabd842c,1995-12-17T03:24:00Z,Harry John,Can you please check if battery connections are fine?
|
||||
2b23bb4b-4ac7-4a24-ac02-aa10cabd843c,3a4ede72-244a-4f5f-8efa-b17e032d01ee,1995-12-18T04:24:00Z,Emily Elizabeth,Can you please check if there are any loose connections?
|
||||
9583f982-d7df-4aad-ab26-301d4a157cd7,3583f982-d7df-4aad-ab26-301d4a157cd7,2022-09-04T12:00:00Z,Sunny Sunshine,Please check why the solar panel is broken.
|
||||
9583f982-d7df-4aad-ab26-301d4a158cd7,3ccf474c-3881-44b7-99fb-59a2a4668418,2022-09-04T13:00:00Z,Bradley Flowers,What exactly is wrong?
|
||||
|
5
db/data/sap.capire.incidents-Incidents.csv
Normal file
5
db/data/sap.capire.incidents-Incidents.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
ID,customer_ID,title,urgency_code,status_code
|
||||
3b23bb4b-4ac7-4a24-ac02-aa10cabd842c,1004155,Inverter not functional,H,C
|
||||
3a4ede72-244a-4f5f-8efa-b17e032d01ee,1004161,No current on a sunny day,H,N
|
||||
3ccf474c-3881-44b7-99fb-59a2a4668418,1004161,Strange noise when switching off Inverter,M,N
|
||||
3583f982-d7df-4aad-ab26-301d4a157cd7,1004100,Solar panel broken,H,I
|
||||
|
7
db/data/sap.capire.incidents-Status.csv
Normal file
7
db/data/sap.capire.incidents-Status.csv
Normal file
@@ -0,0 +1,7 @@
|
||||
code,descr,criticality
|
||||
N,New,3
|
||||
A,Assigned,2
|
||||
I,In Process,2
|
||||
H,On Hold,3
|
||||
R,Resolved,2
|
||||
C,Closed,4
|
||||
|
1
db/data/sap.capire.incidents-Status.texts.csv
Normal file
1
db/data/sap.capire.incidents-Status.texts.csv
Normal file
@@ -0,0 +1 @@
|
||||
code,locale,name,descr
|
||||
|
4
db/data/sap.capire.incidents-Urgency.csv
Normal file
4
db/data/sap.capire.incidents-Urgency.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
code,descr
|
||||
H,High
|
||||
M,Medium
|
||||
L,Low
|
||||
|
1
db/data/sap.capire.incidents-Urgency.texts.csv
Normal file
1
db/data/sap.capire.incidents-Urgency.texts.csv
Normal file
@@ -0,0 +1 @@
|
||||
code,locale,name,descr
|
||||
|
70
db/schema.cds
Normal file
70
db/schema.cds
Normal file
@@ -0,0 +1,70 @@
|
||||
using {
|
||||
cuid,
|
||||
managed,
|
||||
sap.common.CodeList
|
||||
} from '@sap/cds/common';
|
||||
|
||||
namespace sap.capire.incidents;
|
||||
|
||||
/**
|
||||
* Incidents created by Customers.
|
||||
*/
|
||||
entity Incidents : cuid, managed {
|
||||
customer : Association to Customers;
|
||||
title : String @title: 'Title';
|
||||
urgency : Association to Urgency default 'M';
|
||||
status : Association to Status default 'N';
|
||||
conversation : Composition of many {
|
||||
key ID : UUID;
|
||||
timestamp : type of managed : createdAt;
|
||||
author : type of managed : createdBy;
|
||||
message : String;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Customers entitled to create support Incidents.
|
||||
*/
|
||||
entity Customers : managed {
|
||||
key ID : String;
|
||||
firstName : String;
|
||||
lastName : String;
|
||||
name : String = trim(firstName || ' ' || lastName);
|
||||
email : EMailAddress;
|
||||
phone : PhoneNumber;
|
||||
incidents : Association to many Incidents
|
||||
on incidents.customer = $self;
|
||||
creditCardNo : String(16) @assert.format: '^[1-9]\d{15}$';
|
||||
addresses : Composition of many Addresses
|
||||
on addresses.customer = $self;
|
||||
}
|
||||
|
||||
entity Addresses : cuid, managed {
|
||||
customer : Association to Customers;
|
||||
city : String;
|
||||
postCode : String;
|
||||
streetAddress : String;
|
||||
}
|
||||
|
||||
entity Status : CodeList {
|
||||
key code : String enum {
|
||||
new = 'N';
|
||||
assigned = 'A';
|
||||
in_process = 'I';
|
||||
on_hold = 'H';
|
||||
resolved = 'R';
|
||||
closed = 'C';
|
||||
};
|
||||
criticality : Integer;
|
||||
}
|
||||
|
||||
entity Urgency : CodeList {
|
||||
key code : String enum {
|
||||
high = 'H';
|
||||
medium = 'M';
|
||||
low = 'L';
|
||||
};
|
||||
}
|
||||
|
||||
type EMailAddress : String;
|
||||
type PhoneNumber : String;
|
||||
1460
package-lock.json
generated
Normal file
1460
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
package.json
Normal file
14
package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "incident-management",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@sap/cds": "^9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cap-js/sqlite": "^2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cds-serve"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
22
readme.md
Normal file
22
readme.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Getting Started
|
||||
|
||||
Welcome to your new CAP project.
|
||||
|
||||
It contains these folders and files, following our recommended project layout:
|
||||
|
||||
File or Folder | Purpose
|
||||
---------|----------
|
||||
`app/` | content for UI frontends goes here
|
||||
`db/` | your domain models and data go here
|
||||
`srv/` | your service models and code go here
|
||||
`readme.md` | this getting started guide
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Open a new terminal and run `cds watch`
|
||||
- (in VS Code simply choose _**Terminal** > Run Task > cds watch_)
|
||||
- Start with your domain model, in a CDS file in `db/`
|
||||
|
||||
## Learn More
|
||||
|
||||
Learn more at <https://cap.cloud.sap>.
|
||||
19
srv/services.cds
Normal file
19
srv/services.cds
Normal file
@@ -0,0 +1,19 @@
|
||||
using {sap.capire.incidents as my} from '../db/schema';
|
||||
|
||||
/**
|
||||
* Service used by support personell, i.e. the incidents' 'processors'.
|
||||
*/
|
||||
service ProcessorService {
|
||||
entity Incidents as projection on my.Incidents;
|
||||
|
||||
@readonly
|
||||
entity Customers as projection on my.Customers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service used by administrators to manage customers and incidents.
|
||||
*/
|
||||
service AdminService {
|
||||
entity Customers as projection on my.Customers;
|
||||
entity Incidents as projection on my.Incidents;
|
||||
}
|
||||
Reference in New Issue
Block a user