# Nūr Al-'Ilm — Admin API Documentation

## 🚀 Setup

```bash
cd backend
npm install
node server.js
```

Runs on: **http://localhost:3001**

---

## 🔑 Authentication

All protected endpoints require Bearer token in header:
```
Authorization: Bearer <token>
```

### POST /api/auth/login
```json
{ "email": "admin@nuralilm.id", "password": "admin123" }
```
Returns: `{ token, user }`

### POST /api/auth/logout *(auth)*
### GET  /api/auth/me *(auth)*

---

## 📚 Materi

| Method | Endpoint | Auth Role |
|--------|----------|-----------|
| GET    | /api/materi | Any |
| GET    | /api/materi/stats | Any |
| POST   | /api/materi | Admin/Editor/Ustadz |
| PUT    | /api/materi/:id | Admin/Editor/Ustadz |
| DELETE | /api/materi/:id | Admin/Editor |

**Query params (GET):** `page, limit, search, jenis, status, kategori`

---

## 📜 Risalah Jumat

| Method | Endpoint |
|--------|----------|
| GET    | /api/risalah |
| POST   | /api/risalah |
| PUT    | /api/risalah/:id |
| DELETE | /api/risalah/:id |

---

## 📰 Berita

| Method | Endpoint |
|--------|----------|
| GET    | /api/berita |
| POST   | /api/berita |
| PUT    | /api/berita/:id |
| DELETE | /api/berita/:id |

---

## 🖼️ Galeri

| Method | Endpoint |
|--------|----------|
| GET    | /api/galeri |
| POST   | /api/galeri *(multipart/form-data)* |
| DELETE | /api/galeri/:id |

---

## 💬 Konsultasi

| Method | Endpoint | Notes |
|--------|----------|-------|
| GET    | /api/konsultasi | Admin only |
| GET    | /api/konsultasi/pending-count | |
| POST   | /api/konsultasi | **Public** |
| POST   | /api/konsultasi/:id/reply | Admin/Ustadz |
| PATCH  | /api/konsultasi/:id/status | Admin/Ustadz |

---

## 📧 Newsletter

| Method | Endpoint |
|--------|----------|
| GET    | /api/newsletter |
| POST   | /api/newsletter *(Public)* |
| DELETE | /api/newsletter/:id |

---

## 💰 Donasi

| Method | Endpoint |
|--------|----------|
| GET    | /api/donasi |
| POST   | /api/donasi *(Public)* |
| PATCH  | /api/donasi/:id/status |

---

## 📅 Program

| Method | Endpoint |
|--------|----------|
| GET    | /api/program |
| POST   | /api/program |
| PUT    | /api/program/:id |
| DELETE | /api/program/:id |

---

## 👥 Users *(Admin only)*

| Method | Endpoint |
|--------|----------|
| GET    | /api/users |
| POST   | /api/users |
| PUT    | /api/users/:id |
| DELETE | /api/users/:id |

---

## ⚙️ Settings

| Method | Endpoint |
|--------|----------|
| GET    | /api/settings |
| PUT    | /api/settings *(Admin)* |

---

## 📋 Logs *(Admin only)*

| Method | Endpoint |
|--------|----------|
| GET    | /api/logs |
| DELETE | /api/logs |

---

## 📊 Dashboard

```
GET /api/dashboard/stats
```

---

## 📤 File Upload

```
POST /api/upload
Content-Type: multipart/form-data
Body: file (image/pdf, max 5MB)
```

---

## 🏥 Health Check

```
GET /api/health
```

---

## Roles

| Role | Permissions |
|------|------------|
| Admin | Full access |
| Ustadz | Materi, Risalah, Konsultasi reply |
| Editor | Materi, Berita, Program (no delete) |
| Viewer | Read-only |
