Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Donation Redistribution Application (DRA) - Laravel API

A Laravel 11 RESTful API backend for connecting food donors (supermarkets, restaurants) with receivers (charities, orphanages, low-income families) to minimize food waste and fight hunger in Uganda.

πŸš€ Features

  • Laravel Passport Authentication - OAuth2-based API authentication
  • Role-Based Access Control - Donor, Receiver, and Admin and (Donor-Receiver) roles
  • Donation Management - Create, update, and manage food donations
  • Claiming System - Receivers can claim donations with approval workflow
  • Location-Based Matching - Find nearby donations using geo-filtering (surplus to requirements)
  • Campaign Management - Create and manage awareness campaigns (removed)
  • Admin Analytics - Reports and statistics for monitoring activities

πŸ“‹ Requirements

  • PHP 8.2+
  • Composer
  • MySQL or PostgreSQL (SQLite for development)
  • Laravel 11

πŸ”§ Installation

  1. Clone the repository
git clone https://github.com/IsaacJM03/Year-3-Capstone-Project.git
cd Year-3-Capstone-Project
  1. Install dependencies
composer install
  1. Configure environment
cp .env.example .env
php artisan key:generate
  1. Configure database Edit .env file with your database credentials:
DB_CONNECTION=sqlite
# Or for MySQL/PostgreSQL
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=dra
# DB_USERNAME=root
# DB_PASSWORD=
  1. Run migrations
php artisan migrate
  1. Install Passport
php artisan passport:keys
php artisan passport:client --personal --name="DRA Personal Access Client"
  1. Seed the database (optional)
php artisan db:seed

This will create:

  • 1 admin user
  • 3 donor users
  • 3 receiver users
  • 5 sample donations
  • 2 sample campaigns

πŸ” Test Accounts

After seeding, you can use these accounts:

Admin:

Donors:

Receivers:

πŸ“š API Documentation

Base URL

http://localhost:8000/api/v1

Authentication Endpoints

Register

POST /api/v1/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123",
  "role": "donor",
  "phone": "0700000000",
  "address": "Kampala, Uganda",
  "organization": "Supermarket Ltd"
}

Login

POST /api/v1/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "password123"
}

Get User

GET /api/v1/user
Authorization: Bearer {token}

Logout

POST /api/v1/logout
Authorization: Bearer {token}

Donation Endpoints

Create Donation (Donor only)

POST /api/v1/donations
Authorization: Bearer {token}
Content-Type: application/json

{
  "title": "Fresh Bread",
  "description": "End of day bread and pastries",
  "category": "Bakery",
  "quantity": 50,
  "unit": "packs",
  "expiry_date": "2025-10-20",
  "pickup_location": "Kampala Road, Kampala",
  "latitude": 0.3476,
  "longitude": 32.5825,
  "image_url": "https://example.com/image.jpg"
}

List Donations

GET /api/v1/donations
Authorization: Bearer {token}

Get Donation Details

GET /api/v1/donations/{id}
Authorization: Bearer {token}

Update Donation (Donor only)

PUT /api/v1/donations/{id}
Authorization: Bearer {token}
Content-Type: application/json

{
  "status": "available",
  "quantity": 40
}

Delete Donation (Donor or Admin)

DELETE /api/v1/donations/{id}
Authorization: Bearer {token}

Get Nearby Donations

GET /api/v1/donations/nearby?lat=0.3476&lng=32.5825&radius=5
Authorization: Bearer {token}

Claim Endpoints

Create Claim (Receiver only)

POST /api/v1/claims
Authorization: Bearer {token}
Content-Type: application/json

{
  "donation_id": 1,
  "pickup_time": "2025-10-15 14:00:00",
  "notes": "Will pick up in the afternoon"
}

List Claims

GET /api/v1/claims
Authorization: Bearer {token}

Approve Claim (Donor or Admin)

PUT /api/v1/claims/{id}/approve
Authorization: Bearer {token}

Mark as Delivered (Donor or Admin)

PUT /api/v1/claims/{id}/deliver
Authorization: Bearer {token}

Campaign Endpoints

Create Campaign

POST /api/v1/campaigns
Authorization: Bearer {token}
Content-Type: application/json

{
  "title": "Feed 100 Families",
  "description": "Help us raise funds to feed 100 families",
  "goal_amount": 5000,
  "deadline": "2025-12-31"
}

List Campaigns

GET /api/v1/campaigns
Authorization: Bearer {token}

Get Campaign Details

GET /api/v1/campaigns/{id}
Authorization: Bearer {token}

Donate to Campaign

POST /api/v1/campaigns/{id}/donate
Authorization: Bearer {token}
Content-Type: application/json

{
  "amount": 100
}

Admin Endpoints

Get Summary Statistics

GET /api/v1/admin/reports/summary
Authorization: Bearer {admin-token}

Get Donations Per Category

GET /api/v1/admin/reports/donations-per-category
Authorization: Bearer {admin-token}

πŸ”„ Response Format

All API responses follow this standard format:

{
  "success": true,
  "message": "Operation successful",
  "data": {}
}

πŸ§ͺ Testing

Run the test suite:

php artisan test

Run specific tests:

php artisan test --filter AuthenticationTest
php artisan test --filter DonationTest

πŸ—οΈ Project Structure

app/
β”œβ”€β”€ Http/
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   └── API/
β”‚   β”‚       └── V1/
β”‚   β”‚           β”œβ”€β”€ AuthController.php
β”‚   β”‚           β”œβ”€β”€ DonationController.php
β”‚   β”‚           β”œβ”€β”€ ClaimController.php
β”‚   β”‚           β”œβ”€β”€ CampaignController.php
β”‚   β”‚           └── AdminController.php
β”‚   β”œβ”€β”€ Middleware/
β”‚   β”‚   └── AdminMiddleware.php
β”‚   β”œβ”€β”€ Requests/
β”‚   └── Resources/
β”œβ”€β”€ Models/
β”‚   β”œβ”€β”€ User.php
β”‚   β”œβ”€β”€ Donation.php
β”‚   β”œβ”€β”€ DonationClaim.php
β”‚   └── Campaign.php
database/
β”œβ”€β”€ factories/
β”‚   β”œβ”€β”€ UserFactory.php
β”‚   β”œβ”€β”€ DonationFactory.php
β”‚   β”œβ”€β”€ DonationClaimFactory.php
β”‚   └── CampaignFactory.php
β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ *_create_users_table.php
β”‚   β”œβ”€β”€ *_add_role_and_fields_to_users_table.php
β”‚   β”œβ”€β”€ *_create_donations_table.php
β”‚   β”œβ”€β”€ *_create_donation_claims_table.php
β”‚   └── *_create_campaigns_table.php
└── seeders/
    └── DatabaseSeeder.php
routes/
└── api.php
tests/
β”œβ”€β”€ Feature/
β”‚   β”œβ”€β”€ AuthenticationTest.php
β”‚   └── DonationTest.php
└── Unit/

πŸ› οΈ Tech Stack

  • Framework: Laravel 11
  • Authentication: Laravel Passport (OAuth2)
  • Database: MySQL/PostgreSQL/SQLite
  • ORM: Eloquent
  • Testing: PHPUnit
  • API: RESTful with JSON responses

πŸ“ Database Schema

Users

  • id, name, email, password
  • role (donor, receiver, admin)
  • phone, address, organization
  • verified (boolean)

Donations

  • id, donor_id, title, description
  • category, quantity, unit
  • expiry_date, status
  • pickup_location, latitude, longitude
  • image_url

Donation Claims

  • id, donation_id, receiver_id
  • claim_status (pending, approved, rejected, delivered)
  • pickup_time, notes

Campaigns

  • id, title, description, creator_id
  • goal_amount, raised_amount
  • deadline, status

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“„ License

This project is open-source and available under the MIT License.

πŸ™‹β€β™‚οΈ Support

For support, email support@dra.com or create an issue in the repository.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages