Add dispatcher dashboard, simulated DispatchState and simple admin JSON APIs - #4
Add dispatcher dashboard, simulated DispatchState and simple admin JSON APIs#4Peter220101 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa9d26aa7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| $names = ['Carlos Mite', 'Ana Solis', 'Ricardo Cedeño', 'Marlon Vera', 'Jessica Ortiz', 'Luis Falconi', 'Pedro Villao', 'Diana Mendoza']; | ||
| $zones = ['Kennedy Norte', 'Urdesa', 'Ceibos', 'Centro', 'Mapasingue', 'Samanes', 'Alborada', 'Sauces']; | ||
|
|
||
| $maxId = max(array_column($state['drivers'], 'id')); |
There was a problem hiding this comment.
Guard empty driver list before computing next driver ID
In maybeAddDriver, calling max(array_column($state['drivers'], 'id')) crashes with a ValueError when the session starts with zero drivers (the seeded default). As soon as simulate_live_data is enabled and the 50% add-driver path is hit, api/state.php will return 500 and the dashboard polling breaks. Handle the empty-array case (e.g., seed from 0) before calling max().
Useful? React with 👍 / 👎.
| exit; | ||
| } | ||
|
|
||
| $action = $payload['action'] ?? 'create'; |
There was a problem hiding this comment.
Reject missing action instead of defaulting to create
For any non-GET request, the API defaults $action to 'create' when the client omits action. That means a malformed or empty write request (for example POST {}) silently inserts a new blank record, which mutates admin data unexpectedly. Mutating endpoints should require an explicit supported action and otherwise return a client error.
Useful? React with 👍 / 👎.
Motivation
users,vehiclesandreportsvia session storage.Description
dispatcher.phpthat renders a responsive UI, pollsapi/state.php, renders drivers/services/queues, and exposes an admin modal that interacts withapi/admin.php.app/DispatchState.phpwhich seeds, simulates and persists an in-memory dispatch state in the session and exposes metrics, drivers, services and zone queues.api/state.phpto return the current dispatch state and aggregated stats, andapi/admin.phpto provide simpleGET/create/update/deleteoperations against per-session demo data forusers,vehicles, andreports.config/dispatcher_config.phpwith options such asenable_google_maps,google_maps_api_key,polling_ms,max_drivers, andsimulate_live_data.Testing
php -land verified there were no parse errors.curl --silent --failagainstapi/state.phpandapi/admin.php?module=usersto confirm responses are200and valid JSON, and both checks succeeded.Codex Task