Skip to content

Build an API to manage tasks where users can create, update, and delete tasks, and mark tasks as complete or incomplete.

Notifications You must be signed in to change notification settings

KhadijaMakkaoui/Task-Management-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task-Management-API

Description:

  • Build an API to manage tasks where users can create, update, and delete tasks, and mark tasks as complete or incomplete. Why this project? Requirements:
  • CRUD operations for tasks and users.
  • Endpoint for marking tasks as complete or incomplete.
  • Use Django ORM for database interactions.
  • Deploy the API on Heroku or PythonAnywhere. Project Managment(TRELLO) KANBAN BOARD

Entity Relationship Diagram(ERD) ERD

1. Initializing Git and GitHub

Create a new directory for the project:

mkdir task_management_api
cd task_management_api
git init
git remote add origin [Repository Link](https://github.com/KhadijaMakkaoui/Task-Management-API.git) 

2. Setting Up Django Project Structure

 pip install django
 pip install djangorestframework
 #Create an app for managing tasks
 python manage.py startapp tasks

Add the app to INSTALLED_APPS in task_management/settings.py

3. Creating a Virtual Environment and Installing Dependencies

#Create a virtual environment to isolate project dependencies
python -m venv venv
# Activate the virtual environment on Windows
venv\Scripts\activate
#Install required dependencies, including Django and Django REST Framework
pip install django djangorestframework
#Save dependencies to requirements.txt to simplify future setup
pip freeze > requirements.txt
#Run initial migrations for the project
python manage.py migrate

Configure PostgreSQL db

Install PostgreSQL and psycopg2 First, ensure that PostgreSQL is installed on your system. You will also need the psycopg2 package to allow Django to interact with the PostgreSQL database.

  • Install psycopg2 using pip:
pip install psycopg2
  • Modify the DATABASES setting in the settings.py file to use PostgreSQL instead of SQLite.

Task URLs (CRUD Operations):

GET /tasks/ → List all tasks.

POST /tasks/ → Create a new task.

GET /tasks// → Retrieve a specific task.

PUT /tasks// or PATCH /tasks// → Update a specific task.

DELETE /tasks// → Delete a specific task.

User URLs (CRUD Operations):

GET /users/ → List all users.

POST /users/ → Create a new user.

GET /users// → Retrieve a specific user.

PUT /users// or PATCH /users// → Update a specific user.

DELETE /users// → Delete a specific user.

Custom Action URLs (Using @action):

PATCH /tasks//mark_complete/ → Mark a task as complete.

PATCH /tasks//mark_incomplete/ → Revert a task to incomplete.

Setting Up JWT Authentication

  1. Install Required Packages:
pip install djangorestframework-simplejwt
  1. Configure JWT in Django:
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',  # By default, require users to be logged in
    ],}
  1. Usage: You can now use the /api/token/ endpoint to obtain an access and refresh token by sending a POST request with valid user credentials (username and password).

Use the /api/token/refresh/ endpoint to refresh the access token using the refresh token.

  1. Implement task filtering and sorting in Django REST Framework
    1. install django filter
   pip install django-filter
  1. Update settings to include DjangoFilterBackend Add DEFAULT_FILTER_BACKENDS to the settings.py file

  2. Define Filters and Ordering in the View

  3. API Requests Filter by status: /api/tasks/?status=pending

Filter by priority: /api/tasks/?priority=high

Filter by due date: /api/tasks/?due_date=2024-10-07

Sort by due date: /api/tasks/?ordering=due_date

Sort by priority: /api/tasks/?ordering=priority_level

if you'd like to reverse the order, use a minus sign: /api/tasks/?ordering=-priority_level Filter by status and sort by due date: /api/tasks/?status=pending&ordering=due_date

Deployment with PythonAnywhere

About

Build an API to manage tasks where users can create, update, and delete tasks, and mark tasks as complete or incomplete.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published