# Import Products Processing Required (Why table still empty after import)

## Gejala

Di FE, setelah upload Excel muncul pesan sukses request import, tetapi tabel product tetap kosong.

## Akar Masalah (Backend)

Endpoint import saat ini:

- `POST /api/v1/import/products`

baru melakukan:

1. validasi file ada
2. insert record ke `bazzar_pos.import_jobs` dengan status `queued`
3. return:
   - `{"job_id":<id>,"status":"queued"}`

Namun **belum ada proses parsing Excel + insert/update ke `bazzar_pos.products`**.

Referensi file:

- `internal/modules/products/handler.go`
  - fungsi `Import` (hanya enqueue job, belum process data)

## Yang Harus Diimplementasi di BE

## 1) Parsing file import

Di `Import` handler atau worker terpisah:

- baca file excel/csv (`excelize`)
- map header:
  - `ITEM CODE`
  - `BARCODE`
  - `DESCRIPTION`
  - `BRAND`
  - `GENDER`
  - `FUNCTION`
  - `SIZE`
  - `COLLECTION`
  - `SELL PRICE`
  - `QTY STOCK`
  - `VALUE STOCK`
  - `HARGA PROMO`

## 2) Upsert product ke DB

Minimal upsert by `item_code`:

- insert jika belum ada
- update jika sudah ada

Tabel target:

- `bazzar_pos.products`

## 3) Update status import_jobs

Setelah proses:

- `status`: `success` / `failed`
- `total_rows`
- `success_rows`
- `failed_rows`
- `log_json` (error per row)

## 4) Endpoint cek status job

Tambahkan endpoint:

- `GET /api/v1/import/jobs/:id`

Response:

```json
{
  "id": 3,
  "status": "success",
  "total_rows": 1200,
  "success_rows": 1197,
  "failed_rows": 3,
  "errors": [
    { "row": 12, "message": "ITEM CODE kosong" }
  ]
}
```

## 5) Optional: async worker

Disarankan proses import async:

- endpoint hanya enqueue job
- worker goroutine/queue proses file
- FE poll `GET /import/jobs/:id` sampai status final

## Checklist Uji

1. Upload excel -> response `job_id` + `queued`
2. `GET /import/jobs/:id` berubah ke `processing` lalu `success`
3. `GET /api/v1/products` menampilkan item hasil import
4. Jika ada baris gagal, tersimpan di `log_json`

