feat: enhance messaging system with improved API and tests

- Refactor messaging API endpoints for admin, shop, and vendor
- Add message-specific exceptions (ConversationNotFoundException, etc.)
- Enhance messaging service with additional helper methods
- Add comprehensive test fixtures for messaging
- Add integration tests for admin and vendor messaging APIs
- Add unit tests for messaging and attachment services

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-21 21:01:14 +01:00
parent 3bfe0ad3f8
commit 0098093287
11 changed files with 2229 additions and 136 deletions

View File

@@ -21,7 +21,12 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_customer_api
from app.core.database import get_db
from app.exceptions import ConversationNotFoundException, VendorNotFoundException
from app.exceptions import (
AttachmentNotFoundException,
ConversationClosedException,
ConversationNotFoundException,
VendorNotFoundException,
)
from app.services.message_attachment_service import message_attachment_service
from app.services.messaging_service import messaging_service
from models.database.customer import Customer
@@ -292,12 +297,7 @@ async def send_message(
# Check if conversation is closed
if conversation.is_closed:
from fastapi import HTTPException
raise HTTPException(
status_code=400,
detail="Cannot send messages to a closed conversation",
)
raise ConversationClosedException(conversation_id)
# Process attachments
attachment_data = []
@@ -405,7 +405,6 @@ async def download_attachment(
Validates that customer has access to the conversation.
"""
from fastapi import HTTPException
from fastapi.responses import FileResponse
vendor = getattr(request.state, "vendor", None)
@@ -433,7 +432,7 @@ async def download_attachment(
)
if not attachment:
raise HTTPException(status_code=404, detail="Attachment not found")
raise AttachmentNotFoundException(attachment_id)
return FileResponse(
path=attachment.file_path,
@@ -455,7 +454,6 @@ async def get_attachment_thumbnail(
Validates that customer has access to the conversation.
"""
from fastapi import HTTPException
from fastapi.responses import FileResponse
vendor = getattr(request.state, "vendor", None)
@@ -483,7 +481,7 @@ async def get_attachment_thumbnail(
)
if not attachment or not attachment.thumbnail_path:
raise HTTPException(status_code=404, detail="Thumbnail not found")
raise AttachmentNotFoundException(f"{attachment_id}/thumbnail")
return FileResponse(
path=attachment.thumbnail_path,