Implement batch delete operation for CRUD API#614
Conversation
78041e9 to
5a83c9f
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements a batch delete operation for the CRUD API, adding a DELETE /records/{resource}/many endpoint that allows deletion of multiple records in a single request using query parameters.
Key Changes:
- Adds
delete_many()function indynamodb.rsthat uses DynamoDB'sbatch_write_itemAPI with automatic chunking (25 items per batch) - Adds
delete_many_records_handler()inmain.rswith ownership verification for user-scoped resources - Updates route configuration to support DELETE method on
/records/{resource}/manyendpoint
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| crud_api/src/dynamodb.rs | Implements delete_many() function using DynamoDB batch_write_item API with chunking and unprocessed item tracking |
| crud_api/src/main.rs | Adds delete_many_records_handler() with user ownership verification, updates route to include DELETE method, and modifies unused parameter naming in get_many_related_records_handler |
5a83c9f to
c332e00
Compare
|
@copilot apply changes based on the comments in this thread |
9c27f44 to
af71aa1
Compare
|
@copilot apply changes based on the comments in this thread |
| let ids = query_params | ||
| .id | ||
| .iter() | ||
| .map(String::as_str) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| // Enforce a maximum of 100 IDs per request to align with DynamoDB batch limits | ||
| if ids.len() > 100 { | ||
| return ( | ||
| StatusCode::BAD_REQUEST, | ||
| [(header::CONTENT_TYPE, "application/json")], | ||
| Json(json!({ | ||
| "message": "Too many IDs provided. Maximum of 100 IDs per request.", | ||
| })), | ||
| ); | ||
| } | ||
|
|
||
| // If user_scoped, verify ownership of all items before deleting | ||
| if table_config.user_scoped { | ||
| match dynamodb::get_many(&state.dynamodb, &table_config, &ids).await { | ||
| Ok(items) => { | ||
| if let Some(user) = &user_id { | ||
| // Verify all requested IDs exist and belong to the user | ||
| if items.len() != ids.len() { | ||
| return ( |
There was a problem hiding this comment.
delete_many_records_handler treats duplicate IDs as an error because items.len() != ids.len() will trip even when all records exist (BatchGet returns one item per unique key). Consider de-duplicating the requested IDs (while optionally preserving original order) before doing existence/ownership checks and before calling delete_many, or return a 400 with a clear message when duplicates are provided.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com>
…fy deletion tracking Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com>
… fix security gap, and improve consistency Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com>
… chunking logic Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com>
…lts, return 503 on errors Agent-Logs-Url: https://github.com/saebyn/glowing-telegram/sessions/328fedef-f215-42a7-81f1-18941b6f2c7e Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com>
aa2dbb5 to
1274a4e
Compare
Adds
DELETE /records/{resource}/manyendpoint to delete multiple records in a single request.Implementation
dynamodb.rs:
delete_many()usingbatch_write_itemAPI with chunking (25 items per batch) and exponential backoff retry for unprocessed itemsget_many()with 100-item chunking and retry logic for unprocessed keysmain.rs:
delete_many_records_handlerwith user ownership verification?id=id1&id=id2&id=id3{"deleted": [...], "count": n}with IDs in sorted orderUsage
Features
Testing
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.