Skip to content

amr-94/Evauation

Repository files navigation

🧩 Task Management API

A modular Laravel REST API for managing user tasks with authentication, real-time notifications, and auto-generated API docs.


🚀 Features

  • 🔐 Auth via Laravel Sanctum
  • 📋 Task CRUD (create, list, update, delete)
  • ⚙️ Filtering by status or due date
  • 🔔 Realtime Notifications (Pusher)
  • 🗃️ Stored Notifications in DB
  • 🧪 API Documentation using Scribe
  • 🧰 Queue Support (database / sync)

🧱 Stack

Layer Technology
Framework Laravel 12
Auth Laravel Sanctum
Database MySQL
Realtime Pusher / Laravel WebSockets
Queue Database
Docs Scribe
Tests Pest / PHPUnit

📂 Key Structure

app/
 ├── Http/
 │   ├── Controllers/Api/
 │   │   ├── AuthController.php
 │   │   ├── TaskController.php
 │   │   └── NotificationController.php
 │   ├── Requests/Task/
 │   │   ├── TaskStoreRequest.php
 │   │   └── TaskUpdateRequest.php
 │   └── Resources/TaskResource.php
 ├── Models/Task.php
 ├── Notifications/TaskStatusChanged.php
 ├── Policies/TaskPolicy.php
routes/
 ├── api.php
 └── channels.php

🔐 Auth Endpoints

Register
POST /api/register

{
    "name": "Amr",
    "email": "amr@example.com",
    "password": "password",
    "password_confirmation": "password"
}

Login
POST /api/login

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

Use returned token:
Authorization: Bearer {token}


📋 Tasks API

All endpoints require auth:sanctum.

Method Endpoint Description
GET /api/tasks List tasks (filters: status, due_from, due_to)
POST /api/tasks Create a new task
GET /api/tasks/{id} Show task
PUT /api/tasks/{id} Update task
DELETE /api/tasks/{id} Soft delete
PATCH /api/tasks/{id}/status Update status & trigger notification

Example:

{
    "title": "Finish backend module",
    "description": "Complete Laravel evaluation",
    "due_date": "2025-10-25"
}

🔔 Notifications

Stored in DB + broadcasted in real time.

TaskStatusChanged notification uses:

public function via($notifiable)
{
    return ['database', 'broadcast'];
}

Endpoints

Method Endpoint Description
GET /api/notifications List user notifications
POST /api/notifications/{id}/read Mark as read
POST /api/notifications/read-all Mark all as read

📡 Broadcasting Setup

routes/channels.php

Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

Register with Sanctum auth:

Broadcast::routes(['middleware' => ['auth:sanctum']]);
require base_path('routes/channels.php');

⚙️ .env Essentials

BROADCAST_CONNECTION=pusher

PUSHER_APP_ID=xxxxx
PUSHER_APP_KEY=xxxxx
PUSHER_APP_SECRET=xxxxx
PUSHER_APP_CLUSTER=eu

QUEUE_CONNECTION=database

After updates:

php artisan config:clear && php artisan cache:clear

🧪 Testing & Queues

Use sync for local:

QUEUE_CONNECTION=sync

Run queues:

php artisan queue:work

Run tests:

php artisan test

🧰 Debug Tips

  1. Ensure BROADCAST_CONNECTION=pusher.
  2. Install dependency: composer require pusher/pusher-php-server.
  3. Clear cache: php artisan config:clear.
  4. Run worker if queued: php artisan queue:work.
  5. Test events in Pusher console.

⚙️ Setup Locally

# 1️⃣ Clone the project
git clone https://github.com/yourusername/task-management-api.git

# 2️⃣ Navigate into the project
cd task-management-api

# 3️⃣ Install dependencies
composer install

# 4️⃣ Copy environment file
cp .env.example .env

# 5️⃣ Generate app key
php artisan key:generate

#  for composer
php artisan composer install

# 6️⃣ Configure database in .env
# (update DB_DATABASE, DB_USERNAME, DB_PASSWORD)

# 7️⃣ Run migrations and seed data
php artisan migrate --seed

# 8️⃣ Start the local server
php artisan serve

# 9️⃣ For broadcasting (optional)
php artisan queue:work

📚 API Docs (Scribe)

Install:

composer require --dev knuckleswtf/scribe
php artisan scribe:install

Generate:

php artisan scribe:generate

Visit:

/docs

🧑‍💻 Author

Amr — Laravel Backend Developer
Building maintainable, real-time backend systems ⚡

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages