Skip to content

ristekoss/ulaskelas-backend

Repository files navigation

UlasKelas Backend

Final Project's Backend of Mobile Development SIG 2021 using Django Rest Framework.

Database Schmea

Database schema to as a guidance to data that will be used in this project

image

Getting Started

Move to backend directory

cd backend

Create virtual environment

python3 -m venv env

# Activate virtual environment
source env/bin/activate

# How to Deactivate
deactivate

Run app dev

  1. duplicate ./UlasKelas/.env.sample and rename to .env

  2. run postgres db

docker-compose up -d
  1. activate env and install requirement
source env/bin/activate
pip install -r requirements.txt
  1. run project
python manage.py runserver

Run app prod

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

Create or update database dev

before migrate db, make sure ulas-pg container running

  1. change or add the related models

  2. make migrations file && migrate database

python manage.py makemigrations
python manage.py migrate

Create or update database prod

  1. change or add the related models

  2. make migrations file make sure change pg host to localhost in settings.py before makemigrations

python manage.py makemigrations

change host to postgres again

  1. migrate database before migrate db, make sure ulas-pg container running
docker exec -it ulas-server python manage.py migrate

Access db

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 Endpoint Used

Sunjad all courses mock servers https://3e081de5-8b4c-46ea-8736-99476c47204b.mock.pstmn.io/courses


Documentation from 2020

Authentication

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"

About

Bacend Repository for Ulas Kelas RISTEK Fasilkom UI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages