# Product Edit/Delete Required (Master Data)

Dokumen ini untuk tim BE agar fitur **Edit** dan **Delete** di halaman Product Master berjalan real API.

## Masalah Saat Ini

Di FE, tombol edit/delete sudah aktif, tetapi BE endpoint belum siap penuh:

- `PUT /api/v1/products/:id` masih `501` / belum implementasi final
- `DELETE /api/v1/products/:id` belum ada route handler
- `GET /api/v1/products/:id` juga belum implementasi detail

Akibatnya:

- modal edit terbuka, tetapi simpan gagal
- delete gagal

## Endpoint yang Wajib Diimplementasi

## 1) Detail Product

`GET /api/v1/products/:id`

Response minimum:

```json
{
  "id": 1,
  "item_code": "VLRMC020006",
  "barcode": "91031102000601",
  "name": "ABSTRACT TROPICAL",
  "brand": "RYCROFT",
  "category": "VOLLEY SHORT",
  "size": "S",
  "collection": "2024 Q4",
  "is_consignment": true
}
```

## 2) Update Product

`PUT /api/v1/products/:id`

Payload minimum:

```json
{
  "item_code": "VLRMC020006",
  "barcode": "91031102000601",
  "name": "ABSTRACT TROPICAL",
  "brand": "RYCROFT",
  "category": "VOLLEY SHORT",
  "size": "S",
  "collection": "2024 Q4",
  "is_consignment": true
}
```

Behavior:

- update by id
- validasi unik `item_code`
- update `updated_at`

## 3) Delete Product

`DELETE /api/v1/products/:id`

Saran:

- soft delete (`is_active=false`) untuk keamanan audit.
- list endpoint default hanya tampilkan `is_active=true`.

Response contoh:

```json
{
  "message": "deleted"
}
```

## File BE yang Harus Diupdate

- `internal/server/http.go`
  - tambahkan route `DELETE /products/:id`
- `internal/modules/products/handler.go`
  - implement `Detail`, `Update`, dan `Delete`
- migration (jika belum ada):
  - pastikan `products` punya `updated_at`
  - optional `deleted_at` jika pakai soft delete advanced

## SQL Saran (soft delete sederhana)

Jika gunakan `is_active`:

```sql
UPDATE bazzar_pos.products
SET is_active = FALSE, updated_at = NOW()
WHERE id = $1;
```

Dan list query:

```sql
... FROM bazzar_pos.products
WHERE is_active = TRUE
  AND (...search condition...)
```

## Checklist Uji

1. Edit item dari FE -> `PUT` sukses -> reload list berubah.
2. Delete item -> hilang dari list.
3. Search/list tidak menampilkan item non-aktif.

