Initial monorepo structure
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
"""Email message routes."""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.auth import get_current_user_id
|
||||
from app.core.exceptions import NotFoundException
|
||||
from app.schemas.email import (
|
||||
EmailMessageResponse,
|
||||
EmailMessageListResponse,
|
||||
SendEmailRequest,
|
||||
ForwardEmailRequest
|
||||
)
|
||||
from 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))
|
||||
Reference in New Issue
Block a user