# SMART FOOD ORDERING SYSTEM - API DOCUMENTATION ## Base URL ``` http://localhost/food/api/ ``` --- ## Authentication APIs ### 1. User Login **Endpoint**: `POST /api/login.php` **Request Body**: ```json { "email": "user@example.com", "password": "password123" } ``` **Success Response** (200): ```json { "success": true, "message": "Login successful", "data": { "user": { "id": 1, "full_name": "John Doe", "email": "user@example.com", "phone": "+63 912 345 6789", "address": "123 Street, City", "status": "active" }, "token": "abc123xyz789" } } ``` **Error Response** (200): ```json { "success": false, "message": "Invalid email or password" } ``` --- ### 2. User Registration **Endpoint**: `POST /api/register.php` **Request Body**: ```json { "full_name": "John Doe", "email": "user@example.com", "phone": "+63 912 345 6789", "password": "password123", "address": "123 Street, City" } ``` **Success Response** (200): ```json { "success": true, "message": "Registration successful", "data": { "user_id": 1, "full_name": "John Doe", "email": "user@example.com", "phone": "+63 912 345 6789" } } ``` --- ## Category APIs ### 3. Fetch Categories **Endpoint**: `GET /api/categories.php` **Success Response** (200): ```json { "success": true, "message": "Categories fetched successfully", "data": [ { "id": "1", "name": "Burgers", "description": "Delicious burgers", "image": "burger.jpg", "image_url": "http://localhost/food/uploads/categories/burger.jpg", "icon": "🍔", "display_order": "1", "status": "active" } ] } ``` --- ## Food APIs ### 4. Fetch Foods **Endpoint**: `GET /api/foods.php` **Query Parameters**: - `category_id` (optional): Filter by category - `is_featured` (optional): Filter featured foods - `search` (optional): Search by name or description **Example**: `GET /api/foods.php?category_id=1&is_featured=1` **Success Response** (200): ```json { "success": true, "message": "Foods fetched successfully", "data": [ { "id": "1", "category_id": "1", "name": "Classic Cheeseburger", "description": "Juicy beef patty with cheese", "price": "199.00", "image": "burger1.jpg", "image_url": "http://localhost/food/uploads/foods/burger1.jpg", "is_featured": "1", "is_available": "1", "preparation_time": "15", "calories": "650", "rating": "4.50", "total_reviews": "25", "category_name": "Burgers" } ] } ``` --- ### 5. Fetch Food Details **Endpoint**: `GET /api/food_details.php?id={food_id}` **Success Response** (200): ```json { "success": true, "message": "Food details fetched successfully", "data": { "id": "1", "name": "Classic Cheeseburger", "description": "Juicy beef patty with cheese", "price": "199.00", "image_url": "http://localhost/food/uploads/foods/burger1.jpg", "preparation_time": "15", "calories": "650", "rating": "4.50", "category_name": "Burgers", "reviews": [ { "id": "1", "rating": "5", "comment": "Delicious!", "full_name": "Jane Doe", "created_at": "2024-01-15 10:30:00" } ] } } ``` --- ## Cart APIs ### 6. Fetch Cart **Endpoint**: `GET /api/cart.php?user_id={user_id}` **Success Response** (200): ```json { "success": true, "message": "Cart fetched successfully", "data": [ { "id": "1", "user_id": "1", "food_id": "1", "name": "Classic Cheeseburger", "price": "199.00", "image_url": "http://localhost/food/uploads/foods/burger1.jpg", "quantity": "2", "subtotal": 398.00, "is_available": "1" } ] } ``` --- ### 7. Add to Cart **Endpoint**: `POST /api/cart.php` **Request Body**: ```json { "user_id": 1, "food_id": 1, "quantity": 2, "special_instructions": "No onions" } ``` **Success Response** (200): ```json { "success": true, "message": "Item added to cart successfully" } ``` --- ### 8. Update Cart **Endpoint**: `PUT /api/cart.php` **Request Body**: ```json { "cart_id": 1, "quantity": 3 } ``` **Success Response** (200): ```json { "success": true, "message": "Cart updated successfully" } ``` --- ### 9. Remove from Cart **Endpoint**: `DELETE /api/cart.php?cart_id={cart_id}` **Success Response** (200): ```json { "success": true, "message": "Item removed from cart" } ``` --- ## Order APIs ### 10. Place Order **Endpoint**: `POST /api/place_order.php` **Request Body**: ```json { "user_id": 1, "delivery_address": "123 Street, City", "delivery_phone": "+63 912 345 6789", "payment_method": "cash_on_delivery", "notes": "Please ring the doorbell", "items": [ { "food_id": 1, "name": "Classic Cheeseburger", "price": 199.00, "quantity": 2, "special_instructions": "No onions" } ] } ``` **Success Response** (200): ```json { "success": true, "message": "Order placed successfully", "data": { "order_id": 1, "order_number": "ORD-20240115-ABC123", "total_amount": 448.00 } } ``` --- ### 11. Fetch Orders **Endpoint**: `GET /api/orders.php?user_id={user_id}&status={status}` **Query Parameters**: - `user_id` (required): User ID - `status` (optional): Filter by order status **Success Response** (200): ```json { "success": true, "message": "Orders fetched successfully", "data": [ { "id": "1", "order_number": "ORD-20240115-ABC123", "user_id": "1", "delivery_address": "123 Street, City", "delivery_phone": "+63 912 345 6789", "subtotal": "398.00", "delivery_fee": "50.00", "discount": "0.00", "total_amount": "448.00", "payment_method": "cash_on_delivery", "payment_status": "unpaid", "order_status": "pending", "created_at": "2024-01-15 10:30:00", "items": [ { "id": "1", "food_name": "Classic Cheeseburger", "food_price": "199.00", "quantity": "2", "subtotal": "398.00", "image_url": "http://localhost/food/uploads/foods/burger1.jpg" } ] } ] } ``` --- ### 12. Fetch Order Details **Endpoint**: `GET /api/order_details.php?order_id={order_id}` **Success Response** (200): ```json { "success": true, "message": "Order details fetched successfully", "data": { "id": "1", "order_number": "ORD-20240115-ABC123", "full_name": "John Doe", "email": "user@example.com", "delivery_address": "123 Street, City", "delivery_phone": "+63 912 345 6789", "total_amount": "448.00", "order_status": "preparing", "items": [...], "status_history": [ { "status": "pending", "created_at": "2024-01-15 10:30:00" }, { "status": "accepted", "created_at": "2024-01-15 10:35:00" }, { "status": "preparing", "created_at": "2024-01-15 10:40:00" } ] } } ``` --- ## Profile APIs ### 13. Update Profile **Endpoint**: `POST /api/update_profile.php` **Request Body**: ```json { "user_id": 1, "full_name": "John Doe Updated", "phone": "+63 912 345 6789", "address": "456 New Street, City" } ``` **Success Response** (200): ```json { "success": true, "message": "Profile updated successfully", "data": { "id": "1", "full_name": "John Doe Updated", "email": "user@example.com", "phone": "+63 912 345 6789", "address": "456 New Street, City", "status": "active" } } ``` --- ## Notification APIs ### 14. Fetch Notifications **Endpoint**: `GET /api/notifications.php?user_id={user_id}` **Success Response** (200): ```json { "success": true, "message": "Notifications fetched successfully", "data": [ { "id": "1", "title": "Order Placed Successfully", "message": "Your order ORD-20240115-ABC123 has been placed", "type": "order", "reference_id": "1", "is_read": "0", "created_at": "2024-01-15 10:30:00" } ] } ``` --- ## Promo APIs ### 15. Fetch Promos **Endpoint**: `GET /api/promos.php` **Success Response** (200): ```json { "success": true, "message": "Promos fetched successfully", "data": [ { "id": "1", "title": "New Year Sale", "description": "Get 20% off on all orders", "image_url": "http://localhost/food/uploads/promos/promo1.jpg", "discount_type": "percentage", "discount_value": "20.00", "promo_code": "NEWYEAR2024", "start_date": "2024-01-01 00:00:00", "end_date": "2024-01-31 23:59:59", "status": "active" } ] } ``` --- ## Settings APIs ### 16. Fetch Settings **Endpoint**: `GET /api/settings.php` **Success Response** (200): ```json { "success": true, "message": "Settings fetched successfully", "data": { "restaurant_name": "Smart Food Restaurant", "contact_number": "+63 912 345 6789", "email": "info@smartfood.com", "address": "123 Food Street, Manila", "opening_time": "08:00", "closing_time": "22:00", "delivery_fee": "50.00", "min_order_amount": "100.00", "currency": "PHP" } } ``` --- ## Error Responses All endpoints return consistent error responses: ```json { "success": false, "message": "Error description here" } ``` Common HTTP Status Codes: - `200` - Success - `400` - Bad Request - `401` - Unauthorized - `404` - Not Found - `500` - Server Error --- ## Order Status Values - `pending` - Order placed, waiting for acceptance - `accepted` - Order accepted by restaurant - `preparing` - Food is being prepared - `ready_for_pickup` - Order ready for pickup - `out_for_delivery` - Order is being delivered - `completed` - Order delivered successfully - `cancelled` - Order cancelled --- ## Payment Methods - `cash_on_delivery` - Cash on Delivery - `gcash` - GCash Payment - `card` - Credit/Debit Card --- ## Payment Status - `unpaid` - Payment not received - `paid` - Payment received - `failed` - Payment failed - `refunded` - Payment refunded --- **API Version**: 1.0.0 **Last Updated**: 2024