# Postman Test Cases - Dental Clinic Backend API

**Base URL:** `http://localhost:5000/api`

---

## Table of Contents

1. [Authentication Endpoints](#authentication-endpoints)
2. [Appointment Endpoints](#appointment-endpoints)
3. [Blog Endpoints](#blog-endpoints)
4. [Service Endpoints](#service-endpoints)
5. [Doctor Endpoints](#doctor-endpoints)
6. [Contact Endpoints](#contact-endpoints)
7. [Gallery Endpoints](#gallery-endpoints)

---

## Authentication Endpoints

### 1. Register Admin User

**Method:** `POST`  
**URL:** `http://localhost:5000/api/auth/register`  
**Headers:**
```
Content-Type: application/json
```

**Body (JSON):**
```json
{
  "username": "admin",
  "email": "admin@dentalclinic.com",
  "password": "admin123"
}
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "User registered successfully",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "username": "admin",
    "email": "admin@dentalclinic.com"
  }
}
```

**Notes:**
- Save the `token` from response for use in other requests
- Password must be at least 6 characters
- Username and email must be unique

---

### 2. Login Admin User

**Method:** `POST`  
**URL:** `http://localhost:5000/api/auth/login`  
**Headers:**
```
Content-Type: application/json
```

**Body (JSON):**
```json
{
  "email": "admin@dentalclinic.com",
  "password": "admin123"
}
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "username": "admin",
    "email": "admin@dentalclinic.com"
  }
}
```

**Notes:**
- Save the `token` for authenticated requests
- Use this token in Authorization header for admin endpoints

---

## Appointment Endpoints

### 3. Book Appointment (Public)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/appointments`  
**Headers:**
```
Content-Type: application/json
```

**Body (JSON):**
```json
{
  "patient_name": "John Doe",
  "phone": "1234567890",
  "email": "john@example.com",
  "service_id": 1,
  "preferred_date": "2024-12-25",
  "preferred_time": "10:00"
}
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Appointment booked successfully",
  "data": {
    "id": 1,
    "patient_name": "John Doe",
    "phone": "1234567890",
    "email": "john@example.com",
    "service_id": 1,
    "preferred_date": "2024-12-25",
    "preferred_time": "10:00:00",
    "status": "pending",
    "created_at": "2024-12-20T10:00:00.000Z",
    "service": {
      "id": 1,
      "name": "Teeth Cleaning"
    }
  }
}
```

**Notes:**
- No authentication required (public endpoint)
- `patient_name` and `phone` are required
- `service_id`, `preferred_date`, and `preferred_time` are optional
- Date format: YYYY-MM-DD
- Time format: HH:MM (24-hour format)

---

### 4. Get All Appointments (Admin)

**Method:** `GET`  
**URL:** `http://localhost:5000/api/appointments`  
**Query Parameters (Optional):**
- `status`: pending | confirmed | completed
- `page`: 1 (default)
- `limit`: 10 (default)

**Example:** `http://localhost:5000/api/appointments?status=pending&page=1&limit=10`

**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "patient_name": "John Doe",
      "phone": "1234567890",
      "email": "john@example.com",
      "service_id": 1,
      "preferred_date": "2024-12-25",
      "preferred_time": "10:00:00",
      "status": "pending",
      "created_at": "2024-12-20T10:00:00.000Z",
      "service": {
        "id": 1,
        "name": "Teeth Cleaning",
        "description": "Professional teeth cleaning"
      }
    }
  ],
  "pagination": {
    "total": 1,
    "page": 1,
    "limit": 10,
    "pages": 1
  }
}
```

**Notes:**
- Requires authentication
- Returns paginated results

---

### 5. Get Appointment by ID (Admin)

**Method:** `GET`  
**URL:** `http://localhost:5000/api/appointments/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "data": {
    "id": 1,
    "patient_name": "John Doe",
    "phone": "1234567890",
    "email": "john@example.com",
    "service_id": 1,
    "preferred_date": "2024-12-25",
    "preferred_time": "10:00:00",
    "status": "pending",
    "created_at": "2024-12-20T10:00:00.000Z",
    "service": {
      "id": 1,
      "name": "Teeth Cleaning",
      "description": "Professional teeth cleaning",
      "image_url": "/api/uploads/services/image.jpg"
    }
  }
}
```

---

### 6. Update Appointment Status (Admin)

**Method:** `PATCH`  
**URL:** `http://localhost:5000/api/appointments/1/status`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json
```

**Body (JSON):**
```json
{
  "status": "confirmed"
}
```

**Valid Status Values:**
- `pending`
- `confirmed`
- `completed`

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Appointment status updated successfully",
  "data": {
    "id": 1,
    "patient_name": "John Doe",
    "status": "confirmed",
    ...
  }
}
```

---

## Blog Endpoints

### 7. Create Blog Post (Admin)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/blogs`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
title: How to Maintain Good Oral Health
excerpt: Learn the basics of maintaining healthy teeth and gums
content: Full blog content here... This is a comprehensive guide...
author_name: Dr. Jane Smith
category: Dental Health
status: published
image: [Select File] (optional - choose an image file)
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Blog post created successfully",
  "data": {
    "id": 1,
    "title": "How to Maintain Good Oral Health",
    "slug": "how-to-maintain-good-oral-health",
    "excerpt": "Learn the basics...",
    "content": "Full blog content here...",
    "author_name": "Dr. Jane Smith",
    "category": "Dental Health",
    "image_url": "/api/uploads/blogs/image-1234567890-987654321.jpg",
    "published_at": "2024-12-20T10:00:00.000Z",
    "status": "published"
  }
}
```

**Notes:**
- Image is optional
- Status can be `draft` or `published`
- Slug is auto-generated from title
- If status is `published`, `published_at` is automatically set

---

### 8. Get All Blogs

**Method:** `GET`  
**URL:** `http://localhost:5000/api/blogs`  
**Query Parameters (Optional):**
- `page`: 1 (default)
- `limit`: 10 (default)
- `status`: draft | published (admin only)
- `category`: Filter by category name

**Example:** `http://localhost:5000/api/blogs?category=Dental Health&page=1&limit=10`

**Headers:**
- Public: No headers needed (returns only published blogs)
- Admin: `Authorization: Bearer YOUR_JWT_TOKEN` (returns all blogs)

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "title": "How to Maintain Good Oral Health",
      "slug": "how-to-maintain-good-oral-health",
      "excerpt": "Learn the basics...",
      "image_url": "/api/uploads/blogs/image.jpg",
      "author_name": "Dr. Jane Smith",
      "category": "Dental Health",
      "published_at": "2024-12-20T10:00:00.000Z",
      "status": "published"
    }
  ],
  "pagination": {
    "total": 1,
    "page": 1,
    "limit": 10,
    "pages": 1
  }
}
```

---

### 9. Get Blog by Slug (Public)

**Method:** `GET`  
**URL:** `http://localhost:5000/api/blogs/how-to-maintain-good-oral-health`  
**Headers:** None required

**Expected Response (200):**
```json
{
  "success": true,
  "data": {
    "id": 1,
    "title": "How to Maintain Good Oral Health",
    "slug": "how-to-maintain-good-oral-health",
    "excerpt": "Learn the basics...",
    "content": "Full blog content here...",
    "image_url": "/api/uploads/blogs/image.jpg",
    "author_name": "Dr. Jane Smith",
    "category": "Dental Health",
    "published_at": "2024-12-20T10:00:00.000Z",
    "status": "published"
  }
}
```

**Notes:**
- Returns 404 if blog is not published (for non-admin users)
- Use the slug from the blog title

---

### 10. Update Blog Post (Admin)

**Method:** `PUT`  
**URL:** `http://localhost:5000/api/blogs/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
title: Updated Blog Title (optional)
excerpt: Updated excerpt (optional)
content: Updated content (optional)
author_name: Updated Author (optional)
category: Updated Category (optional)
status: published (optional)
published_at: 2024-12-25T10:00:00.000Z (optional)
image: [Select File] (optional - new image to replace old one)
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Blog post updated successfully",
  "data": {
    "id": 1,
    "title": "Updated Blog Title",
    ...
  }
}
```

**Notes:**
- Only include fields you want to update
- If you upload a new image, the old image is automatically deleted
- If title changes, slug is regenerated

---

### 11. Delete Blog Post (Admin)

**Method:** `DELETE`  
**URL:** `http://localhost:5000/api/blogs/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Blog post deleted successfully"
}
```

**Notes:**
- Deletes the blog post and its associated image file

---

## Service Endpoints

### 12. Create Service (Admin)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/services`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
name: Teeth Cleaning
description: Professional teeth cleaning and polishing service
is_active: true
image: [Select File] (optional)
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Service created successfully",
  "data": {
    "id": 1,
    "name": "Teeth Cleaning",
    "description": "Professional teeth cleaning and polishing service",
    "image_url": "/api/uploads/services/image-1234567890.jpg",
    "is_active": true,
    "created_at": "2024-12-20T10:00:00.000Z"
  }
}
```

---

### 13. Get All Services

**Method:** `GET`  
**URL:** `http://localhost:5000/api/services`  
**Headers:**
- Public: No headers (returns only active services)
- Admin: `Authorization: Bearer YOUR_JWT_TOKEN` (returns all services)

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "name": "Teeth Cleaning",
      "description": "Professional teeth cleaning",
      "image_url": "/api/uploads/services/image.jpg",
      "is_active": true,
      "created_at": "2024-12-20T10:00:00.000Z"
    }
  ]
}
```

---

### 14. Get Service by ID

**Method:** `GET`  
**URL:** `http://localhost:5000/api/services/1`  
**Headers:** Optional (for admin to see inactive services)

**Expected Response (200):**
```json
{
  "success": true,
  "data": {
    "id": 1,
    "name": "Teeth Cleaning",
    "description": "Professional teeth cleaning",
    "image_url": "/api/uploads/services/image.jpg",
    "is_active": true,
    "created_at": "2024-12-20T10:00:00.000Z"
  }
}
```

---

### 15. Update Service (Admin)

**Method:** `PUT`  
**URL:** `http://localhost:5000/api/services/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
name: Updated Service Name (optional)
description: Updated description (optional)
is_active: false (optional)
image: [Select File] (optional - new image)
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Service updated successfully",
  "data": {
    "id": 1,
    "name": "Updated Service Name",
    ...
  }
}
```

---

### 16. Delete Service (Admin)

**Method:** `DELETE`  
**URL:** `http://localhost:5000/api/services/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Service deleted successfully"
}
```

---

## Doctor Endpoints

### 17. Create Doctor Profile (Admin)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/doctors`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
name: Dr. Jane Smith
title: DDS
specialty: Orthodontics
biography: Dr. Jane Smith has over 10 years of experience...
email: jane.smith@dentalclinic.com
phone: 1234567890
experience_years: 10
is_active: true
image: [Select File] (optional - doctor photo)
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Doctor profile created successfully",
  "data": {
    "id": 1,
    "name": "Dr. Jane Smith",
    "title": "DDS",
    "specialty": "Orthodontics",
    "biography": "Dr. Jane Smith has over 10 years...",
    "photo_url": "/api/uploads/doctors/image-1234567890.jpg",
    "email": "jane.smith@dentalclinic.com",
    "phone": "1234567890",
    "experience_years": 10,
    "is_active": true
  }
}
```

---

### 18. Get All Doctors

**Method:** `GET`  
**URL:** `http://localhost:5000/api/doctors`  
**Headers:**
- Public: No headers (returns only active doctors)
- Admin: `Authorization: Bearer YOUR_JWT_TOKEN` (returns all doctors)

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "name": "Dr. Jane Smith",
      "title": "DDS",
      "specialty": "Orthodontics",
      "biography": "...",
      "photo_url": "/api/uploads/doctors/image.jpg",
      "email": "jane.smith@dentalclinic.com",
      "phone": "1234567890",
      "experience_years": 10,
      "is_active": true
    }
  ]
}
```

---

### 19. Get Doctor by ID

**Method:** `GET`  
**URL:** `http://localhost:5000/api/doctors/1`  
**Headers:** Optional (for admin to see inactive doctors)

**Expected Response (200):**
```json
{
  "success": true,
  "data": {
    "id": 1,
    "name": "Dr. Jane Smith",
    ...
  }
}
```

---

### 20. Update Doctor (Admin)

**Method:** `PUT`  
**URL:** `http://localhost:5000/api/doctors/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
name: Dr. Jane Smith Updated (optional)
title: DDS, MS (optional)
specialty: Updated Specialty (optional)
biography: Updated biography (optional)
email: updated@email.com (optional)
phone: 9876543210 (optional)
experience_years: 12 (optional)
is_active: false (optional)
image: [Select File] (optional - new photo)
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Doctor profile updated successfully",
  "data": {
    "id": 1,
    "name": "Dr. Jane Smith Updated",
    ...
  }
}
```

---

### 21. Delete Doctor (Admin)

**Method:** `DELETE`  
**URL:** `http://localhost:5000/api/doctors/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Doctor profile deleted successfully"
}
```

---

## Contact Endpoints

### 22. Submit Contact Message (Public)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/contact`  
**Headers:**
```
Content-Type: application/json
```

**Body (JSON):**
```json
{
  "name": "John Doe",
  "email": "john@example.com",
  "phone": "1234567890",
  "message": "I would like to schedule an appointment for a checkup."
}
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Contact message submitted successfully",
  "data": {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "1234567890",
    "message": "I would like to schedule an appointment...",
    "created_at": "2024-12-20T10:00:00.000Z"
  }
}
```

**Notes:**
- All fields are optional
- No authentication required

---

### 23. Get All Contact Messages (Admin)

**Method:** `GET`  
**URL:** `http://localhost:5000/api/contact`  
**Query Parameters (Optional):**
- `page`: 1 (default)
- `limit`: 10 (default)

**Example:** `http://localhost:5000/api/contact?page=1&limit=10`

**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "name": "John Doe",
      "email": "john@example.com",
      "phone": "1234567890",
      "message": "I would like to schedule...",
      "created_at": "2024-12-20T10:00:00.000Z"
    }
  ],
  "pagination": {
    "total": 1,
    "page": 1,
    "limit": 10,
    "pages": 1
  }
}
```

---

## Gallery Endpoints

### 24. Upload Gallery Image (Admin)

**Method:** `POST`  
**URL:** `http://localhost:5000/api/gallery`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
```

**Body (form-data):**
```
title: Before and After - Teeth Whitening
category: before-after
image: [Select File] (required)
```

**Expected Response (201):**
```json
{
  "success": true,
  "message": "Gallery image uploaded successfully",
  "data": {
    "id": 1,
    "title": "Before and After - Teeth Whitening",
    "image_url": "/api/uploads/gallery/image-1234567890.jpg",
    "category": "before-after",
    "created_at": "2024-12-20T10:00:00.000Z"
  }
}
```

**Notes:**
- Image file is required
- Category is optional but recommended for organization

---

### 25. Get Gallery Images

**Method:** `GET`  
**URL:** `http://localhost:5000/api/gallery`  
**Query Parameters (Optional):**
- `category`: Filter by category (e.g., "before-after")
- `page`: 1 (default)
- `limit`: 20 (default)

**Example:** `http://localhost:5000/api/gallery?category=before-after&page=1&limit=20`

**Headers:** None required

**Expected Response (200):**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "title": "Before and After - Teeth Whitening",
      "image_url": "/api/uploads/gallery/image.jpg",
      "category": "before-after",
      "created_at": "2024-12-20T10:00:00.000Z"
    }
  ],
  "pagination": {
    "total": 1,
    "page": 1,
    "limit": 20,
    "pages": 1
  }
}
```

---

### 26. Delete Gallery Image (Admin)

**Method:** `DELETE`  
**URL:** `http://localhost:5000/api/gallery/1`  
**Headers:**
```
Authorization: Bearer YOUR_JWT_TOKEN
```

**Expected Response (200):**
```json
{
  "success": true,
  "message": "Gallery image deleted successfully"
}
```

---

## Testing Order Recommendation

### Step 1: Setup
1. **Register Admin** (Test Case #1)
2. **Login** (Test Case #2) - Save the token!

### Step 2: Create Resources (Admin)
3. **Create Service** (Test Case #12)
4. **Create Doctor** (Test Case #17)
5. **Create Blog** (Test Case #7)

### Step 3: Test Public Endpoints
6. **Book Appointment** (Test Case #3) - Use service_id from step 3
7. **Get Services** (Test Case #13)
8. **Get Doctors** (Test Case #18)
9. **Get Blogs** (Test Case #8)
10. **Get Blog by Slug** (Test Case #9)
11. **Submit Contact** (Test Case #22)
12. **Get Gallery** (Test Case #25)

### Step 4: Test Admin Management
13. **Get Appointments** (Test Case #4)
14. **Update Appointment Status** (Test Case #6)
15. **Update Blog** (Test Case #10)
16. **Update Service** (Test Case #15)
17. **Update Doctor** (Test Case #20)
18. **Get Contact Messages** (Test Case #23)
19. **Upload Gallery Image** (Test Case #24)

### Step 5: Test Delete Operations
20. **Delete Blog** (Test Case #11)
21. **Delete Service** (Test Case #16)
22. **Delete Doctor** (Test Case #21)
23. **Delete Gallery Image** (Test Case #26)

---

## Common Error Responses

### 400 Bad Request
```json
{
  "success": false,
  "message": "Validation errors",
  "errors": [
    {
      "msg": "Patient name is required",
      "param": "patient_name",
      "location": "body"
    }
  ]
}
```

### 401 Unauthorized
```json
{
  "success": false,
  "message": "No token provided. Authorization denied."
}
```

### 404 Not Found
```json
{
  "success": false,
  "message": "Blog post not found"
}
```

### 500 Server Error
```json
{
  "success": false,
  "message": "Error message here",
  "error": "Detailed error information"
}
```

---

## Postman Collection Setup Tips

1. **Create Environment Variables:**
   - `base_url`: `http://localhost:5000/api`
   - `token`: (will be set after login)

2. **Set Authorization:**
   - Type: Bearer Token
   - Token: `{{token}}`

3. **For Image Uploads:**
   - Change Body type to `form-data`
   - Add key `image` with type `File`
   - Select your image file

4. **Save Responses:**
   - Save IDs from create operations for use in update/delete tests
   - Save tokens from login for authenticated requests

---

## Quick Test Checklist

- [ ] Authentication (Register & Login)
- [ ] Create Resources (Service, Doctor, Blog)
- [ ] Public Endpoints (Appointments, Services, Doctors, Blogs, Contact, Gallery)
- [ ] Admin Endpoints (Get Appointments, Update Status)
- [ ] Update Operations (Blog, Service, Doctor)
- [ ] Delete Operations (Blog, Service, Doctor, Gallery)
- [ ] Image Uploads (Blog, Service, Doctor, Gallery)
- [ ] Pagination (Appointments, Blogs, Contact, Gallery)
- [ ] Filtering (Blogs by category, Gallery by category, Appointments by status)

---

**Happy Testing! 🚀**

