Files
dashboard-cpsp/backend/README.md
T

62 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# New Dashboard Backend
Greenfield Django 5 + Wagtail 6 + DRF API aligned to `ERD_dashboard.png`.
## Services
| Compose service | Role |
| --------------- | ------------------------------------------------ |
| `api` | Gunicorn on `:8000` |
| `cron` | Same image, runs management commands on schedule |
| `db` | Postgres 16 (`--profile prod`) |
## Quick start (local, no Docker)
From `dashboard-cpsp/backend`:
```bash
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # if needed
python manage.py migrate
python manage.py seed_demo
npm run dev
# or: python manage.py runserver 0.0.0.0:8000
```
Seed creates user `admin` / `admin123`, then seeds the default Sukawarna demo data — **Kandang 1** and **Kandang 2** closed cycles (49 days each, 22 May – 9 Jul 2026) with full daily records and IoT panels. A manager login `skw_manager` / `skw_manager123` is created too. It also prints a one-time API key.
## Docker Compose
From the project root (`dashboard-cpsp/`):
```bash
cp docker/.env.example .env
docker compose up -d --build
docker compose exec api python manage.py bootstrap_admin
```
Production bootstrap creates superadmin only (no demo cycles). Dev demo: `python manage.py seed_demo`.
See [../DOCKER.md](../DOCKER.md) for ports, cron, and troubleshooting.
## Auth
- **Session:** `POST /api/v1/auth/login/` then send session cookie + `X-CSRFToken` on writes
- **API key:** header `X-API-Key: <raw>` (hashed at rest)
- Public: `GET /api/v1/health/`
## External integrations
- karung-web-admin → `POST /api/v1/karungs/request/` (`KARUNG_WEB_ADMIN_BASE_URL`)
- Saldo Awal IoT compare → karung-web-admin `GET /api/combined`
## Docs
- Curl samples: [docs/API_CURL.md](../../docs/API_CURL.md)
- Postman: [docs/postman/](../../docs/postman/)
- OpenAPI UI: `http://localhost:8000/api/docs/`
- Wagtail admin: `http://localhost:8000/admin/`