API for view schools and students
- Python 3.8
- Docker
- Docker-Compose
- Postgres (if want to run locally)
- Django 3.2
- Django Rest Framework 3.13.1
- Pytest
- api/v1/students/ (GET, POST)
- api/v1//schools/ (GET, POST)
- api/v1/schools/:id (GET, PUT, PATCH, DELETE)
- api/v1/students/:id (GET, PUT, PATCH, DELETE)
- api/v1//schools/:id/students (GET, POST)
- api/v1/schools/:id/students/:id (GET, PUT, PATCH, DELETE)
- Clone the project into a directory you've created on your machine
git clone https://github.com/switchell1990/challenge.git- To get into the project directory from your terminal
cd manatal- Open project into your editior (VS CODE)
code .- Create a file in the root and call it .env
- Add the following environments
ALLOWED_HOSTS=*
DATABASE_URL=postgres://postgres:postgres@postgres:5432/school_api (for docker)
DATABASE_URL=postgres://postgres:postgres@localhost:5432/school_api (for local)
POSTGRES_PASSWORD=postgres
POSTGRES_DB=school_api
DEBUG=True
SECRET_KEY=set_me
Once your project is up and running,you can access it from your access the api by going to - http://localhost:8000/api/
- Open a command terminal and run Docker-Compose (Postgres)
docker-compose up -d postgres- Open a new terminal and Run Docker-Compose (Django) - This will also do your create migrations and migrations.
docker-compose up -d django- Add initial data
docker-compose exec django ./manage.py createdatadocker-compose exec django pytest- Create a database with the following commands (reuqires postgres installed on local machine)
psql -U postgrescreate database school_api;- Create environemnt and install dependencies
pipenv install -r dependencies/requirements-dev.txt- Activate the virtual enviornment
pipenv shell- Migrate the migrations.
./manage.py migrate-Run tests
pytest- Run the server
./manage.py runserver- To access the API Document, visit - http://localhost:8000/docs/
- Time spend - 1 hour
- Time spent - 2 hours
- Time spent - 3 hours (including setting up tests)
I have decided to change how delete works, instead of deleting the record I have opted to change the is_active flag to false so the records can be kept in the database for a period of time.
