janczizikow / timeoff_backend

https://timeoff-backend.herokuapp.com/admin
1 stars 0 forks source link

timeoff_backend

Getting started

  1. virtualenv myenv --python=python3
  2. . myenv/bin/activate
  3. pip install -r requirements.txt
  4. ./manage.py migrate
  5. ./manage.py runserver

Endpoints:

All protected endpoints are marked with authentication required - pass Authorization: "Bearer " with a valid access_token.

Authentication:

POST /api/auth/token

Generates new pair of access & refresh tokens.

Example request body:

{
  "email": "user@example.com",
  "password": "password"
}

No authentication required Required fields: email, password

Returns auth payload

{
  "access":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU",
  "refresh":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}

access is a short-lived token, once it expires use refresh token to obtain another access token


POST /api/auth/refresh

Generates new short-lived access token.

Example request body:

{
  "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}

Required fields: refresh

Returns new access token

{"access":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w"}

POST /api/auth/forgot-password/

Sends an email with reset password link to the user.

Example request body:

{
  "email": "user@example.com"
}

Required fields: email

Returns __204 NO_CONTENT__


POST /api/auth/reset-password/

Resets user password.

Example request body:

{
  "reset_token": "en1rZSJ4Wo21SCJh2VWTvdGtR0TkIFdj",
  "password": "new_password123",
  "confirm_password": "new_password123"
}

Required fields: reset_token, password, confirm_password

Returns __204 NO_CONTENT__


POST /api/auth/change-password/

authentication required

Changes user password.

Example request body:

{
  "current_password": "secret123",
  "new_password": "new_password123",
  "confirm_new_password": "new_password123"
}

Required fields: current_password, new_password, confirm_new_password

Returns __204 NO_CONTENT__


GET /api/auth/me/

authentication required

Retrieves current user information

{
    "id": 1,
    "email": "user@example.com",
    "gender": "male",
    "first_name": "John",
    "last_name": "Doe",
    "preferred_name": "",
    "birth_date": "YYYY-MM-DD"
}

PUT /api/auth/me/

authentication required

Updates current user information

Example request body:

{
    "id": 1,
    "email": "user@example.com",
    "gender": "male",
    "first_name": "John",
    "last_name": "Doe",
    "preferred_name": "",
    "birth_date": "YYYY-MM-DD"
}

Leave Requests

LeaveRequest

{
    "id": 1,
    "start": "2019-12-02T10:00:00.000Z",
    "end": "2019-12-03T19:00:00.000Z",
    "description": "",
    "type": "VACATION",
    "status": "PENDING"
}

GET /api/leave-requests/

authentication required

List of leave requests for user


GET /api/leave-requests/<id>

authentication required

Retrieves leave request instance


POST /api/leave-requests/

authentication required

Creates a new Leave Request

Example request body:

{
    "start": "2019-12-02T10:00:00.000Z",
    "end": "2019-12-03T19:00:00.000Z",
    "description": "Gotta chill.",
    "type": "VACATION",
    "status": "PENDING"
}

PUT /api/leave-requests/<id>

authentication required

Updates a Leave Request


DELETE /api/leave-requests/<id>

authentication required

Deletes a Leave Request