This project is a simple web application for sending scheduled emails. It follows the Clean Architecture pattern.
- Python 3.11
- Flask Micro Framework
- PostgreSQL & SQLAlchemy (ORM)
- Redis
- Celery & Celery Beat
Copy .env.example:
cp .env.example .env
Requirements: Docker and Docker Compose must be installed.
Start the project with the following command:
docker-compose up -d
The application can be accessed at: http://127.0.0.1:5000/
Requirements: Redis must be installed for Celery to work.
Setup virtual environment with the following command:
flask --app src/app run
celery -A src.celery_config.celery_app worker --loglevel=info
celery -A src.celery_config.celery_app beat
The application can be accessed at: https://127.0.0.1:5000/
With docker:
docker exec -it flask_app flask db upgrade
Without docker:
flask db upgrade
Import sample data using the SQL query below:
INSERT INTO events (id, name)
VALUES
(1, 'Event 1'),
(2, 'Event 2'),
(3, 'Event 3');
INSERT INTO users (id, email)
VALUES
(1, '[email protected]'),
(2, '[email protected]'),
(3, '[email protected]');
INSERT INTO event_user_association (event_id, user_id)
VALUES
(1, 1), -- Event 1 with User 1
(1, 2), -- Event 1 with User 2
(2, 2), -- Event 2 with User 2
(3, 1), -- Event 3 with User 1
(3, 3); -- Event 3 with User 3
python -m unittest discover -s tests
You can access http://localhost:5000 to use the user interface to create emails.
curl -X POST \
http://localhost:5000/email \
-H 'Content-Type: application/json' \
-d '{
"event_id": 1,
"email_subject": "Example subject 3",
"email_content": "Example email content",
"timestamp": "15 Dec 2015 23:12"
}'
Sample Response (200 OK):
* Trying 127.0.0.1:5000...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> POST /email HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 139
>
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Sat, 16 Mar 2024 13:24:04 GMT
< Connection: close
< Content-Type: application/json
< Content-Length: 123
<
{"email_content":"Example email content","email_subject":"Example subject 3","event_id":1,"timestamp":"15 Dec 2015 23:12"}
* Closing connection 0