Skip to content

rahulg0/task-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Management API

Overview

This is a Django REST framework-based Task Management API that allows user registration, authentication, task management, and user retrieval. It includes token-based authentication, rate limiting, and an AWS Lambda simulation for task completion notifications.

Setup Instructions

Prerequisites

  • Python 3.x
  • Django 3.x or later
  • Django REST Framework
  • PostgreSQL or SQLite (default)

Installation

  1. Clone the repository:

    git clone git@github.com:rahulg0/task-management.git
    cd task-management
  2. Create a virtual environment and activate it:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install dependencies:

    pip install -r requirements.txt
  4. Apply migrations:

    python manage.py migrate
  5. Create a superuser:

    python manage.py createsuperuser
  6. Run the development server:

    python manage.py runserver

API Endpoints

Authentication

Register a new user

POST /api/register/

Request Body:

{
  "username": "testuser",
  "email": "test@example.com",
  "password": "securepassword"
}

Response:

{
  "message": "Successfully created user.",
  "token": "<authentication_token>"
}

Login

POST /api/login/

Request Body:

{
  "email": "test@example.com",
  "password": "securepassword"
}

Response:

{
  "token": "<authentication_token>",
  "id": 1
}

Users

Get All Users (Admin Only)

GET /api/get-users/

Headers:

Authorization: Token <authentication_token>

Response:

{
  "users": [
    {
      "id": 1,
      "username": "testuser",
      "email": "test@example.com"
    }
  ]
}

Tasks

Get Tasks

GET /api/tasks/?status=

Headers:

Authorization: Token <authentication_token>

Response:

{
  "tasks": [
    {
      "id": 1,
      "title": "Task 1",
      "status": "pending",
      "assigned_to": 1
    }
  ]
}

Create Task (Admin Only)

POST /api/tasks/

Headers:

Authorization: Token <authentication_token>

Request Body:

{
  "title": "New Task",
  "description": "Task description",
  "assigned_to": 2
}

Response:

{
  "message": "Successfully created task: New Task"
}

Update Task

PUT /api/tasks/{task_id}/

Headers:

Authorization: Token <authentication_token>

Request Body:

{
  "status": "completed"
}

Response:

{
  "message": "Successfully updated task: New Task"
}

Delete Task (Admin Only)

DELETE /api/tasks/{task_id}/

Headers:

Authorization: Token <authentication_token>

Response:

{
  "message": "Task deleted successfully"
}

Design Choices

1. Django Rest Framework (DRF) with Token Authentication

  • Provides a structured and scalable approach for API development.
  • Token-based authentication ensures secure access.

2. Class-Based Views (CBVs) with APIView

  • Enhances maintainability and code reuse.
  • Simplifies handling different HTTP methods.

3. Permissions & Authentication

  • permissions.IsAuthenticated ensures only authorized users can access certain endpoints.
  • permissions.AllowAny allows open access for login and registration.
  • TokenAuthentication secures API requests.

4. Task Management Logic

  • Superusers can create, assign, and delete tasks.
  • Regular users can only update the status of their assigned tasks.
  • Query parameters allow task filtering by status.

5. Rate Limiting (Throttling)

  • UserRateThrottle prevents API abuse.
  • Unit tests validate throttling behavior.

6. Database Indexing for Performance

  • status and assigned_to fields in Task model have db_index=True.
  • Improves filtering and lookup speed.

7. AWS Lambda Simulation for Task Completion

  • Optional feature to simulate a Lambda function call when a task is completed.
  • Useful for event-driven processing.

8. User Management & Superuser Privileges

  • Users are uniquely identified via email.
  • Only superusers can manage tasks and user data.

Running Unit Tests

To run tests for tasks throttling, execute:

python manage.py test

Conclusion

This API balances security, scalability, and maintainability, making it efficient for managing tasks with proper access control.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages