Skip to content

Commit

Permalink
Add mail endpoint for sending test emails
Browse files Browse the repository at this point in the history
Introduced a new API endpoint to send test emails to curators. A new `TestMail` model was added to handle the email payload. Updated the API router to include routes for the mailing functionality.
  • Loading branch information
Zerskk committed Dec 2, 2024
1 parent 6ea8a10 commit f9dce4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.api.endpoints import publish
from app.api.endpoints import info
from app.api.endpoints import order
from app.api.endpoints import Mail


api_router = APIRouter(prefix="/api/v1")
Expand All @@ -18,3 +19,5 @@
api_router.include_router(publish.router, prefix="/publish", tags=["Publish"])
api_router.include_router(publish.router, prefix="/auth", tags=["Auth"])
api_router.include_router(order.router, prefix="/order", tags=["Order"])

api_router.include_router(order.router, prefix="/mail", tags=["Mail"])
25 changes: 25 additions & 0 deletions app/api/endpoints/mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import APIRouter, Body, Depends, HTTPException, status, Response, Request, BackgroundTasks
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder

from app.api.middlewares.http_basic_auth import *
from app.api.models.setup.project import TestMail
from app.tasks.email.send_mail import send_curator_mail

router = APIRouter()

@router.post("/send_test_curator_mail", summary="Send test mail", status_code=status.HTTP_201_CREATED,
response_class=Response, dependencies=[Depends(basic_auth)],
description="Send Curator Test Mail")
async def send_test_mail(request: Request, payload: TestMail, background_tasks: BackgroundTasks):

username = payload.username
project_name = payload.projectname
submission_url = payload.submission_url

curator_mail = os.environ.get("CURATOR_MAIL", None)
curator_mail = curator_mail.split(',')


background_tasks.add_task(send_curator_mail, curator_mail, username, project_name, submission_url)
return Response(status_code=status.HTTP_201_CREATED)
9 changes: 8 additions & 1 deletion app/api/models/setup/project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from __future__ import annotations

from pydantic import BaseModel
from typing import Optional
from typing import Optional, List


class Project(BaseModel):
project_id: int
overwrite: Optional[bool] = False

class Projects(BaseModel):
overwrite: Optional[bool] = False

class TestMail(BaseModel):
receiver: List[str]
username: str
projectname: str
submission_url: str

0 comments on commit f9dce4b

Please sign in to comment.