You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/messaging/index.md
+24-27Lines changed: 24 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,53 +116,51 @@ The following explanations walk us through a books review example from cap/sampl
116
116

117
117
118
118
::: tip
119
-
Follow the instructions in [*cap/samples/readme*](https://github.com/capire) for getting the samples and exercising the following steps.
119
+
Follow the instructions in [*cap/samples/readme*](https://github.com/capire/samples) for getting the samples and exercising the following steps.
120
120
:::
121
121
122
122
### Declaring Events in CDS
123
123
124
-
Package `@capire/reviews`essentially provides a `ReviewsService`, [declared like that](https://github.com/capire/reviews/tree/main/srv/reviews-service.cds):
124
+
Package `@capire/reviews` provides a `ReviewsService` API, [declared like that](https://github.com/capire/reviews/tree/main/srv/reviews-api.cds):
125
125
126
126
```cds
127
-
service ReviewsService {
128
-
129
-
// Sync API
130
-
entity Reviews as projection on my.Reviews excluding { likes }
131
-
action like (review: Reviews:ID);
132
-
action unlike (review: Reviews:ID);
133
-
134
-
// Async API
135
-
event reviewed : {
136
-
subject : Reviews:subject;
137
-
count : Integer;
138
-
rating : Decimal; // new avg rating
139
-
}
140
-
127
+
service ReviewsService @(path:'reviews/api') {
128
+
129
+
/**
130
+
* Summary of average ratings per subject.
131
+
*/
132
+
@readonly entity AverageRatings as projection on my.Reviews {
133
+
key subject,
134
+
round(avg(rating),2) as rating : my.Rating,
135
+
count(*) as reviews : Integer,
136
+
} group by subject;
137
+
138
+
/**
139
+
* Informs about changes in a subject's average rating.
[Learn more about declaring events in CDS.](../../cds/cdl#events){.learn-more}
145
146
146
-
As you can read from the definitions, the service's synchronous API allows to create, read, update, and delete user `Reviews` for arbitrary review subjects. In addition, the service's asynchronous API declares the `reviewed` event that shall be emitted whenever a subject's average rating changes.
147
+
As we can read from the definition, the service's synchronous API allows to read average ratings per subject; the service's asynchronous API declares the `AverageRatings.Changed` event that shall be emitted whenever a subject's average rating changes.
147
148
148
149
::: tip
149
150
**Services in CAP** combine **synchronous***and***asynchronous** APIs. Events are declared on conceptual level focusing on domain, instead of low-level wire protocols.
150
151
:::
151
152
152
153
### Emitting Events
153
154
154
-
Find the code to emit events in *[@capire/reviews/srv/reviews-service.js](https://github.com/capire/reviews/tree/main/srv/reviews-service.js#L12-L20)*:
155
+
Find the code to emit events in *[@capire/reviews/srv/reviews-service.js](https://github.com/capire/reviews/tree/main/srv/reviews-service.js#L32-L37)*:
0 commit comments