Register a company, log in as it, then create a branch beneath it and register users against either — each identified by their cell number — then check them in and out with a real photo upload. Every step below runs against this running server, in order. Responses appear inline; IDs are captured automatically.
| Endpoint | What it does |
|---|---|
| POST /api/v1/companies | Register a company: full_name (the person), name, email, phone, password and terms_and_conditions. slug is derived from name when omitted; duplicates return 409. Open for a standalone company. With parent_id it adds a branch instead, which asks for none of the sign-up fields and requires logging in as that parent. |
| POST /api/v1/auth/login | Log in as a company with slug + password. Returns a bearer token. |
| POST /api/v1/auth/token | Same, as an OAuth2 form (username = slug) for Swagger's Authorize button. |
| GET /api/v1/auth/me | The company the token belongs to. |
| GET /api/v1/companies | Paginated list. Filters: search, is_active, parent_id, only_main, limit, offset. |
| GET /api/v1/companies/{id}/sub-companies | The companies directly beneath this one. |
| GET /api/v1/companies/{id} | Fetch one company. |
| PATCH /api/v1/companies/{id} | Partial update. Send location: null or "" to clear it. |
| DELETE /api/v1/companies/{id} | Delete the company and cascade to its users. 204. |
| POST /api/v1/companies/{id}/users | Register a user. phone identifies them within the company; duplicates return 409. |
| GET /api/v1/companies/{id}/users/by-phone | Resolve a user by cell number (?phone=). 404 if no match. |
| GET /api/v1/companies/{id}/users | That company's users. include_sub_companies=true rolls up the branches. |
| POST /api/v1/users/register | Same as above but company_id travels in the body. |
| GET /api/v1/users | All users; optional company_id filter, search matches phone/email/name. |
| GET /api/v1/users/roles | The accepted role values, with descriptions and which one is the default. |
| GET /api/v1/users/{id} | Fetch one user. |
| PATCH /api/v1/users/{id} | Update phone, email, name, role, active flag or password. |
| DELETE /api/v1/users/{id} | Delete a user. 204. |
| Check-in / check-out | |
| POST /api/v1/users/{id}/check-in | Open a shift. Optional latitude, longitude, photo_url, note. 409 if already checked in. |
| POST /api/v1/users/{id}/check-out | Close the open shift, with its own coordinates and photo. 409 if not checked in. |
| GET /api/v1/users/{id}/attendance/current | The user's open shift, or 404. |
| GET /api/v1/users/{id}/attendance | That user's shift history. |
| GET /api/v1/companies/{id}/attendance | The company's table. Filters: user_id, is_open, checked_in_from, checked_in_to, include_sub_companies. |
| GET /api/v1/attendance/{id} | One attendance record. |
| GET /api/v1/companies/{id}/storage | The bucket this company's photos go to, and whether it exists. |
| Incident reports | |
| POST /api/v1/users/{id}/incidents | Report an incident. message required, photo optional. 400 if the user is inactive. |
| GET /api/v1/users/{id}/incidents | That user's reports, newest first. Filters status, has_photo. |
| GET /api/v1/companies/{id}/incidents | The company's log. Filters: user_id, status, search, has_photo, reported_from, reported_to, include_sub_companies. |
| GET /api/v1/incidents/statuses | The accepted status values, and which one a new report starts in. |
| GET /api/v1/incidents/{id} | One incident report. |
| PATCH /api/v1/incidents/{id} | Update the message, or close / reopen it. Closing records who did it. Needs a company login. |
| GET /health/storage | MinIO readiness probe. |
+27 82 123 4567, (+27) 82-123-4567 and 27821234567
are one and the same. A number in national format (leading 0) is rejected with a 422,
because it cannot be resolved without knowing the country.email is optional and carries no uniqueness constraint — two users may share one,
or have none at all.parent_id when creating one to put it under a main company. The tree stops
at two levels, enforced by a composite foreign key in Postgres — the same constraint blocks a
company becoming its own parent, and blocks demoting a main company that still has branches.include_sub_companies=true for a whole-group view.checked_out_at NULL; check-out fills in the closing half. So
is_open means "on site", and duration_seconds is available the
moment the shift closes.{} is a valid check-in. Supplying a latitude without a longitude is a 422.multipart/form-data, not JSON, because they carry a file.<MINIO_BUCKET_PREFIX>-<company slug> — by default
checkin-checkout-acme-industries. The bucket is created on first upload.
The record stores the bucket and object key; the bucket itself is recorded per row, so
renaming a company cannot orphan its old photos.MINIO_URL_EXPIRY_SECONDS, 15 minutes by default) — it is regenerated on
every read, so do not store it. An unsigned request for the same object gets a 403.Content-Type, so a text file renamed .png is still rejected.
JPEG, PNG, GIF, WebP and HEIC are accepted, up to MAX_PHOTO_BYTES.owner, admin, member. Default is member.PATCH /api/v1/incidents/{id}. Closing stamps closed_at, records the closing
company as closed_by_company_id + closed_by_name, and can carry a
resolution; it never removes the message, photo or reporter. Reopening clears all of it again.
status and closed_at are kept in agreement by a check constraint, so a closed
report always has a closing time and an open one never does.closed_by_name is a copy, not a join. It is the company's name as it read at the moment
of closing, so renaming the company does not rewrite old log entries, and deleting it nulls
closed_by_company_id while the name stays on record.Authorization: Bearer <token> from /auth/login. No token is a 401;
a token for a company that does not own the target is a 403.