Skip to content

DeShyam01/student-task-manager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Student Task Manager API

A RESTful API for managing student tasks with JWT-based authentication. Built with Node.js, Express, and MongoDB.

🌐 Live API: https://student-task-manager-api-latest.onrender.com


πŸ› οΈ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB (Mongoose)
  • Authentication: JWT (JSON Web Tokens)

πŸš€ Getting Started (Run Locally)

Prerequisites

  • Node.js v18+
  • MongoDB (local or Atlas)

Installation

# Clone the repository
git clone https://github.com/DeShyam01/student-task-manager-api.git
cd student-task-manager-api

# Install dependencies
npm install

Environment Variables

Create a .env file in the root directory:

PORT=3000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key

Run the Server

# Development
npm run dev

# Production
npm start

Server will start at http://localhost:3000


πŸ“‘ API Endpoints

Base URL

https://student-task-manager-api-1.onrender.com

Note: All /tasks routes require a valid JWT token in the Authorization header:

Authorization: Bearer <your_token>

πŸ” Auth Routes β€” /api/v1/user

Method Endpoint Auth Description
POST /api/v1/user/register ❌ Register a new user
POST /api/v1/user/login ❌ Login and get JWT token
GET /api/v1/user/profile βœ… Get logged-in user's profile

POST /api/v1/user/register

// Request Body
{
  "name": "Shyam",
  "email": "shyam@example.com",
  "password": "yourpassword"
}

// Response 201
{
  "message": "User registered successfully",
  "token": "<jwt_token>"
}

POST /api/v1/user/login

// Request Body
{
  "email": "shyam@example.com",
  "password": "yourpassword"
}

// Response 200
{
  "token": "<jwt_token>"
}

GET /api/v1/user/profile πŸ”’

// Response 200
{
  "_id": "64abc...",
  "name": "Shyam",
  "email": "shyam@example.com",
  "role": "student",
  "createdAt": "2025-03-01T00:00:00.000Z",
  "updatedAt": "2025-03-01T00:00:00.000Z"
}

βœ… Task Routes β€” /api/v1/tasks

All task routes are protected β€” include the JWT token in every request.

Method Endpoint Auth Description
GET /api/v1/tasks βœ… Get all tasks for logged-in user
GET /api/v1/tasks/:id βœ… Get a specific task by ID
POST /api/v1/tasks βœ… Create a new task
PUT /api/v1/tasks/:id βœ… Update a task
PATCH /api/v1/tasks/:id/complete βœ… Mark a task as complete
DELETE /api/v1/tasks/:id βœ… Delete a task

GET /api/v1/tasks πŸ”’

// Response 200
[
  {
    "_id": "64xyz...",
    "title": "Complete DSA assignment",
    "description": "Solve linked list problems",
    "dueDate": "2025-03-10T00:00:00.000Z",
    "priority": 1,
    "status": "Pending",
    "userId": "64abc...",
    "createdAt": "2025-03-01T00:00:00.000Z",
    "updatedAt": "2025-03-01T00:00:00.000Z"
  }
]

POST /api/v1/tasks πŸ”’

// Request Body
{
  "title": "Complete DSA assignment",
  "description": "Solve linked list problems",
  "dueDate": "2025-03-10",
  "priority": 1
}
// priority: 1 = High, 2 = Medium, 3 = Low

// Response 201
{
  "_id": "64xyz...",
  "title": "Complete DSA assignment",
  "description": "Solve linked list problems",
  "dueDate": "2025-03-10T00:00:00.000Z",
  "priority": 1,
  "status": "Pending",
  "userId": "64abc...",
  "createdAt": "2025-03-01T00:00:00.000Z",
  "updatedAt": "2025-03-01T00:00:00.000Z"
}

PUT /api/v1/tasks/:id πŸ”’

// Request Body (all fields optional)
{
  "title": "Updated title",
  "description": "Updated description",
  "dueDate": "2025-03-15",
  "priority": 2
}

// Response 200
{
  "_id": "64xyz...",
  "title": "Updated title",
  "description": "Updated description",
  "dueDate": "2025-03-15T00:00:00.000Z",
  "priority": 2,
  "status": "Pending",
  "userId": "64abc...",
  "createdAt": "2025-03-01T00:00:00.000Z",
  "updatedAt": "2025-03-05T00:00:00.000Z"
}

PATCH /api/v1/tasks/:id/complete πŸ”’

// Response 200
{
  "_id": "64xyz...",
  "title": "Complete DSA assignment",
  "status": "completed",
  "updatedAt": "2025-03-05T00:00:00.000Z"
}

DELETE /api/v1/tasks/:id πŸ”’

// Response 200
{
  "message": "Task deleted successfully"
}

πŸ“ Project Structure

student-task-manager-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ taskController.js
β”‚   β”‚   └── userController.js
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── authMiddleware.js
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Tasks.js
β”‚   β”‚   └── Users.js
β”‚   └── routes/
β”‚       β”œβ”€β”€ taskRoutes.js
β”‚       └── userRoutes.js
β”œβ”€β”€ server.js
β”œβ”€β”€ package.json
β”œβ”€β”€ .env
└── .gitignore

πŸ—ƒοΈ Data Models

User

Field Type Required Notes
name String βœ…
email String βœ… Unique
password String βœ… Stored hashed
role String βœ… "student" (default) or "admin"
createdAt Date β€” Auto-set
updatedAt Date β€” Auto-set

Task

Field Type Required Notes
title String βœ…
description String βœ…
dueDate Date βœ…
priority Number βœ… 1 = High, 2 = Medium, 3 = Low
status String βœ… "Pending" (default) or "completed"
userId ObjectId βœ… Ref to User β€” auto-set from JWT
createdAt Date β€” Auto-set
updatedAt Date β€” Auto-set

πŸ”’ Authentication Flow

  1. Register via POST /api/v1/user/register β†’ receive JWT token
  2. Login via POST /api/v1/user/login β†’ receive JWT token
  3. Include token in all protected requests:
    Authorization: Bearer <token>
    

About

RESTful API for managing tasks, users, with Node.js, Express, MongoDB, and JWT authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors