Final Project's Backend of Mobile Development SIG 2021 using Django Rest Framework.
Database schema to as a guidance to data that will be used in this project
cd backend
python3 -m venv env
# Activate virtual environment
source env/bin/activate
# How to Deactivate
deactivate
-
duplicate ./UlasKelas/.env.sample and rename to .env
-
run postgres db
docker-compose up -d
- activate env and install requirement
source env/bin/activate
pip install -r requirements.txt
- run project
python manage.py runserver
docker-compose -f docker-compose-prod.yml up -d
if you make code changes, run this command
docker-compose -f docker-compose-prod.yml down && sudo docker-compose -f docker-compose-prod.yml build && docker-compose -f docker-compose-prod.yml up -d
before migrate db, make sure ulas-pg container running
-
change or add the related models
-
make migrations file && migrate database
python manage.py makemigrations
python manage.py migrate
-
change or add the related models
-
make migrations file make sure change pg host to localhost in settings.py before makemigrations
python manage.py makemigrations
change host to postgres again
- migrate database before migrate db, make sure ulas-pg container running
docker exec -it ulas-server python manage.py migrate
docker exec -it ulas-pg bash
psql -U postgres
or use database management and input credentials provided in settings.py
Now you can login with superuser you just create on https://localhost:8000 and interact with API view OR call the API endpoint with cURL or Postman.
Sunjad all courses mock servers https://3e081de5-8b4c-46ea-8736-99476c47204b.mock.pstmn.io/courses
Send POST request to /login/
. This endpoint will redirect user to SSO Login page. If login success, login page will be directed to /token/
endpoint where you can retrieve token and username in its URL parameters.
Example:
{BACKEND_ROOT_URL}/token?token=f039021efcvery-long-tokencbe90717daded39&username=dummy.dumdum
This token will be used in authorization header as token authorization. Set Token {very-long-token}
as value of Authorization
on the headers of every endpoint that need authorization.
Example:
curl {BACKEND_ROOT_URL}/any-restricted-endpoint/
-H "Accept: application/json"
-H "Authorization: Token f039021efcvery-long-tokencbe90717daded39"