# Blog API

## Create Blog

`POST /api/blog`

Create a new blog post with optional images.

### Headers

| Header | Value |
|--------|-------|
| Content-Type | multipart/form-data |

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| name | string | Yes | Blog title |
| type | string | Yes | Blog type — `face`, `body`, or `dental` |
| datas | string | Yes | JSON array of description objects, e.g. `[{"title":"...","description":"..."}]` |
| blog | file[] | No | Up to 5 images (png, jpg, jpeg, gif, webp, avif). Max 10MB each |

### Response

```json
{
  "success": true,
  "message": "Create Blog Successfully",
  "data": {
    "_id": "...",
    "name": "Dental Tips",
    "type": "dental",
    "image": null,
    "relatedDescription": ["desc1_id", "desc2_id"],
    "isDeleted": false
  }
}
```

### Errors

- `400` — Validation error
- `413` — File too large
- `500` — Server error

---

## List All Blogs

`GET /api/blogs`

Get all active blogs (excludes soft-deleted).

### Headers

| Header | Value |
|--------|-------|
| Content-Type | application/json |

### Response

```json
{
  "success": true,
  "data": [
    {
      "_id": "...",
      "name": "Dental Tips",
      "type": "dental",
      "relatedDescription": [
        {
          "_id": "...",
          "title": "Brushing Techniques",
          "description": "...",
          "imageUrl": "/blogs/12345.jpg"
        }
      ],
      "isDeleted": false
    }
  ]
}
```

### Errors

- `500` — Server error

---

## Get Blog By ID

`GET /api/blog/:id`

Get a specific blog by its ID.

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Blog MongoDB ObjectID |

### Response

```json
{
  "success": true,
  "data": {
    "_id": "...",
    "name": "Dental Tips",
    "type": "dental",
    "relatedDescription": [...],
    "isDeleted": false
  }
}
```

### Errors

- `500` — Server error

---

## Update Blog

`PUT /api/blog/:id`

Update a blog post. Accepts new images via multipart/form-data.

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Blog MongoDB ObjectID |

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| name | string | No | Blog title |
| type | string | No | Blog type — `face`, `body`, or `dental` |
| datas | string | No | JSON array of description objects |
| blog | file[] | No | Up to 5 images |

### Response

```json
{
  "success": true,
  "message": "Updated Blog Successfully",
  "data": {
    "_id": "...",
    "name": "Dental Tips Updated",
    "type": "dental"
  }
}
```

### Errors

- `400` — Validation error
- `404` — Blog not found
- `413` — File too large
- `500` — Server error

---

## Delete Blog

`DELETE /api/blog/:id`

Soft delete a blog (sets `isDeleted` to `true`).

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Blog MongoDB ObjectID |

### Response

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

### Errors

- `500` — Server error

---

## Add Description to Blog

`POST /api/blog/:id`

Add a description entry to an existing blog.

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Blog MongoDB ObjectID |

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| datas | string | Yes | JSON array of description objects |
| blog | file[] | No | Up to 5 images |

### Response

```json
{
  "success": true,
  "message": "Add Description Blog Successfully",
  "data": "..."
}
```

### Errors

- `500` — Server error

---

## Update Description

`PUT /api/blog-update/:id`

Update a specific description entry within a blog.

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Description MongoDB ObjectID |

### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| datas | string | Yes | JSON array of description objects |
| blog | file[] | No | Up to 5 images |

### Response

```json
{
  "success": true,
  "message": "Updated Description Successfully",
  "data": "..."
}
```

### Errors

- `500` — Server error

---

## Delete Description

`DELETE /api/blog-update/:id`

Soft delete a description entry within a blog.

### Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| id | string | Yes | Description MongoDB ObjectID |

### Response

```json
{
  "success": true,
  "message": "Deleted Description Successfully",
  "data": "..."
}
```

### Errors

- `500` — Server error

---

## Banner Photos

### List All Banner Photos

`GET /api/banner-photos`

Get all banner photos, optionally filtered by page.

#### Query Parameters

| Param | Type | Required | Description |
|-------|------|----------|-------------|
| page | string | No | Filter by page (`Home`, `About Us`, `Our Services`, `Promos`, `Testimonials`, `Activities`, `Blog`, `Contacts`) |

#### Response

```json
{
  "success": true,
  "data": [
    {
      "_id": "...",
      "type": "banner",
      "imgUrl": "https://cherryk.s3.ap-southeast.1.amazonaws.com/banners/1712345678900-banner.jpg",
      "page": "Home",
      "description": "Main hero banner",
      "isDeleted": false
    }
  ]
}
```

---

### Upload Banner Photos

`POST /api/banner-photos`

Upload one or more banner photos with page and optional description.

#### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| banners | file[] | Yes | Up to 5 images. Max 10MB each |
| page | string | Yes | Page identifier — one of: `Home`, `About Us`, `Our Services`, `Promos`, `Testimonials`, `Activities`, `Blog`, `Contacts` |
| description | string | No | Banner description |

#### Response

```json
{
  "success": true,
  "message": "Upload Banner Photos Successfully"
}
```

---

### Get Banner Photo By ID

`GET /api/banner-photo/:id`

---

### Edit Banner Photo

`PUT /api/banner-photo/:id`

Replace image and/or update page/description for a single banner photo.

#### Body (multipart/form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| banners | file | No | New image (replaces existing). Max 10MB |
| page | string | No | New page value |
| description | string | No | New description |

---

### Delete Banner Photo

`DELETE /api/banner-photo/:id`

Soft delete a banner photo.
