# Article API

## Create Article

`POST /api/article`

Create a new article.

### Headers
- `Authorization: Bearer <token>`
- `Content-Type: multipart/form-data`

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| title | string | Yes | Article title |
| content | string | Yes | Article body content |
| date | string (ISO 8601) | Yes | Publication date (e.g. `"2026-07-02"` or `"2026-07-02T10:00:00Z"`) |
| category | string | Yes | Must be either `"activity"` or `"event"` |
| images | file[] | No | Upload images (max 10 files, allowed: png, avif, webp, jpg, jpeg, gif, mp4, mp3, mov, pdf, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip. Max 10MB each) |
| isActive | boolean | No | Visibility on website (default: true) |

### Response

```json
{
  "message": "Article create success",
  "success": true,
  "data": {
    "_id": "...",
    "title": "Community Dental Camp 2026",
    "content": "We organized a free dental checkup camp...",
    "date": "2026-07-02T00:00:00.000Z",
    "category": "event",
    "imageUrls": ["https://cherryk.s3.ap-southeast-1.amazonaws.com/Article/Images/1687154298_photo.jpg"],
    "isActive": true,
    "isDeleted": false,
    "createdAt": "...",
    "updatedAt": "..."
  }
}
```

---

## Get Article

`GET /api/article/:id`

Retrieve a single article.

### Headers
- `Authorization: Bearer <token>`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Response

```json
{
  "success": true,
  "data": { "...": "..." }
}
```

### Errors
- `404` — Article not found

---

## Update Article

`PUT /api/article/:id`

Update an existing article.

### Headers
- `Authorization: Bearer <token>`
- `Content-Type: multipart/form-data`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| title | string | No | Article title |
| content | string | No | Article body content |
| date | string (ISO 8601) | No | Publication date |
| category | string | No | Must be either `"activity"` or `"event"` |
| existingImageUrls | string[] | No | URLs of images to keep from the current set |
| images | file[] | No | Upload new images (max 10 files, allowed: png, avif, webp, jpg, jpeg, gif, mp4, mp3, mov, pdf, doc, docx, xls, xlsx, ppt, pptx, txt, csv, zip. Max 10MB each) |
| isActive | boolean | No | Visibility on website |

> **Image management:** Send `existingImageUrls` with URLs you want to keep. Upload new files via `images` field to add more. Omit a URL from `existingImageUrls` to remove that image (also deletes it from S3).

### Errors
- `404` — Article not found

---

## Delete Article (Soft Delete)

`DELETE /api/article/:id`

Soft-delete an article (sets `isDeleted` to `true`). Also deletes associated images from S3.

### Headers
- `Authorization: Bearer <token>`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Response

```json
{
  "success": true,
  "data": { "isDeleted": true }
}
```

### Errors
- `404` — Article not found

---

## Activate Article

`POST /api/article/:id`

Restore a soft-deleted article (sets `isDeleted` to `false`).

### Headers
- `Authorization: Bearer <token>`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Response

```json
{
  "success": true,
  "data": { "isDeleted": false }
}
```

### Errors
- `404` — Article not found

---

## Activate Article (Visibility)

`POST /api/article/:id/activate`

Set an article's `isActive` to `true` (show on website).

### Headers
- `Authorization: Bearer <token>`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Response

```json
{
  "success": true,
  "data": { "isActive": true }
}
```

### Errors
- `404` — Article not found

---

## Deactivate Article (Visibility)

`POST /api/article/:id/deactivate`

Set an article's `isActive` to `false` (hide from website).

### Headers
- `Authorization: Bearer <token>`

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Article MongoId |

### Response

```json
{
  "success": true,
  "data": { "isActive": false }
}
```

### Errors
- `404` — Article not found

---

## List All Articles (Paginated)

`GET /api/articles`

Get a paginated list of active (non-deleted) articles.

### Headers
- `Authorization: Bearer <token>`

### Query Parameters

| Param | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| keyword | string | No | — | Search by title or content (case-insensitive) |
| category | string | No | — | Filter by category (`"activity"` or `"event"`) |
| isActive | boolean | No | — | Filter by website visibility |
| limit | int | No | 10 | Items per page (max 100) |
| page | int | No | 1 | Page number (starts at 1) |

Results are sorted by `date` descending.

### Response

```json
{
  "success": true,
  "count": 0,
  "_metadata": {
    "current_page": 1,
    "per_page": 10,
    "page_count": 0,
    "total_count": 0
  },
  "list": []
}
```

---

## List Website Articles (Public)

`GET /api/website/articles`

Public endpoint for the Cherry-K website. Returns all active articles (no auth, no pagination).

### Query Parameters

| Param | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| category | string | No | — | Filter by category (`"activity"` or `"event"`) |

### Response

```json
{
  "success": true,
  "data": [
    {
      "_id": "...",
      "title": "Community Dental Camp 2026",
      "content": "We organized a free dental checkup camp...",
      "date": "2026-07-02T00:00:00.000Z",
      "category": "event",
      "imageUrls": ["https://cherryk.s3.ap-southeast-1.amazonaws.com/Article/Images/1687154298_photo.jpg"],
      "isActive": true,
      "isDeleted": false,
      "createdAt": "...",
      "updatedAt": "..."
    }
  ]
}
```

### Errors
- `404` — No articles found

Filters: `isDeleted: false`, `isActive: true`. Sorted by `date` descending.
