# Dashboard beranda (Home) — data nyata & handoff BE

**Status FE (wire selesai):** `FE/pages/index.vue` memanggil API ringkas:

- `GET /api/v1/me`
- `GET /api/v1/me/summary?period=week&includeToday=1`
- `GET /api/v1/me/focus-preview`
- `GET /api/v1/me/activity`
- `GET /api/v1/analytics/trends?align=week` (opsional `days=…`)
- `GET /api/v1/teams` + `GET /api/v1/teams/:id/summary?period=week` (tim pertama)

**Polling** ~90 detik. Composable: `useWorkpulseMe`, `useWorkpulseAnalytics`, `useWorkpulseCalendar` (lihat repo FE).

**Catatan “real-time”:** BE tidak mengirim push khusus dashboard; FE memakai **polling** (lihat juga [`../FE/docs/BE_SPEC_DASHBOARD_HOME_REALTIME.md`](../FE/docs/BE_SPEC_DASHBOARD_HOME_REALTIME.md) jika ada).

**Daily Report (Kanban + JSON `body`):** [`BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md`](./BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md) — sumber utuh mirror: [`../FE/docs/BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md`](../FE/docs/BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md).

---

## Kontrak BE (repo ini)

Bagian di bawah mempertahankan **riwayat gap analysis** sebelum `focus-preview`, `includeToday`, `teams/:id/summary`, dan query `align=week` / `days` pada `analytics/trends` — banyak baris tabel “gap” sudah **tertutup** oleh implementasi terbaru.

---

## Endpoint yang diperluas / baru (implementasi)

### `GET /api/v1/me/summary?period=week|month|all`

| Query | Efek |
|--------|------|
| **`includeToday=1`** atau **`true`** | Field **`todayReport`**: `{ id, status, reportDate?, updatedAt }` atau **`null`**. Aturan: `report_date = CURRENT_DATE` **atau** (`report_date` null **dan** `created_at::date = CURRENT_DATE`), pilih terbaru `updated_at`. |

**“On time” / jam cut-off:** belum di BE; FE memetakan `status <> 'draft'` → “Submitted”.

### `GET /api/v1/me/focus-preview?limit=5`

- Notifikasi belum dibaca ∪ laporan **draft**, urut `at` DESC.
- Respons: `{ "items": [ { "type": "notification" \| "report", "id", "title", "subtitle", "at" } ] }` — `limit` default **5**, maks **20**.

### `GET /api/v1/teams/:id/summary?period=week|month|all`

- Anggota tim saja. Respons: `{ "teamId", "period", "reportsDraft", "reportsSubmitted", "reportsTotal" }` untuk **semua anggota** di periode yang sama dengan `me/summary`.

### `GET /api/v1/analytics/trends`

| Query | Default | Catatan |
|--------|---------|---------|
| **`days`** | `30` | `1`–`90`, sliding `r.created_at > NOW() - INTERVAL 'n days'`. |
| **`align=week`** | — | Minggu kalender saat ini (`date_trunc('week', …)`). Respons bisa berisi **`"align": "week"`**. |

Respons: **`reportsByDay`**, **`days`**, opsional **`align`**.

---

## Endpoint yang sudah ada (tanpa ubah kontrak utama)

| Endpoint | Kegunaan dashboard |
|----------|---------------------|
| `GET /api/v1/me` | `id`, `name`, `email`, `role`, `isActive`, … |
| `GET /api/v1/me/activity?limit=&offset=` | `items[]`: `type` `report` \| `notification`, `title`, `description`, `at` |
| `GET /api/v1/analytics/summary` | `reportsTotal`, `notificationsUnread` |
| `GET /api/v1/notifications` | Widget tambahan / daftar |
| `GET /api/v1/analytics/org/summary?period=` | **Superadmin** — KPI organisasi |

---

## Gap & usulan (riwayat / backlog produk)

| § | Topik | Status |
|---|--------|--------|
| 1 | Status hari ini / `todayReport` | **Ada** — `includeToday` pada `me/summary`. |
| 2 | Pending lintas anggota tim | **Ada** — `GET /teams/:id/summary`. |
| 3 | “Main blocker” | **Belum** — tidak ada kolom; `blockerResolutionPercent` org placeholder. |
| 4 | Attendance / velocity | **Belum** — tidak ada tabel; FE sembunyikan atau map ke metrik ada. |
| 5 | Grafik minggu | **Ada** — `analytics/trends?align=week` atau `days=7` + agregasi FE. |
| 6 | Focus Today | **Ada** — `me/focus-preview` (bukan hanya notifikasi mentah). |
| 7 | Team presence “online” | **Belum** — tidak ada sumber data. |

---

## Checklist implementasi (disarankan)

1. ~~FE wire ke `/me`, summary, activity, trends; polling~~ — sesuai status di atas.
2. ~~BE: `includeToday`~~ — selesai.
3. ~~BE: ringkasan tim~~ — selesai.
4. **Produk:** blocker, attendance, velocity — spesifikasi terpisah atau penyesuaian UI.

---

## File kode & dokumen

| Layer | Path |
|-------|------|
| UI | `FE/pages/index.vue` |
| BE me / focus | `internal/api/me.go` |
| BE teams / trends | `internal/api/rest.go` |
| BE router | `internal/api/router.go` |
| Kanban body | [`BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md`](./BE_SPEC_REPORT_KANBAN_BODY_SCHEMA.md) |

---

## Deploy

Tidak ada migrasi untuk fitur dashboard di atas. **Build** + **`pm2 restart workpulse-api`**.
