Besteats allows users to cast votes on restaurants.
Django 5 pre-configured with the following side-services and libraries:
- Django Admin configured with Constance config which is where the admin can update the "configurable" daily user votes.
- Celery - Background task/job runner, along with the popular django-celery-beat integration which allows us to configure cronjobs and schedule tasks in the admin interface e.g. that resets the users daily votes.
- REST Framework - API endpoint development framework built on top of Django. Minimally configured so we can have endpoints to interact with frontend.
- drf-spectacular - generates Swagger documentation for our REST Framework endpoints at
/api/swagger
.
This is all wrapped up into a docker-compose
environment with development defaults. The only configuration required is a random SECRET_KEY
. Postgres which waits for the service to be ready and Redis are all preconfigured.
We've configured docker-compose to run flake8 and tests using default values in the example.env
file.
A complete list of everything included in this app beyond what you get from the default Django cookiecutter.
- Application with the name
besteats
created apps/
module created for our apps- Cache enabled with Redis backend
settings.py
greatly expanded beyond the default options in the file.- Admin page settings added for
staff
to investigate changes constance.py
pattern implemented as an optional alternative to environment variables for configuration
- Functions and classes that are reusable accross the project e.g. get or set constance config
- Users can
create
restaurants andupdate or delete
restaurants they have added. - Users can set a
vote or unvote
restaurants. - Each user is given a
daily vote limit
which resets at midnight. - User's cast the first vote towards a particular restaurant which amounts to 1 point, second amounts to 0.5 and the rest amount to 0.25 points.
- Integrated into Django
- Standard base config defined in
settings.py
- Swagger documentation generation configured at
/api/swagger
- Documentation toggled on and off with
ENABLE_BROWSEABLE
setting
- Integrated into project
- Django Beat scheduler added so you can configure scheduled tasks using the django admin interface
- Default configuration uses redis as broker and result backend
- Accessible on Django Admin
- Config changes can be made while the app is running with no need of rebooting the server
- Update the
USER_DAILY_VOTES
Please ensure you have Docker Compose installed. If not, you can get it here
cp example.env .env
in root folder- Update variables in
.env
- Run
docker-compose build
- Run migrations with
docker-compose run --rm backend ./manage.py migrate
- Create a superuser with
docker-compose run --rm backend ./manage.py createsuperuser
- Update
Constance Config
values on Django Admin
docker-compose up
to start the project
- http://localhost:8000/api/swagger to access the swagger
- http://localhost:8000/admin to access the admin
- We'll be using Postman because we're able to update
environment variables
using scripts - Import the
besteats.postman_collection.json
andbesteats.postman_environment.json
files found in the root folder. See here or here for guidance on how to import the files. - Navigate to
Besteats/authentication/registration
and register at least 3 users using thehttp://{{base_url}}/api/auth/registration/
endpoint - Navigate to
Besteats/restaurants/create
, update theBody
and create at least 3 restaurants. - Now we can cast votes on the latest created restaurant i.e.
{restaurant_id}
, usingBesteats/restaurants/vote
- We can cast votes on other restaurants by changing the
{restaurant_id}
env variable or updating the URL -http://{{base_url}}/api/restaurants/{{restaurant_id}}/vote
. Use theBesteats/restaurants/list
to get the restaurant IDs. - Users can unvote from restaurants using
Besteats/restaurants/unvote
- Users can also view the restaurant or restaurants with the most votes today using
Besteats/restaurants/most_voted
- To view the previos winner(s) on a specific date, update the
query params
usingdate
as the key and the value should be in the following formatYYYY-MM-DD
, e.g.http://{{base_url}}/api/restaurants/most_voted?date=2024-07-10
- Login as a different user using
Besteats/authentication/login
to cast more votes - To reset the daily user votes, we can use the managemnent command
docker-compose run --rm backend ./manage.py reset_daily_votes_for_all_profles
or wait until the next day. - Try replicate the scenario in the tests
test_most_voted_restaurant
andtest_most_voted_restaurants
both found inbesteats/apps/restaurants/tests/integration/test_restaurant_views
- Note: only users who created a restaurant and staff can make updates to it.
These operations assume the project is already up and are to be run in a second terminal session.
- Flake8:
docker-compose exec backend flake8
- Generate migrations:
docker-compose exec backend ./manage.py makemigrations
- Run migrations:
docker-compose exec backend ./manage.py migrate
- Create superuser:
docker-compose exec backend ./manage.py createsuperuser
- Create a new app:
docker-compose exec backend ./manage.py startapp <APP_NAME>
(and drag it into theapps/
folder) - Run the project in the background:
docker-compose up -d
- Run tests with coverage:
docker-compose exec backend sh -c "coverage run --source='.' ./manage.py test && coverage report -m --omit=*/tests/*,*/migrations/*,*manage.py,*wsgi.py,*asgi.py"
- Completely stop the project:
docker-compose down
- Delete the project and delete database/S3 data:
docker-compose down -v