Repository navigation
feat(go-api): Implement BulkDeleteChats Go API and fix ListChats - #16157
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughTwo new HTTP DELETE endpoints and their backing service methods are added for soft-deleting chats. The service enforces ownership via tenant ID matching, deduplicates IDs in batch operations, supports a ChangesChat soft-delete (single and bulk)
Sequence Diagram(s)sequenceDiagram
participant Client
participant Router
participant ChatHandler
participant ChatService
participant DB
rect rgba(70, 130, 180, 0.5)
note over Client,DB: DELETE /api/v1/chats/:chat_id
Client->>Router: DELETE /chats/:chat_id (auth token)
Router->>ChatHandler: DeleteChat(c *gin.Context)
ChatHandler->>ChatService: DeleteChat(userID, chatID)
ChatService->>DB: find chat where id=chatID, status=valid
DB-->>ChatService: chat or error
ChatService->>DB: update status="invalid"
DB-->>ChatService: ok
ChatService-->>ChatHandler: nil or "no authorization" error
ChatHandler-->>Client: 200 {code, data: true/false}
end
rect rgba(34, 139, 34, 0.5)
note over Client,DB: DELETE /api/v1/chats (bulk)
Client->>Router: DELETE /chats (JSON body: IDs/DeleteAll)
Router->>ChatHandler: BulkDeleteChats(c *gin.Context)
ChatHandler->>ChatService: BulkDeleteChats(userID, req)
ChatService->>DB: optionally fetch all valid chats for userID
loop each deduped chatID
ChatService->>DB: ownership check + status update
end
ChatService-->>ChatHandler: map[success_count, errors] or error
ChatHandler-->>Client: 200 {code, data: result, message}
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/handler/chat.go (1)
400-405: 💤 Low valueMinor: Pluralization in partial success message.
The message uses "chats" regardless of count, resulting in grammatically incorrect "1 chats" when
success_countis 1. Consider handling singular vs plural for better user experience.♻️ Suggested fix
message := "success" if errorsList, ok := result["errors"].([]string); ok && len(errorsList) > 0 { if successCount, ok := result["success_count"].(int); ok { - message = "Partially deleted " + strconv.Itoa(successCount) + " chats with " + strconv.Itoa(len(errorsList)) + " errors" + chatWord := "chats" + if successCount == 1 { + chatWord = "chat" + } + errorWord := "errors" + if len(errorsList) == 1 { + errorWord = "error" + } + message = "Partially deleted " + strconv.Itoa(successCount) + " " + chatWord + " with " + strconv.Itoa(len(errorsList)) + " " + errorWord } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/chat.go` around lines 400 - 405, The message string construction in the chat handler needs to handle proper pluralization for grammatically correct output. When building the "Partially deleted" message, check both the successCount value and the length of errorsList to determine whether to use singular or plural forms of "chat" and "error". Specifically, if successCount equals 1, use "chat" instead of "chats", and if len(errorsList) equals 1, use "error" instead of "errors". Apply conditional logic to select the appropriate word form based on the respective counts before constructing the final message string.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/handler/chat.go`:
- Around line 400-405: The message string construction in the chat handler needs
to handle proper pluralization for grammatically correct output. When building
the "Partially deleted" message, check both the successCount value and the
length of errorsList to determine whether to use singular or plural forms of
"chat" and "error". Specifically, if successCount equals 1, use "chat" instead
of "chats", and if len(errorsList) equals 1, use "error" instead of "errors".
Apply conditional logic to select the appropriate word form based on the
respective counts before constructing the final message string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 268c9309-8389-462a-9890-2c450538b6c8
📒 Files selected for processing (5)
internal/handler/chat.gointernal/handler/chat_test.gointernal/router/router.gointernal/service/chat.gointernal/service/chat_delete_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16157 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
LGTM |
Description
DELETE /api/v1/chatssupporting bulk delete byids,delete_allflag, and backward-compatiblechat_idbody payload (with tenant-ownership security checks).ListChatshandler to properly exclude soft-deleted chats.Verification & Testing
curltests.internal/handler/chat_test.gointernal/service/chat_delete_test.go