typespec-rust-emitter 0.10.6 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/dist/src/emitter.d.ts +2 -0
- package/dist/src/emitter.js +111 -7
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/test/hello.test.js +108 -1
- package/dist/test/hello.test.js.map +1 -1
- package/example/main.tsp +68 -5
- package/example/output-rust/Cargo.lock +2 -0
- package/example/output-rust/Cargo.toml +2 -0
- package/example/output-rust/src/generated/server.rs +82 -525
- package/example/output-rust/src/generated/types.rs +5 -352
- package/example/output-rust/src/main.rs +148 -2
- package/example/package-lock.json +3 -1
- package/package.json +1 -1
- package/src/emitter.ts +133 -8
- package/src/index.ts +2 -0
- package/src/lib.tsp +2 -0
- package/test/hello.test.ts +119 -1
- package/example/lib/learning/models.tsp +0 -234
- package/example/lib/learning/operations.tsp +0 -364
- package/example/output-rust/src/mod.rs +0 -1
|
@@ -14,565 +14,139 @@ pub trait Server: Send + Sync {
|
|
|
14
14
|
type Claims: Send + Sync + 'static;
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
async fn
|
|
19
|
-
|
|
20
|
-
async fn
|
|
21
|
-
|
|
22
|
-
async fn
|
|
23
|
-
/// Get the details of a group by its ID.
|
|
24
|
-
async fn groups_get_by_id(&self, account_id: uuid::Uuid, id: i64) -> Result<GroupsGetByIdResponse>;
|
|
25
|
-
/// Update a group. Only provide the fields that need to be changed.
|
|
26
|
-
async fn groups_update(&self, claims: Self::Claims, account_id: uuid::Uuid, id: i64, body: UpdateGroupBody) -> Result<GroupsUpdateResponse>;
|
|
27
|
-
/// Soft delete a group. All subjects within the group will also be soft deleted.
|
|
28
|
-
async fn groups_delete(&self, claims: Self::Claims, account_id: uuid::Uuid, id: i64) -> Result<GroupsDeleteResponse>;
|
|
29
|
-
/// Retrieve a list of subjects for a group (from view_subject_statistics).
|
|
30
|
-
async fn subjects_list(&self, account_id: uuid::Uuid, group_id: i64) -> Result<SubjectsListResponse>;
|
|
31
|
-
/// Create a new subject within the specified group.
|
|
32
|
-
async fn subjects_create(&self, claims: Self::Claims, account_id: uuid::Uuid, group_id: i64, body: CreateSubjectBody) -> Result<SubjectsCreateResponse>;
|
|
33
|
-
/// Get the details of a subject by its ID.
|
|
34
|
-
async fn subjects_get_by_id(&self, account_id: uuid::Uuid, group_id: i64, id: i64) -> Result<SubjectsGetByIdResponse>;
|
|
35
|
-
/// Update a subject. Only provide the fields that need to be changed.
|
|
36
|
-
async fn subjects_update(&self, claims: Self::Claims, account_id: uuid::Uuid, group_id: i64, id: i64, body: UpdateSubjectBody) -> Result<SubjectsUpdateResponse>;
|
|
37
|
-
/// Soft delete a subject.
|
|
38
|
-
async fn subjects_delete(&self, claims: Self::Claims, account_id: uuid::Uuid, group_id: i64, id: i64) -> Result<SubjectsDeleteResponse>;
|
|
39
|
-
/// Start a new study session for the subject.
|
|
40
|
-
/// The server creates a Log (status=Starting) and the first Timelog.
|
|
41
|
-
/// Returns 409 if the subject already has a session in Starting or Paused status.
|
|
42
|
-
async fn sessions_start(&self, claims: Self::Claims, account_id: uuid::Uuid, subject_id: i64, body: SessionNoteBody) -> Result<SessionsStartResponse>;
|
|
43
|
-
/// Pause the currently running session (transition from Starting to Paused).
|
|
44
|
-
/// The server closes the current Timelog (sets stoppedAt and calculates durationInSeconds).
|
|
45
|
-
/// Returns 409 if the session is not in the Starting state.
|
|
46
|
-
async fn sessions_pause(&self, claims: Self::Claims, account_id: uuid::Uuid, subject_id: i64, log_id: i64) -> Result<SessionsPauseResponse>;
|
|
47
|
-
/// Resume a paused session (transition from Paused to Starting).
|
|
48
|
-
/// The server creates a new Timelog.
|
|
49
|
-
/// Returns 409 if the session is not in the Paused state.
|
|
50
|
-
async fn sessions_resume(&self, claims: Self::Claims, account_id: uuid::Uuid, subject_id: i64, log_id: i64) -> Result<SessionsResumeResponse>;
|
|
51
|
-
/// End the session (transition from Starting or Paused to Stopped).
|
|
52
|
-
/// The server closes the current Timelog if it is running, and updates Log.stoppedAt.
|
|
53
|
-
/// Returns 409 if the session is already Stopped.
|
|
54
|
-
async fn sessions_stop(&self, claims: Self::Claims, account_id: uuid::Uuid, subject_id: i64, log_id: i64, body: SessionNoteBody) -> Result<SessionsStopResponse>;
|
|
55
|
-
/// Server-Sent Events stream for learning data changes.
|
|
56
|
-
async fn accounts_events(&self, account_id: uuid::Uuid) -> Result<AccountsEventsResponse>;
|
|
17
|
+
async fn events_accounts_events(&self, account_id: String) -> Result<EventsAccountsEventsResponse>;
|
|
18
|
+
async fn pets_list(&self, first_query: String, second_query: String) -> Result<PetsListResponse>;
|
|
19
|
+
async fn items_get_item(&self, id: String) -> Result<ItemsGetItemResponse>;
|
|
20
|
+
async fn items_create_item(&mut self, body: Item) -> Result<ItemsCreateItemResponse>;
|
|
21
|
+
async fn items_update_item(&mut self, id: String, body: Item) -> Result<ItemsUpdateItemResponse>;
|
|
22
|
+
async fn consuming_consume_and_delete(self, id: String) -> Result<ConsumingConsumeAndDeleteResponse>;
|
|
57
23
|
}
|
|
58
24
|
#[allow(clippy::type_complexity)]
|
|
59
|
-
pub enum
|
|
60
|
-
Ok(
|
|
61
|
-
Unauthorized(Json<ApiError>),
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
impl IntoResponse for GroupsListResponse {
|
|
65
|
-
fn into_response(self) -> axum::response::Response {
|
|
66
|
-
match self {
|
|
67
|
-
|
|
68
|
-
GroupsListResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
69
|
-
GroupsListResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
#[allow(clippy::type_complexity)]
|
|
75
|
-
pub enum GroupsCalendarResponse {
|
|
76
|
-
Ok(Json<Vec<CalendarHeatmapItem>>),
|
|
77
|
-
Unauthorized(Json<ApiError>),
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
impl IntoResponse for GroupsCalendarResponse {
|
|
81
|
-
fn into_response(self) -> axum::response::Response {
|
|
82
|
-
match self {
|
|
83
|
-
|
|
84
|
-
GroupsCalendarResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
85
|
-
GroupsCalendarResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
#[allow(clippy::type_complexity)]
|
|
91
|
-
pub enum GroupsCreateResponse {
|
|
92
|
-
Created(Json<Group>),
|
|
93
|
-
BadRequest(Json<ValidationError>),
|
|
94
|
-
Unauthorized(Json<ApiError>),
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
impl IntoResponse for GroupsCreateResponse {
|
|
98
|
-
fn into_response(self) -> axum::response::Response {
|
|
99
|
-
match self {
|
|
100
|
-
|
|
101
|
-
GroupsCreateResponse::Created(body) => (StatusCode::CREATED, body).into_response(),
|
|
102
|
-
GroupsCreateResponse::BadRequest(body) => (StatusCode::BAD_REQUEST, body).into_response(),
|
|
103
|
-
GroupsCreateResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
#[allow(clippy::type_complexity)]
|
|
109
|
-
pub enum GroupsGetByIdResponse {
|
|
110
|
-
Ok(Json<GroupStatistics>),
|
|
111
|
-
Unauthorized(Json<ApiError>),
|
|
112
|
-
NotFound(Json<NotFoundError>),
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
impl IntoResponse for GroupsGetByIdResponse {
|
|
116
|
-
fn into_response(self) -> axum::response::Response {
|
|
117
|
-
match self {
|
|
118
|
-
|
|
119
|
-
GroupsGetByIdResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
120
|
-
GroupsGetByIdResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
121
|
-
GroupsGetByIdResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
#[allow(clippy::type_complexity)]
|
|
127
|
-
pub enum GroupsUpdateResponse {
|
|
128
|
-
Ok(Json<Group>),
|
|
129
|
-
BadRequest(Json<ValidationError>),
|
|
130
|
-
Unauthorized(Json<ApiError>),
|
|
131
|
-
NotFound(Json<NotFoundError>),
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
impl IntoResponse for GroupsUpdateResponse {
|
|
135
|
-
fn into_response(self) -> axum::response::Response {
|
|
136
|
-
match self {
|
|
137
|
-
|
|
138
|
-
GroupsUpdateResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
139
|
-
GroupsUpdateResponse::BadRequest(body) => (StatusCode::BAD_REQUEST, body).into_response(),
|
|
140
|
-
GroupsUpdateResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
141
|
-
GroupsUpdateResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
#[allow(clippy::type_complexity)]
|
|
147
|
-
pub enum GroupsDeleteResponse {
|
|
148
|
-
NoContent,
|
|
149
|
-
Unauthorized(Json<ApiError>),
|
|
150
|
-
NotFound(Json<NotFoundError>),
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
impl IntoResponse for GroupsDeleteResponse {
|
|
154
|
-
fn into_response(self) -> axum::response::Response {
|
|
155
|
-
match self {
|
|
156
|
-
|
|
157
|
-
GroupsDeleteResponse::NoContent => StatusCode::NO_CONTENT.into_response(),
|
|
158
|
-
GroupsDeleteResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
159
|
-
GroupsDeleteResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
#[allow(clippy::type_complexity)]
|
|
165
|
-
pub enum SubjectsListResponse {
|
|
166
|
-
Ok(Json<Vec<SubjectStatistics>>),
|
|
167
|
-
Unauthorized(Json<ApiError>),
|
|
168
|
-
NotFound(Json<NotFoundError>),
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
impl IntoResponse for SubjectsListResponse {
|
|
172
|
-
fn into_response(self) -> axum::response::Response {
|
|
173
|
-
match self {
|
|
174
|
-
|
|
175
|
-
SubjectsListResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
176
|
-
SubjectsListResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
177
|
-
SubjectsListResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
#[allow(clippy::type_complexity)]
|
|
183
|
-
pub enum SubjectsCreateResponse {
|
|
184
|
-
Created(Json<Subject>),
|
|
185
|
-
BadRequest(Json<ValidationError>),
|
|
186
|
-
Unauthorized(Json<ApiError>),
|
|
187
|
-
NotFound(Json<NotFoundError>),
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
impl IntoResponse for SubjectsCreateResponse {
|
|
191
|
-
fn into_response(self) -> axum::response::Response {
|
|
192
|
-
match self {
|
|
193
|
-
|
|
194
|
-
SubjectsCreateResponse::Created(body) => (StatusCode::CREATED, body).into_response(),
|
|
195
|
-
SubjectsCreateResponse::BadRequest(body) => (StatusCode::BAD_REQUEST, body).into_response(),
|
|
196
|
-
SubjectsCreateResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
197
|
-
SubjectsCreateResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
#[allow(clippy::type_complexity)]
|
|
203
|
-
pub enum SubjectsGetByIdResponse {
|
|
204
|
-
Ok(Json<SubjectStatistics>),
|
|
205
|
-
Unauthorized(Json<ApiError>),
|
|
206
|
-
NotFound(Json<NotFoundError>),
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
impl IntoResponse for SubjectsGetByIdResponse {
|
|
210
|
-
fn into_response(self) -> axum::response::Response {
|
|
211
|
-
match self {
|
|
212
|
-
|
|
213
|
-
SubjectsGetByIdResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
214
|
-
SubjectsGetByIdResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
215
|
-
SubjectsGetByIdResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
#[allow(clippy::type_complexity)]
|
|
221
|
-
pub enum SubjectsUpdateResponse {
|
|
222
|
-
Ok(Json<Subject>),
|
|
223
|
-
BadRequest(Json<ValidationError>),
|
|
224
|
-
Unauthorized(Json<ApiError>),
|
|
225
|
-
NotFound(Json<NotFoundError>),
|
|
25
|
+
pub enum EventsAccountsEventsResponse {
|
|
26
|
+
Ok(axum::response::Response),
|
|
226
27
|
}
|
|
227
28
|
|
|
228
|
-
impl IntoResponse for
|
|
29
|
+
impl IntoResponse for EventsAccountsEventsResponse {
|
|
229
30
|
fn into_response(self) -> axum::response::Response {
|
|
230
31
|
match self {
|
|
231
32
|
|
|
232
|
-
|
|
233
|
-
SubjectsUpdateResponse::BadRequest(body) => (StatusCode::BAD_REQUEST, body).into_response(),
|
|
234
|
-
SubjectsUpdateResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
235
|
-
SubjectsUpdateResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
33
|
+
EventsAccountsEventsResponse::Ok(body) => body.into_response(),
|
|
236
34
|
}
|
|
237
35
|
}
|
|
238
36
|
}
|
|
239
37
|
|
|
240
38
|
#[allow(clippy::type_complexity)]
|
|
241
|
-
pub enum
|
|
242
|
-
|
|
243
|
-
Unauthorized(Json<ApiError>),
|
|
244
|
-
NotFound(Json<NotFoundError>),
|
|
39
|
+
pub enum PetsListResponse {
|
|
40
|
+
Ok(Json<Vec<String>>),
|
|
245
41
|
}
|
|
246
42
|
|
|
247
|
-
impl IntoResponse for
|
|
43
|
+
impl IntoResponse for PetsListResponse {
|
|
248
44
|
fn into_response(self) -> axum::response::Response {
|
|
249
45
|
match self {
|
|
250
46
|
|
|
251
|
-
|
|
252
|
-
SubjectsDeleteResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
253
|
-
SubjectsDeleteResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
47
|
+
PetsListResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
254
48
|
}
|
|
255
49
|
}
|
|
256
50
|
}
|
|
257
51
|
|
|
258
52
|
#[allow(clippy::type_complexity)]
|
|
259
|
-
pub enum
|
|
260
|
-
|
|
261
|
-
Unauthorized(Json<ApiError>),
|
|
262
|
-
NotFound(Json<NotFoundError>),
|
|
263
|
-
Conflict(Json<ConflictError>),
|
|
53
|
+
pub enum ItemsGetItemResponse {
|
|
54
|
+
Ok(Json<Item>),
|
|
264
55
|
}
|
|
265
56
|
|
|
266
|
-
impl IntoResponse for
|
|
57
|
+
impl IntoResponse for ItemsGetItemResponse {
|
|
267
58
|
fn into_response(self) -> axum::response::Response {
|
|
268
59
|
match self {
|
|
269
60
|
|
|
270
|
-
|
|
271
|
-
SessionsStartResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
272
|
-
SessionsStartResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
273
|
-
SessionsStartResponse::Conflict(body) => (StatusCode::CONFLICT, body).into_response(),
|
|
61
|
+
ItemsGetItemResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
274
62
|
}
|
|
275
63
|
}
|
|
276
64
|
}
|
|
277
65
|
|
|
278
66
|
#[allow(clippy::type_complexity)]
|
|
279
|
-
pub enum
|
|
280
|
-
Ok(Json<
|
|
281
|
-
Unauthorized(Json<ApiError>),
|
|
282
|
-
NotFound(Json<NotFoundError>),
|
|
283
|
-
Conflict(Json<ConflictError>),
|
|
67
|
+
pub enum ItemsCreateItemResponse {
|
|
68
|
+
Ok(Json<Item>),
|
|
284
69
|
}
|
|
285
70
|
|
|
286
|
-
impl IntoResponse for
|
|
71
|
+
impl IntoResponse for ItemsCreateItemResponse {
|
|
287
72
|
fn into_response(self) -> axum::response::Response {
|
|
288
73
|
match self {
|
|
289
74
|
|
|
290
|
-
|
|
291
|
-
SessionsPauseResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
292
|
-
SessionsPauseResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
293
|
-
SessionsPauseResponse::Conflict(body) => (StatusCode::CONFLICT, body).into_response(),
|
|
75
|
+
ItemsCreateItemResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
294
76
|
}
|
|
295
77
|
}
|
|
296
78
|
}
|
|
297
79
|
|
|
298
80
|
#[allow(clippy::type_complexity)]
|
|
299
|
-
pub enum
|
|
300
|
-
Ok(Json<
|
|
301
|
-
Unauthorized(Json<ApiError>),
|
|
302
|
-
NotFound(Json<NotFoundError>),
|
|
303
|
-
Conflict(Json<ConflictError>),
|
|
81
|
+
pub enum ItemsUpdateItemResponse {
|
|
82
|
+
Ok(Json<Item>),
|
|
304
83
|
}
|
|
305
84
|
|
|
306
|
-
impl IntoResponse for
|
|
85
|
+
impl IntoResponse for ItemsUpdateItemResponse {
|
|
307
86
|
fn into_response(self) -> axum::response::Response {
|
|
308
87
|
match self {
|
|
309
88
|
|
|
310
|
-
|
|
311
|
-
SessionsResumeResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
312
|
-
SessionsResumeResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
313
|
-
SessionsResumeResponse::Conflict(body) => (StatusCode::CONFLICT, body).into_response(),
|
|
89
|
+
ItemsUpdateItemResponse::Ok(body) => (StatusCode::OK, body).into_response(),
|
|
314
90
|
}
|
|
315
91
|
}
|
|
316
92
|
}
|
|
317
93
|
|
|
318
94
|
#[allow(clippy::type_complexity)]
|
|
319
|
-
pub enum
|
|
320
|
-
Ok
|
|
321
|
-
Unauthorized(Json<ApiError>),
|
|
322
|
-
NotFound(Json<NotFoundError>),
|
|
323
|
-
Conflict(Json<ConflictError>),
|
|
95
|
+
pub enum ConsumingConsumeAndDeleteResponse {
|
|
96
|
+
Ok,
|
|
324
97
|
}
|
|
325
98
|
|
|
326
|
-
impl IntoResponse for
|
|
99
|
+
impl IntoResponse for ConsumingConsumeAndDeleteResponse {
|
|
327
100
|
fn into_response(self) -> axum::response::Response {
|
|
328
101
|
match self {
|
|
329
102
|
|
|
330
|
-
|
|
331
|
-
SessionsStopResponse::Unauthorized(body) => (StatusCode::UNAUTHORIZED, body).into_response(),
|
|
332
|
-
SessionsStopResponse::NotFound(body) => (StatusCode::NOT_FOUND, body).into_response(),
|
|
333
|
-
SessionsStopResponse::Conflict(body) => (StatusCode::CONFLICT, body).into_response(),
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
#[allow(clippy::type_complexity)]
|
|
339
|
-
pub enum AccountsEventsResponse {
|
|
340
|
-
Ok(axum::response::Response),
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
impl IntoResponse for AccountsEventsResponse {
|
|
344
|
-
fn into_response(self) -> axum::response::Response {
|
|
345
|
-
match self {
|
|
346
|
-
|
|
347
|
-
AccountsEventsResponse::Ok(body) => body.into_response(),
|
|
103
|
+
ConsumingConsumeAndDeleteResponse::Ok => StatusCode::OK.into_response(),
|
|
348
104
|
}
|
|
349
105
|
}
|
|
350
106
|
}
|
|
351
107
|
|
|
352
108
|
use axum::extract::Query;
|
|
353
|
-
use axum::routing::{delete, get,
|
|
109
|
+
use axum::routing::{delete, get, post, put};
|
|
354
110
|
use axum::Router;
|
|
355
111
|
|
|
356
112
|
|
|
357
113
|
#[derive(Debug, Clone, serde::Deserialize)]
|
|
358
|
-
pub struct
|
|
359
|
-
|
|
360
|
-
pub
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
pub async fn groups_list_handler<S>(
|
|
367
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
368
|
-
Path(account_id): Path<uuid::Uuid>,
|
|
369
|
-
) -> impl axum::response::IntoResponse
|
|
370
|
-
where
|
|
371
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
372
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
373
|
-
{
|
|
374
|
-
let result = service.groups_list(account_id).await;
|
|
375
|
-
match result {
|
|
376
|
-
Ok(response) => response.into_response(),
|
|
377
|
-
Err(e) => (
|
|
378
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
379
|
-
format!("Internal error: {e}"),
|
|
380
|
-
)
|
|
381
|
-
.into_response(),
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
pub async fn groups_calendar_handler<S>(
|
|
386
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
387
|
-
Path((account_id, group_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
|
388
|
-
Query(params): Query<GroupsCalendarQuery>,
|
|
389
|
-
) -> impl axum::response::IntoResponse
|
|
390
|
-
where
|
|
391
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
392
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
393
|
-
{
|
|
394
|
-
let result = service.groups_calendar(account_id, group_id, params.user_timezone, params.year, params.month).await;
|
|
395
|
-
match result {
|
|
396
|
-
Ok(response) => response.into_response(),
|
|
397
|
-
Err(e) => (
|
|
398
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
399
|
-
format!("Internal error: {e}"),
|
|
400
|
-
)
|
|
401
|
-
.into_response(),
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
pub async fn groups_create_handler<S>(
|
|
406
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
407
|
-
Extension(claims): Extension<S::Claims>,
|
|
408
|
-
Path(account_id): Path<uuid::Uuid>,
|
|
409
|
-
Json(payload): Json<CreateGroupBody>,
|
|
410
|
-
) -> impl axum::response::IntoResponse
|
|
411
|
-
where
|
|
412
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
413
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
414
|
-
{
|
|
415
|
-
let result = service.groups_create(claims, account_id, payload).await;
|
|
416
|
-
match result {
|
|
417
|
-
Ok(response) => response.into_response(),
|
|
418
|
-
Err(e) => (
|
|
419
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
420
|
-
format!("Internal error: {e}"),
|
|
421
|
-
)
|
|
422
|
-
.into_response(),
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
pub async fn groups_get_by_id_handler<S>(
|
|
427
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
428
|
-
Path((account_id, id)): Path<(uuid::Uuid, i64)>,
|
|
429
|
-
) -> impl axum::response::IntoResponse
|
|
430
|
-
where
|
|
431
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
432
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
433
|
-
{
|
|
434
|
-
let result = service.groups_get_by_id(account_id, id).await;
|
|
435
|
-
match result {
|
|
436
|
-
Ok(response) => response.into_response(),
|
|
437
|
-
Err(e) => (
|
|
438
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
439
|
-
format!("Internal error: {e}"),
|
|
440
|
-
)
|
|
441
|
-
.into_response(),
|
|
442
|
-
}
|
|
114
|
+
pub struct PetsListQuery {
|
|
115
|
+
#[serde(rename = "firstQuery")]
|
|
116
|
+
pub first_query: String,
|
|
117
|
+
#[serde(rename = "secondQuery")]
|
|
118
|
+
pub second_query: String
|
|
443
119
|
}
|
|
444
120
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
Json(payload): Json<UpdateGroupBody>,
|
|
450
|
-
) -> impl axum::response::IntoResponse
|
|
451
|
-
where
|
|
452
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
453
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
454
|
-
{
|
|
455
|
-
let result = service.groups_update(claims, account_id, id, payload).await;
|
|
456
|
-
match result {
|
|
457
|
-
Ok(response) => response.into_response(),
|
|
458
|
-
Err(e) => (
|
|
459
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
460
|
-
format!("Internal error: {e}"),
|
|
461
|
-
)
|
|
462
|
-
.into_response(),
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
pub async fn groups_delete_handler<S>(
|
|
467
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
468
|
-
Extension(claims): Extension<S::Claims>,
|
|
469
|
-
Path((account_id, id)): Path<(uuid::Uuid, i64)>,
|
|
470
|
-
) -> impl axum::response::IntoResponse
|
|
471
|
-
where
|
|
472
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
473
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
474
|
-
{
|
|
475
|
-
let result = service.groups_delete(claims, account_id, id).await;
|
|
476
|
-
match result {
|
|
477
|
-
Ok(response) => response.into_response(),
|
|
478
|
-
Err(e) => (
|
|
479
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
480
|
-
format!("Internal error: {e}"),
|
|
481
|
-
)
|
|
482
|
-
.into_response(),
|
|
483
|
-
}
|
|
121
|
+
#[derive(Debug, Clone, serde::Deserialize)]
|
|
122
|
+
pub struct ItemsGetItemQuery {
|
|
123
|
+
#[serde(rename = "id")]
|
|
124
|
+
pub id: String
|
|
484
125
|
}
|
|
485
126
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
where
|
|
491
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
492
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
493
|
-
{
|
|
494
|
-
let result = service.subjects_list(account_id, group_id).await;
|
|
495
|
-
match result {
|
|
496
|
-
Ok(response) => response.into_response(),
|
|
497
|
-
Err(e) => (
|
|
498
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
499
|
-
format!("Internal error: {e}"),
|
|
500
|
-
)
|
|
501
|
-
.into_response(),
|
|
502
|
-
}
|
|
127
|
+
#[derive(Debug, Clone, serde::Deserialize)]
|
|
128
|
+
pub struct ItemsUpdateItemQuery {
|
|
129
|
+
#[serde(rename = "id")]
|
|
130
|
+
pub id: String
|
|
503
131
|
}
|
|
504
132
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
Json(payload): Json<CreateSubjectBody>,
|
|
510
|
-
) -> impl axum::response::IntoResponse
|
|
511
|
-
where
|
|
512
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
513
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
514
|
-
{
|
|
515
|
-
let result = service.subjects_create(claims, account_id, group_id, payload).await;
|
|
516
|
-
match result {
|
|
517
|
-
Ok(response) => response.into_response(),
|
|
518
|
-
Err(e) => (
|
|
519
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
520
|
-
format!("Internal error: {e}"),
|
|
521
|
-
)
|
|
522
|
-
.into_response(),
|
|
523
|
-
}
|
|
133
|
+
#[derive(Debug, Clone, serde::Deserialize)]
|
|
134
|
+
pub struct ConsumingConsumeAndDeleteQuery {
|
|
135
|
+
#[serde(rename = "id")]
|
|
136
|
+
pub id: String
|
|
524
137
|
}
|
|
525
138
|
|
|
526
|
-
pub async fn subjects_get_by_id_handler<S>(
|
|
527
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
528
|
-
Path((account_id, group_id, id)): Path<(uuid::Uuid, i64, i64)>,
|
|
529
|
-
) -> impl axum::response::IntoResponse
|
|
530
|
-
where
|
|
531
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
532
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
533
|
-
{
|
|
534
|
-
let result = service.subjects_get_by_id(account_id, group_id, id).await;
|
|
535
|
-
match result {
|
|
536
|
-
Ok(response) => response.into_response(),
|
|
537
|
-
Err(e) => (
|
|
538
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
539
|
-
format!("Internal error: {e}"),
|
|
540
|
-
)
|
|
541
|
-
.into_response(),
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
139
|
|
|
545
|
-
pub async fn subjects_update_handler<S>(
|
|
546
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
547
|
-
Extension(claims): Extension<S::Claims>,
|
|
548
|
-
Path((account_id, group_id, id)): Path<(uuid::Uuid, i64, i64)>,
|
|
549
|
-
Json(payload): Json<UpdateSubjectBody>,
|
|
550
|
-
) -> impl axum::response::IntoResponse
|
|
551
|
-
where
|
|
552
|
-
S: Server + Clone + Send + Sync + 'static,
|
|
553
|
-
S::Claims: Send + Sync + Clone + 'static,
|
|
554
|
-
{
|
|
555
|
-
let result = service.subjects_update(claims, account_id, group_id, id, payload).await;
|
|
556
|
-
match result {
|
|
557
|
-
Ok(response) => response.into_response(),
|
|
558
|
-
Err(e) => (
|
|
559
|
-
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
560
|
-
format!("Internal error: {e}"),
|
|
561
|
-
)
|
|
562
|
-
.into_response(),
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
140
|
|
|
566
|
-
pub async fn
|
|
141
|
+
pub async fn events_accounts_events_handler<S>(
|
|
567
142
|
axum::extract::State(service): axum::extract::State<S>,
|
|
568
|
-
|
|
569
|
-
Path((account_id, group_id, id)): Path<(uuid::Uuid, i64, i64)>,
|
|
143
|
+
Path(account_id): Path<String>,
|
|
570
144
|
) -> impl axum::response::IntoResponse
|
|
571
145
|
where
|
|
572
|
-
S: Server
|
|
146
|
+
S: Server+ Clone + Send + Sync + 'static,
|
|
573
147
|
S::Claims: Send + Sync + Clone + 'static,
|
|
574
148
|
{
|
|
575
|
-
let result = service.
|
|
149
|
+
let result = service.events_accounts_events(account_id).await;
|
|
576
150
|
match result {
|
|
577
151
|
Ok(response) => response.into_response(),
|
|
578
152
|
Err(e) => (
|
|
@@ -583,17 +157,15 @@ where
|
|
|
583
157
|
}
|
|
584
158
|
}
|
|
585
159
|
|
|
586
|
-
pub async fn
|
|
160
|
+
pub async fn pets_list_handler<S>(
|
|
587
161
|
axum::extract::State(service): axum::extract::State<S>,
|
|
588
|
-
|
|
589
|
-
Path((account_id, subject_id)): Path<(uuid::Uuid, i64)>,
|
|
590
|
-
Json(payload): Json<SessionNoteBody>,
|
|
162
|
+
Query(params): Query<PetsListQuery>,
|
|
591
163
|
) -> impl axum::response::IntoResponse
|
|
592
164
|
where
|
|
593
|
-
S: Server
|
|
165
|
+
S: Server+ Clone + Send + Sync + 'static,
|
|
594
166
|
S::Claims: Send + Sync + Clone + 'static,
|
|
595
167
|
{
|
|
596
|
-
let result = service.
|
|
168
|
+
let result = service.pets_list(params.first_query, params.second_query).await;
|
|
597
169
|
match result {
|
|
598
170
|
Ok(response) => response.into_response(),
|
|
599
171
|
Err(e) => (
|
|
@@ -604,16 +176,15 @@ where
|
|
|
604
176
|
}
|
|
605
177
|
}
|
|
606
178
|
|
|
607
|
-
pub async fn
|
|
179
|
+
pub async fn items_get_item_handler<S>(
|
|
608
180
|
axum::extract::State(service): axum::extract::State<S>,
|
|
609
|
-
|
|
610
|
-
Path((account_id, subject_id, log_id)): Path<(uuid::Uuid, i64, i64)>,
|
|
181
|
+
Query(params): Query<ItemsGetItemQuery>,
|
|
611
182
|
) -> impl axum::response::IntoResponse
|
|
612
183
|
where
|
|
613
|
-
S: Server
|
|
184
|
+
S: Server+ Clone + Send + Sync + 'static,
|
|
614
185
|
S::Claims: Send + Sync + Clone + 'static,
|
|
615
186
|
{
|
|
616
|
-
let result = service.
|
|
187
|
+
let result = service.items_get_item(params.id).await;
|
|
617
188
|
match result {
|
|
618
189
|
Ok(response) => response.into_response(),
|
|
619
190
|
Err(e) => (
|
|
@@ -624,16 +195,15 @@ where
|
|
|
624
195
|
}
|
|
625
196
|
}
|
|
626
197
|
|
|
627
|
-
pub async fn
|
|
628
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
629
|
-
|
|
630
|
-
Path((account_id, subject_id, log_id)): Path<(uuid::Uuid, i64, i64)>,
|
|
198
|
+
pub async fn items_create_item_handler<S>(
|
|
199
|
+
axum::extract::State(mut service): axum::extract::State<S>,
|
|
200
|
+
Json(payload): Json<Item>,
|
|
631
201
|
) -> impl axum::response::IntoResponse
|
|
632
202
|
where
|
|
633
|
-
S: Server
|
|
203
|
+
S: Server+ Clone + Send + Sync + 'static,
|
|
634
204
|
S::Claims: Send + Sync + Clone + 'static,
|
|
635
205
|
{
|
|
636
|
-
let result = service.
|
|
206
|
+
let result = service.items_create_item(payload).await;
|
|
637
207
|
match result {
|
|
638
208
|
Ok(response) => response.into_response(),
|
|
639
209
|
Err(e) => (
|
|
@@ -644,17 +214,16 @@ where
|
|
|
644
214
|
}
|
|
645
215
|
}
|
|
646
216
|
|
|
647
|
-
pub async fn
|
|
648
|
-
axum::extract::State(service): axum::extract::State<S>,
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
Json(payload): Json<SessionNoteBody>,
|
|
217
|
+
pub async fn items_update_item_handler<S>(
|
|
218
|
+
axum::extract::State(mut service): axum::extract::State<S>,
|
|
219
|
+
Query(params): Query<ItemsUpdateItemQuery>,
|
|
220
|
+
Json(payload): Json<Item>,
|
|
652
221
|
) -> impl axum::response::IntoResponse
|
|
653
222
|
where
|
|
654
|
-
S: Server
|
|
223
|
+
S: Server+ Clone + Send + Sync + 'static,
|
|
655
224
|
S::Claims: Send + Sync + Clone + 'static,
|
|
656
225
|
{
|
|
657
|
-
let result = service.
|
|
226
|
+
let result = service.items_update_item(params.id, payload).await;
|
|
658
227
|
match result {
|
|
659
228
|
Ok(response) => response.into_response(),
|
|
660
229
|
Err(e) => (
|
|
@@ -665,15 +234,17 @@ where
|
|
|
665
234
|
}
|
|
666
235
|
}
|
|
667
236
|
|
|
668
|
-
|
|
237
|
+
// NOTE: consuming_consume_and_delete takes self and cannot be used with the router pattern.
|
|
238
|
+
// It consumes the service, so you need to implement your own handler pattern.
|
|
239
|
+
pub async fn consuming_consume_and_delete_handler<S>(
|
|
669
240
|
axum::extract::State(service): axum::extract::State<S>,
|
|
670
|
-
|
|
241
|
+
Query(params): Query<ConsumingConsumeAndDeleteQuery>,
|
|
671
242
|
) -> impl axum::response::IntoResponse
|
|
672
243
|
where
|
|
673
|
-
S: Server +
|
|
244
|
+
S: Server + Send + Sync + 'static,
|
|
674
245
|
S::Claims: Send + Sync + Clone + 'static,
|
|
675
246
|
{
|
|
676
|
-
let result = service.
|
|
247
|
+
let result = service.consuming_consume_and_delete(params.id).await;
|
|
677
248
|
match result {
|
|
678
249
|
Ok(response) => response.into_response(),
|
|
679
250
|
Err(e) => (
|
|
@@ -692,26 +263,12 @@ where
|
|
|
692
263
|
{
|
|
693
264
|
let mut router = Router::new();
|
|
694
265
|
let public = Router::new()
|
|
695
|
-
.route("/
|
|
696
|
-
.route("/
|
|
697
|
-
.route("/
|
|
698
|
-
.route("/
|
|
699
|
-
.route("/
|
|
700
|
-
.route("/accounts/{accountId}/learning/accounts/{accountId}/events", get(accounts_events_handler::<S>))
|
|
266
|
+
.route("/events/{accountId}", get(events_accounts_events_handler::<S>))
|
|
267
|
+
.route("/pets", get(pets_list_handler::<S>))
|
|
268
|
+
.route("/items", get(items_get_item_handler::<S>))
|
|
269
|
+
.route("/items", post(items_create_item_handler::<S>))
|
|
270
|
+
.route("/items", put(items_update_item_handler::<S>))
|
|
701
271
|
;
|
|
702
272
|
router = router.merge(public);
|
|
703
|
-
let protected = Router::new()
|
|
704
|
-
.route("/accounts/{accountId}/learning/groups", post(groups_create_handler::<S>))
|
|
705
|
-
.route("/accounts/{accountId}/learning/groups/{id}", patch(groups_update_handler::<S>))
|
|
706
|
-
.route("/accounts/{accountId}/learning/groups/{id}", delete(groups_delete_handler::<S>))
|
|
707
|
-
.route("/accounts/{accountId}/learning/groups/{groupId}/subjects", post(subjects_create_handler::<S>))
|
|
708
|
-
.route("/accounts/{accountId}/learning/groups/{groupId}/subjects/{id}", patch(subjects_update_handler::<S>))
|
|
709
|
-
.route("/accounts/{accountId}/learning/groups/{groupId}/subjects/{id}", delete(subjects_delete_handler::<S>))
|
|
710
|
-
.route("/accounts/{accountId}/learning/subjects/{subjectId}/sessions", post(sessions_start_handler::<S>))
|
|
711
|
-
.route("/accounts/{accountId}/learning/subjects/{subjectId}/sessions/{logId}/pause", post(sessions_pause_handler::<S>))
|
|
712
|
-
.route("/accounts/{accountId}/learning/subjects/{subjectId}/sessions/{logId}/resume", post(sessions_resume_handler::<S>))
|
|
713
|
-
.route("/accounts/{accountId}/learning/subjects/{subjectId}/sessions/{logId}/stop", post(sessions_stop_handler::<S>))
|
|
714
|
-
;
|
|
715
|
-
router = router.merge(middleware(protected));
|
|
716
273
|
router.with_state(service)
|
|
717
274
|
}
|