Skip to content

Altu-K/task-manager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager REST API

Python Django DRF JWT SQLite

A backend REST API built with Django and Django REST Framework that provides secure JWT authentication, Role-Based Access Control (RBAC), task management, filtering, searching, ordering, pagination, and unit testing.


About the Project

Task Manager REST API is a backend application that enables authenticated users to securely create and manage personal tasks through RESTful APIs.

The project implements:

  • JWT Authentication using SimpleJWT
  • Role-Based Access Control (RBAC) using Django Groups
  • Complete CRUD operations for task management
  • Filtering
  • Searching
  • Ordering
  • Pagination
  • Unit Tests

The application follows Django REST Framework best practices including serializers, viewsets, custom permissions, optimized querysets using select_related(), and clean project organization.


Features

  • 🔐 JWT Authentication
  • 👥 Role-Based Access Control (Admin & User)
  • ✅ Complete CRUD Operations for Task Management
  • 🔍 Search Tasks
  • 🎯 Filter Tasks
  • ↕️ Ordering Support
  • 📄 Pagination
  • 👤 Admin-only User Listing
  • 🗂️ Admin-only Owner Filtering
  • ⚡ Optimized Database Queries using select_related()
  • 🧪 Unit Tests

This project demonstrates backend development best practices, including authentication, authorization, RESTful API design, query optimization, and automated testing.


Tech Stack

Technology Purpose
Python Programming Language
Django Web Framework
Django REST Framework REST API Development
SQLite Database
SimpleJWT Authentication
django-filter Filtering
python-dotenv Environment Variables

Dependencies

Package Purpose
Django Web framework
Django REST Framework REST API development
djangorestframework-simplejwt JWT authentication
django-filter Filtering support
python-dotenv Environment variable management

Project Structure

Task_Manager/
│
├── accounts/
├── tasks/
├── config/
├── manage.py
├── requirements.txt
├── README.md
└── .gitignore

Installation

Clone Repository

git clone https://github.com/Altu-K/task-manager-api
cd task-manager-api

Create Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Apply Migrations

python manage.py migrate

Create Default Roles

python manage.py create_roles

This command creates:

  • Admin
  • User

Create Superuser

python manage.py createsuperuser

Run the Development Server

python manage.py runserver

The development server will be available at:

http://127.0.0.1:8000/

Authentication

Register

POST

/api/auth/register/

Example Request

{
  "username": "john",
  "email": "john@example.com",
  "password": "Password123!"
}

Every registered user is automatically assigned to the User group. All protected endpoints require a valid JWT access token in the Authorization header.


Login

POST

/api/token/

Request

{
  "username": "john",
  "password": "Password123!"
}

Response

{
  "refresh": "<refresh_token>",
  "access": "<access_token>"
}

Refresh Token

POST

/api/token/refresh/

Request

{
  "refresh": "<refresh_token>"
}

Response

{
  "access": "<new_access_token>"
}

Authorization Header

Authorization: Bearer <access_token>

Roles

The application implements Role-Based Access Control (RBAC) using Django Groups.

Admin

  • View all users' tasks
  • Create, update, and delete any task
  • List all users
  • Filter tasks by owner

User

  • Create tasks
  • View only their own tasks
  • Update only their own tasks
  • Delete only their own tasks

Note:

  • Every newly registered user is automatically assigned to the User group.
  • The Admin and User groups are created using:
python manage.py create_roles
  • To grant Admin privileges, assign a user (including a superuser) to the Admin group through the Django Admin panel.

API Endpoints

Authentication

Method Endpoint
POST /api/auth/register/
POST /api/token/
POST /api/token/refresh/

Users

Method Endpoint Access
GET /api/auth/users/ Admin Only

Tasks

Method Endpoint
GET /api/tasks/
POST /api/tasks/
GET /api/tasks/{id}/
PUT /api/tasks/{id}/
PATCH /api/tasks/{id}/
DELETE /api/tasks/{id}/

Create Task

POST

POST /api/tasks/

Request Body

{
    "title": "Complete Django Assessment",
    "description": "Finish the Task Manager API project.",
    "status": "IN_PROGRESS",
    "due_date": "2026-07-15"
}

Task Status

The status field supports the following values:

Value Description
PENDING Default status for newly created tasks
IN_PROGRESS Task is currently being worked on
COMPLETED Task has been completed

Notes:

  • If status is not provided, it defaults to PENDING.
  • due_date is optional and should be provided in YYYY-MM-DD format.

Filtering

The API supports filtering tasks by status, due date, created date, and owner (Admin only).

Status

GET /api/tasks/?status=PENDING

Due Date

GET /api/tasks/?due_date__gte=2026-07-01

Owner (Admin Only)

GET /api/tasks/?owner=2

Search

GET /api/tasks/?search=django

Search is supported for:

  • title
  • description

Ordering

GET /api/tasks/?ordering=title

Supported fields:

  • title
  • due_date
  • created_at
  • updated_at

Pagination

The project uses Django REST Framework's global PageNumberPagination to return paginated responses for task listings.


Running Tests

Run all tests

python manage.py test

Authentication

python manage.py test accounts.tests.test_auth

Task Model

python manage.py test tasks.tests.test_models

Task API

python manage.py test tasks.tests.test_api

Security

  • JWT Authentication
  • RBAC using Django Groups
  • Read-only owner field
  • Password validation
  • Owner assigned automatically from authenticated user
  • Protected endpoints require authentication

Performance

  • Uses select_related("owner") to prevent the N+1 Query Problem.
  • Global pagination to reduce response size

Future Improvements

  • Docker containerization
  • PostgreSQL
  • Swagger / OpenAPI
  • CI/CD Pipeline

Author

Altamash Khan

Backend Developer | Python | Django | Django REST Framework

GitHub: https://github.com/Altu-K

LinkedIn: https://www.linkedin.com/in/altamash-k/

About

Task Manager REST API built with Django REST Framework featuring JWT Authentication, RBAC, Filtering, Search, Ordering, and Pagination.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages