# One Pager New – API Documentation (cURL)

**Controller:** `App\Http\Controllers\OnePagerNewController`  
**Base URL:** `{{BASE_URL}}/api`  
**Auth:** JWT (`jwt.auth`, `check.token`, `dynamic.permission`)

**Replace in examples:**
- `{{BASE_URL}}` → e.g. `http://127.0.0.1:8000` or `https://your-domain.com`
- `{{JWT_TOKEN}}` → token from back-office login / refresh

| Action | Method | Route name | Endpoint |
|--------|--------|------------|----------|
| List / show | `GET` | `one-pager-new-index` | `one-pager-new/{id?}` |
| Create | `POST` | `one-pager-new-store` | `one-pager-new/store` |
| Update | `POST` | `one-pager-new-update` | `one-pager-new/update/{id}` |
| Download PDF | `GET` | `one-pager-new-download` | `one-pager-new/download/{id}/{language?}` |
| View PDF inline | `GET` | `one-pager-new-view` | `one-pager-new/view/{id}/{language?}` |
| Delete | `DELETE` | `one-pager-new-delete` | `one-pager-new/delete/{id}` |
| Instrument dropdown (helper) | `GET` | `all-security-codes` | `mkt-security-code/all-security-codes` |

**Notes:**
- `security_code` is a **single** instrument code (string), not an array.
- `company_name` is required on store/update (frontend can load it from `all-security-codes`).
- `sector`, `color`, `slug` are optional strings.
- At least one of EN / BN title + matching PDF is required.
- PDF max size: **5 MB** (`mimes:pdf`).
- Not used in this module: `article_text`, `version`, `language`.

---

## 0. Instrument dropdown (load company name)

| Item | Value |
|------|--------|
| **Method** | `GET` |
| **URL** | `{{BASE_URL}}/api/mkt-security-code/all-security-codes` |
| **Auth** | `api` middleware (no JWT on this route) |

### cURL

```bash
curl --location --request GET '{{BASE_URL}}/api/mkt-security-code/all-security-codes' \
--header 'Accept: application/json'
```

### Sample response

```json
[
  {
    "id": 1,
    "security_code": "SQURPHARMA",
    "company_name": "Square Pharmaceuticals PLC"
  }
]
```

---

## 1. List / show – `index`

| Item | Value |
|------|--------|
| **Method** | `GET` |
| **URL** | `{{BASE_URL}}/api/one-pager-new` or `{{BASE_URL}}/api/one-pager-new/{id}` |
| **Auth** | Bearer JWT |

### Query

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `per_page` | int | No | Default `10`, max `100` |
| `id` (path) | int | No | When set, filters to that article |

### cURL – list

```bash
curl --location --request GET '{{BASE_URL}}/api/one-pager-new?per_page=10' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}'
```

### cURL – show by id

```bash
curl --location --request GET '{{BASE_URL}}/api/one-pager-new/1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}'
```

### Sample success (200)

```json
{
  "status": true,
  "data": [
    {
      "id": 1,
      "reporting_date": "2026-08-17",
      "security_code": "SQURPHARMA",
      "company_name": "Square Pharmaceuticals PLC",
      "sector": "Pharmaceuticals",
      "color": "#1A73E8",
      "slug": null,
      "article_title": "Q2 One Pager",
      "article_title_bn": null,
      "article_type": "blue",
      "article_type_bn": null,
      "pdf_file": "uploads/onePagerEn/....pdf",
      "pdf_file_bn": null,
      "created_by": 12,
      "updated_by": null,
      "created_at": "2026-08-17 13:00:00",
      "updated_at": "2026-08-17 13:00:00"
    }
  ],
  "pagination": {
    "current_page": 1,
    "last_page": 1,
    "per_page": 10,
    "total": 1
  }
}
```

---

## 2. Create – `store`

| Item | Value |
|------|--------|
| **Method** | `POST` |
| **URL** | `{{BASE_URL}}/api/one-pager-new/store` |
| **Auth** | Bearer JWT |
| **Body** | `multipart/form-data` |

### Body (form-data)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `reporting_date` | date | Yes | e.g. `2026-08-17` |
| `security_code` | string | Yes | Must exist in `mkt_security_code.security_code` |
| `company_name` | string | Yes | Usually filled from dropdown |
| `sector` | string | No | Free text, max 64 |
| `color` | string | No | Free text / hex, max 64 |
| `slug` | string | No | Optional, max 255 |
| `article_title` | string | One of EN/BN title | English title |
| `article_title_bn` | string | One of EN/BN title | Bangla title |
| `article_type` | string | One of EN/BN type | English type |
| `article_type_bn` | string | One of EN/BN type | Bangla type |
| `pdf_file` | file | Required with EN title | English PDF |
| `pdf_file_bn` | file | Required with BN title | Bangla PDF |

### cURL

```bash
curl --location --request POST '{{BASE_URL}}/api/one-pager-new/store' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--form 'reporting_date="2026-08-17"' \
--form 'security_code="SQURPHARMA"' \
--form 'company_name="Square Pharmaceuticals PLC"' \
--form 'sector="Pharmaceuticals"' \
--form 'color="#1A73E8"' \
--form 'slug=""' \
--form 'article_title="Q2 One Pager"' \
--form 'article_type="blue"' \
--form 'pdf_file=@"/path/to/onepager_en.pdf"'
```

### With both EN + BN

```bash
curl --location --request POST '{{BASE_URL}}/api/one-pager-new/store' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--form 'reporting_date="2026-08-17"' \
--form 'security_code="SQURPHARMA"' \
--form 'company_name="Square Pharmaceuticals PLC"' \
--form 'sector="Pharmaceuticals"' \
--form 'color="#1A73E8"' \
--form 'article_title="Q2 One Pager"' \
--form 'article_title_bn="কিউ২ ওয়ান পেজার"' \
--form 'article_type="blue"' \
--form 'article_type_bn="নীল"' \
--form 'pdf_file=@"/path/to/onepager_en.pdf"' \
--form 'pdf_file_bn=@"/path/to/onepager_bn.pdf"'
```

### Sample success (201)

```json
{
  "status": true,
  "message": "One-pager article created successfully",
  "data": {
    "id": 1,
    "reporting_date": "2026-08-17",
    "security_code": "SQURPHARMA",
    "company_name": "Square Pharmaceuticals PLC",
    "sector": "Pharmaceuticals",
    "color": "#1A73E8",
    "slug": null,
    "article_title": "Q2 One Pager",
    "article_title_bn": null,
    "article_type": "blue",
    "article_type_bn": null,
    "pdf_file": "uploads/onePagerEn/....pdf",
    "pdf_file_bn": null,
    "created_by": 12,
    "updated_by": null,
    "created_at": "2026-08-17 13:00:00",
    "updated_at": "2026-08-17 13:00:00"
  }
}
```

---

## 3. Update – `update`

| Item | Value |
|------|--------|
| **Method** | `POST` |
| **URL** | `{{BASE_URL}}/api/one-pager-new/update/{id}` |
| **Auth** | Bearer JWT |
| **Body** | `multipart/form-data` |

Same fields as create. PDF files are optional if an existing file already covers that language/title pair.

### cURL

```bash
curl --location --request POST '{{BASE_URL}}/api/one-pager-new/update/1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--form 'reporting_date="2026-08-17"' \
--form 'security_code="SQURPHARMA"' \
--form 'company_name="Square Pharmaceuticals PLC"' \
--form 'sector="Pharmaceuticals"' \
--form 'color="#0B57D0"' \
--form 'article_title="Q2 One Pager Updated"' \
--form 'article_type="blue"' \
--form 'pdf_file=@"/path/to/onepager_en_updated.pdf"'
```

---

## 4. Download PDF – `download`

| Item | Value |
|------|--------|
| **Method** | `GET` |
| **URL** | `{{BASE_URL}}/api/one-pager-new/download/{id}/{language}` |
| **Auth** | Bearer JWT |
| **language** | `en` or `bn` (required) |

### cURL

```bash
curl --location --request GET '{{BASE_URL}}/api/one-pager-new/download/1/en' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--output onepager_en.pdf
```

```bash
curl --location --request GET '{{BASE_URL}}/api/one-pager-new/download/1/bn' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--output onepager_bn.pdf
```

---

## 5. View PDF inline – `view`

| Item | Value |
|------|--------|
| **Method** | `GET` |
| **URL** | `{{BASE_URL}}/api/one-pager-new/view/{id}/{language?}` |
| **Auth** | Bearer JWT |
| **language** | `en` / `bn` (optional; if omitted, prefers EN then BN) |

### cURL

```bash
curl --location --request GET '{{BASE_URL}}/api/one-pager-new/view/1/en' \
--header 'Authorization: Bearer {{JWT_TOKEN}}' \
--output - > onepager_inline.pdf
```

---

## 6. Delete – `destroy`

| Item | Value |
|------|--------|
| **Method** | `DELETE` |
| **URL** | `{{BASE_URL}}/api/one-pager-new/delete/{id}` |
| **Auth** | Bearer JWT |

### cURL

```bash
curl --location --request DELETE '{{BASE_URL}}/api/one-pager-new/delete/1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{JWT_TOKEN}}'
```

### Sample success (200)

```json
{
  "status": true,
  "message": "One-pager article deleted successfully"
}
```

---

## Common errors

| Status | When |
|--------|------|
| `401` / `403` | Missing/invalid JWT or no route permission |
| `404` | Article / PDF not found |
| `422` | Validation failed (missing title/PDF, invalid `security_code`, etc.) |
| `500` | Server / storage error |
)
