This is a REST API for voting restaurant menus.
Uses the default Django development server.
- Update the environment variables in the docker-compose.yml and .env.dev.
.env.dev Example
DEBUG=1
SECRET_KEY=foo
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=postgres
SQL_USER=postgres
SQL_PASSWORD=postgres
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
EMAIL_HOST_PASSWORD=<Add sndgrid email host Here>
LOGIN_REDIRECT_URL=<Add login redirect Here>
CLOUDINARY_CLOUD_NAME=<Add Cloudinary Name Here>
CLOUDINARY_API_KEY=<Add Cloudinary API Key Here>
CLOUDINARY_API_SECRET=<Add Cloudinary API Secret Here>
-
Build the images and run the containers:
$ docker-compose up -d --build
-
Create migrations and apply them into database. NOTE the containers must be running:
$ docker-compose exec web python manage.py makemigrations
$ docker-compose exec web python manage.py migrate
-
Test it out at http://localhost:8000. The "app" folder is mounted into the container and your code changes apply automatically.
$ docker-compose exec web python manage.py test
NOTE: Before you execute the command above. The containers must me up an running.
Uses gunicorn and nginx.
- Update the environment variables in .env.prod and .env.prod.db
.env.prod Example
DEBUG=0
SECRET_KEY=foo
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=postgres
SQL_USER=postgres
SQL_PASSWORD=postgres
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
EMAIL_HOST_PASSWORD=<Add sndgrid email host Here>
LOGIN_REDIRECT_URL=<Add login redirect Here>
CLOUDINARY_CLOUD_NAME=<Add Cloudinary Name Here>
CLOUDINARY_API_KEY=<Add Cloudinary API Key Here>
CLOUDINARY_API_SECRET=<Add Cloudinary API Secret Here>
.env.prod.db Example
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
-
Build the images and run the containers:
$ docker-compose -f docker-compose.prod.yml up -d --build
Test it out at http://localhost:1337. No mounted folders. To apply changes, the image must be re-built.
$ docker-compose -f docker-compose.prod.yml down -v
The API has been intergrated with third party services namely:
- Sendgrid - Handles Emailing Check out here how to intergrate sendgrid with Django
- Cloudinary - Handles File Storage Check oout here how to intergrate Cloudinary with Django
- Authentication
- Creating restaurant
- Uploading menu for restaurant (There should be a menu for each day)
- Creating employee
- Getting current day menu
- Voting for restaurant menu
- Getting results for the current day. The winner restaurant should not be the winner for 3 consecutive working days
- Logout
- Django==3.1.7
- djangorestframework==3.12.4
- Markdown==3.3.4
- django-filter==2.4.0
- djangorestframework-jwt==1.11.0
- PyJWT==1.5.2
- django-cors-headers==3.6.0
- cloudinary==1.24.0
- dj3-cloudinary-storage==0.0.3
- gunicorn==19.9.0
- Pillow >= 8.0
- coverage==5.5
- python-decouple==3.4
- pycodestyle==2.7.0
- autopep8==1.5.7
- flake8
- mock==4.0.3
- psycopg2-binary>=2.8
View all the other dependencies
You can view the full Postman Collection Here.
Some endpoints require a token for authentication. The API call should have the token in Authorization header.
`{'Authorization': 'Bearer': <token>}`
EndPoint | Functionality |
---|---|
POST /api/register_user/ | Register a user |
POST /api/create_employee/ | Creates a new employee |
POST /api/login/ | User login |
GET /api/logout/ | Logout user |
GET /api/restaurants/ | List all restaurants |
GET /api/menu_list/ | List all menus of current day |
GET /api/vote/:id/ | Vote menu |
GET /api/results/ | Show results of the day |
The API responds with JSON data by default.
Request GET /api/results/
curl -H "Authorization: Bearer <your_token>" -H "Content-Type: application/json" https://localhost:8000/api/results/