# File Manager

# Attachment (Step by Step)

## A. Tambah Attachment

### Endpoint
- `POST /api/v1/file-manager/attachments/create`

### FE kirim request ini

```json
{
  "data": {
    "type": "file_manager_attachment_create",
    "attributes": {
      "file_id": "file-uuid",
      "ref_type": "helicopter",
      "ref_id": "business-entity-uuid",
      "category": "document",
      "sort_order": 0,
      "is_primary": false
    }
  }
}
```

Keterangan:
- `file_id`, `ref_type`, `ref_id` wajib
- `category` opsional
- `sort_order` opsional (default 0)
- `is_primary` opsional (default false)

## B. Lihat Attachment by Reference

### Endpoint
- `GET /api/v1/file-manager/attachments/get-all?ref_type=<type>&ref_id=<id>`

### Contoh
- `GET /api/v1/file-manager/attachments/get-all?ref_type=helicopter&ref_id=business-entity-uuid`

Catatan urutan default:
- jika query `sort` tidak dikirim, urutan default adalah `sort_order ASC, created_at DESC`
- artinya untuk `sort_order` yang sama, attachment terbaru tampil lebih dulu

## C. Detail Attachment

### Endpoint
- `GET /api/v1/file-manager/attachments/get/:uuid`

## D. Hapus Attachment (Detach)

### Endpoint
- `DELETE /api/v1/file-manager/attachments/delete/:uuid`

### Contoh response

```json
{
  "data": {
    "type": "file_manager_attachment_delete",
    "attributes": {
      "detached": true
    }
  }
}
```

## Ringkasan
1. create relation file -> entity bisnis
2. list by `ref_type + ref_id`
3. get detail relation
4. delete relation (detach)
