DELETE /api/threads/{id}
Delete a thread and all associated messages
DELETE
Authentication
Required: JWT Bearer token JWT Claims Extraction (Lines 430-434):Path Parameters
Thread UUIDFormat: Valid GUIDValidation: Route constraint
:guid (Line 423)Authorization
Ownership Verification (Lines 442-456):- ONLY thread owner can delete
- No admin override documented
- Cannot delete other users’ threads (even if public/unlisted)
Side Effects
Database Mutations (Line 458):- DELETE from
thread_messagesWHEREthread_id = {threadId} - Potential orphaned
comparisonsrecords (if not cascade deleted) - Potential orphaned
model_votesrecords (if linked via comparison_id)
Permissions
Who Can Delete:- Thread owner only
- Other authenticated users
- Unauthenticated users
- Public thread viewers
Edge Cases
- Thread doesn’t exist: 404 (Lines 443-446)
- Already deleted: 404 (service returns null)
- User is not owner: 403 (Lines 448-456)
- Thread has messages: Deleted (cascade assumed)
- Thread has comparisons: Cascade behavior not specified by API contract
- Thread has votes: Cascade behavior not specified by API contract
- Concurrent deletion: Race condition possible (no locking documented)
Error Conditions
| Code | HTTP | Cause | Controller Line |
|---|---|---|---|
| N/A | 401 | JWT missing or invalid | Middleware |
| N/A | 401 | User ID claim missing | 436-439 |
NOT_FOUND | 404 | Thread doesn’t exist | 443-446 |
FORBIDDEN | 403 | Not thread owner | 448-456 |
THREAD_DELETE_ERROR | 500 | Service exception | 466-474 |
Behavioral Guarantees
Atomicity: Database transaction-dependent (not enforced by controller) Idempotency: NOT idempotent- First call: 200 success
- Second call: 404 not found
- No soft delete
- No recovery mechanism documented
Cascade Effects
Documented in Database Schema (outside controller): Likely cascades based on foreign key constraints:thread_messagestable: CASCADE DELETEcomparisonstable: Behavior not specifiedmodel_votestable: Behavior not specified
- If comparisons not cascade deleted, may orphan comparison records
- If votes not cascade deleted, may orphan vote records
- Controller does not enforce cascade rules
Validation Order
- User ID from JWT (401 if missing)
- Thread existence (404 if not found)
- Ownership (403 if not owner)
- Deletion execution (500 if fails)
Recovery
No Undo: Once deleted, thread cannot be recovered via API Backup Recommendation: Application should implement soft delete or backup before deletion No Confirmation: Controller does not require confirmation parameterSecurity Implications
Data Loss: Permanent deletion of:- Thread metadata
- All messages in thread
- Potentially associated comparisons and votes