2019-03-11 13:36:42 +04:00
|
|
|
from fastapi import APIRouter, Depends
|
2020-01-19 22:40:50 +01:00
|
|
|
from pydantic.networks import EmailStr
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2023-12-27 13:49:36 -05:00
|
|
|
from app.api.deps import get_current_active_superuser
|
2019-02-09 19:42:36 +04:00
|
|
|
from app.core.celery_app import celery_app
|
2023-12-27 13:49:36 -05:00
|
|
|
from app.models import Message
|
2024-03-10 00:02:36 +01:00
|
|
|
from app.utils import generate_test_email, send_email
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
2023-12-27 13:49:36 -05:00
|
|
|
@router.post(
|
|
|
|
"/test-celery/",
|
|
|
|
dependencies=[Depends(get_current_active_superuser)],
|
|
|
|
status_code=201,
|
|
|
|
)
|
|
|
|
def test_celery(body: Message) -> Message:
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
:sparkles: Add Items (crud, models, endpoints), utils, refactor (#14)
* Update CRUD utils to use types better.
* Simplify Pydantic model names, from `UserInCreate` to `UserCreate`, etc.
* Upgrade packages.
* Add new generic "Items" models, crud utils, endpoints, and tests. To facilitate re-using them to create new functionality. As they are simple and generic (not like Users), it's easier to copy-paste and adapt them to each use case.
* Update endpoints/*path operations* to simplify code and use new utilities, prefix and tags in `include_router`.
* Update testing utils.
* Update linting rules, relax vulture to reduce false positives.
* Update migrations to include new Items.
* Update project README.md with tips about how to start with backend.
2019-04-19 09:45:23 +04:00
|
|
|
Test Celery worker.
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
2023-12-27 13:49:36 -05:00
|
|
|
celery_app.send_task("app.worker.test_celery", args=[body.message])
|
|
|
|
return Message(message="Word received")
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
2023-12-27 13:49:36 -05:00
|
|
|
@router.post(
|
|
|
|
"/test-email/",
|
|
|
|
dependencies=[Depends(get_current_active_superuser)],
|
|
|
|
status_code=201,
|
|
|
|
)
|
|
|
|
def test_email(email_to: EmailStr) -> Message:
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
:sparkles: Add Items (crud, models, endpoints), utils, refactor (#14)
* Update CRUD utils to use types better.
* Simplify Pydantic model names, from `UserInCreate` to `UserCreate`, etc.
* Upgrade packages.
* Add new generic "Items" models, crud utils, endpoints, and tests. To facilitate re-using them to create new functionality. As they are simple and generic (not like Users), it's easier to copy-paste and adapt them to each use case.
* Update endpoints/*path operations* to simplify code and use new utilities, prefix and tags in `include_router`.
* Update testing utils.
* Update linting rules, relax vulture to reduce false positives.
* Update migrations to include new Items.
* Update project README.md with tips about how to start with backend.
2019-04-19 09:45:23 +04:00
|
|
|
Test emails.
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
2024-03-10 00:02:36 +01:00
|
|
|
email_data = generate_test_email(email_to=email_to)
|
|
|
|
send_email(
|
|
|
|
email_to=email_to,
|
|
|
|
subject=email_data.subject,
|
|
|
|
html_content=email_data.html_content,
|
|
|
|
)
|
2023-12-27 13:49:36 -05:00
|
|
|
return Message(message="Test email sent")
|