TT-003: complete request-module integration into modular platform

- integrated request-module into module registry
- moved backend into modules/request-module
- added manifest.json and module.py
- implemented dynamic router mounting
- implemented dynamic static mounting
- removed direct dependencies from platform core
- verified startup with request-module
- verified startup without request-module
- added implementation_report_003.md
This commit is contained in:
2026-08-06 16:31:27 +03:00
parent c97e6a42f7
commit 6c86f0f571
180 changed files with 204885 additions and 25 deletions
@@ -0,0 +1,115 @@
"""Email message routes."""
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from typing import List
from request_app.core.database import get_db
from request_app.core.auth import get_current_user_id
from request_app.core.exceptions import NotFoundException
from request_app.schemas.email import (
EmailMessageResponse,
EmailMessageListResponse,
SendEmailRequest,
ForwardEmailRequest
)
from request_app.services.email_message_service import EmailMessageService
router = APIRouter(prefix="/tickets/{ticket_id}/emails", tags=["Emails"])
@router.get("", response_model=List[EmailMessageResponse])
async def get_ticket_emails(
ticket_id: int,
token: str = Depends(get_current_user_id),
db: Session = Depends(get_db)
):
"""Get all email messages for a ticket."""
service = EmailMessageService(db)
try:
return service.get_ticket_emails(ticket_id)
except NotFoundException as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
@router.get("/{email_id}", response_model=EmailMessageResponse)
async def get_email(
ticket_id: int,
email_id: int,
token: str = Depends(get_current_user_id),
db: Session = Depends(get_db)
):
"""Get email message by ID."""
service = EmailMessageService(db)
try:
email = service.get_email_by_id(email_id)
if email.ticket_id != ticket_id:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Email not found in this ticket")
return email
except NotFoundException as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
@router.post("/reply", response_model=EmailMessageResponse, status_code=status.HTTP_201_CREATED)
async def send_reply(
ticket_id: int,
email_data: SendEmailRequest,
user_id: int = Depends(get_current_user_id),
db: Session = Depends(get_db)
):
"""Send a reply email."""
service = EmailMessageService(db)
try:
return service.send_reply(
ticket_id=ticket_id,
user_id=user_id,
to_addresses=email_data.to_addresses,
subject=email_data.subject,
body_text=email_data.body_text,
body_html=email_data.body_html,
in_reply_to=email_data.in_reply_to,
cc_addresses=email_data.cc_addresses
)
except NotFoundException as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
@router.post("/{email_id}/forward", response_model=EmailMessageResponse, status_code=status.HTTP_201_CREATED)
async def forward_email(
ticket_id: int,
email_id: int,
forward_data: ForwardEmailRequest,
user_id: int = Depends(get_current_user_id),
db: Session = Depends(get_db)
):
"""Forward an email to new recipients."""
service = EmailMessageService(db)
try:
return service.forward_email(
email_id=email_id,
user_id=user_id,
to_addresses=forward_data.to_addresses,
cc_addresses=forward_data.cc_addresses,
add_message=forward_data.add_message
)
except NotFoundException as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
@router.put("/{email_id}/read", response_model=EmailMessageResponse)
async def mark_as_read(
ticket_id: int,
email_id: int,
token: str = Depends(get_current_user_id),
db: Session = Depends(get_db)
):
"""Mark email as read."""
service = EmailMessageService(db)
try:
return service.mark_as_read(email_id)
except NotFoundException as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))