feat: add weekly schedule shifts and bulk departures
Build and Push Docker Images / detect-changes (push) Successful in 11s
Build and Push Docker Images / build-auth-api (push) Successful in 1m1s
Build and Push Docker Images / build-employee-api (push) Successful in 59s
Build and Push Docker Images / build-transit-api (push) Successful in 56s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m11s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m37s
Build and Push Docker Images / deploy-test-node (push) Successful in 5s
Build and Push Docker Images / detect-changes (push) Successful in 11s
Build and Push Docker Images / build-auth-api (push) Successful in 1m1s
Build and Push Docker Images / build-employee-api (push) Successful in 59s
Build and Push Docker Images / build-transit-api (push) Successful in 56s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m11s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m37s
Build and Push Docker Images / deploy-test-node (push) Successful in 5s
This commit is contained in:
+120
-26
@@ -4,66 +4,149 @@
|
||||
|
||||
The Transit API now includes a comprehensive schedule management system with both admin and public endpoints.
|
||||
|
||||
### Admin Endpoints (requires authentication + admin privileges)
|
||||
### Weekly Admin Endpoints (requires authentication + admin privileges)
|
||||
|
||||
The active admin UI uses weekly schedule templates. `dayOfWeek` follows the
|
||||
JavaScript/PostgreSQL convention: `0` Sunday, `1` through `5` weekdays, and `6`
|
||||
Saturday. Driver assignment is stored in `transit.shifts` and references
|
||||
`workers.users(id)`.
|
||||
|
||||
#### Get weekly schedules
|
||||
|
||||
#### Get all schedules
|
||||
```
|
||||
GET /admin/schedules
|
||||
GET /admin/weekly-schedules
|
||||
Response: { schedules: [...] }
|
||||
```
|
||||
|
||||
#### Create a schedule
|
||||
#### Get shift drivers
|
||||
|
||||
```
|
||||
GET /admin/shift-drivers
|
||||
Response: { drivers: [{ id, name }] }
|
||||
```
|
||||
|
||||
#### Create a weekly schedule
|
||||
|
||||
````
|
||||
|
||||
#### Create multiple departures
|
||||
|
||||
```text
|
||||
POST /admin/weekly-schedules/bulk
|
||||
Body: {
|
||||
busLineId: 1,
|
||||
dayOfWeeks: [1, 2, 3, 4, 5],
|
||||
startTimes: ["06:00", "06:30", "07:00"],
|
||||
driverId: 12
|
||||
}
|
||||
````
|
||||
|
||||
The API creates one schedule row for every day/time combination and derives the
|
||||
end time from the bus line's configured duration.
|
||||
POST /admin/weekly-schedules
|
||||
Body: {
|
||||
busLineId: 1,
|
||||
dayOfWeek: 1,
|
||||
startTime: "08:00",
|
||||
endTime: "09:00",
|
||||
driverId: 12
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
#### Replace a schedule's driver
|
||||
|
||||
```
|
||||
|
||||
PUT /admin/weekly-schedules/:scheduleId/shift
|
||||
Body: { driverId: 12 }
|
||||
|
||||
```
|
||||
|
||||
Use `{ "driverId": null }` to unassign the driver. The current `shifts` table
|
||||
does not contain a week/date column, so this is an active assignment rather than
|
||||
historical per-week assignment. Add `week_start` to support that later.
|
||||
|
||||
### Legacy Admin Endpoints
|
||||
|
||||
#### Get all schedules
|
||||
|
||||
```
|
||||
|
||||
GET /admin/schedules
|
||||
Response: { schedules: [...] }
|
||||
|
||||
```
|
||||
|
||||
#### Create a schedule
|
||||
|
||||
```
|
||||
|
||||
POST /admin/schedules
|
||||
Body: {
|
||||
busLineId: number,
|
||||
busId: number,
|
||||
driverId: number (optional),
|
||||
startTime: "2026-05-06T08:00:00",
|
||||
endTime: "2026-05-06T17:00:00"
|
||||
busLineId: number,
|
||||
busId: number,
|
||||
driverId: number (optional),
|
||||
startTime: "2026-05-06T08:00:00",
|
||||
endTime: "2026-05-06T17:00:00"
|
||||
}
|
||||
Response: { schedule: {...} }
|
||||
|
||||
```
|
||||
|
||||
#### Delete a schedule
|
||||
|
||||
```
|
||||
|
||||
DELETE /admin/schedules/:scheduleId
|
||||
Response: { success: true, schedule: {...} }
|
||||
|
||||
```
|
||||
|
||||
### Public Endpoints (no authentication required)
|
||||
|
||||
#### Get schedules (with optional filters)
|
||||
|
||||
```
|
||||
|
||||
GET /schedules?date=2026-05-06&lineId=1
|
||||
Query params:
|
||||
- date: YYYY-MM-DD (optional)
|
||||
- lineId: number (optional)
|
||||
Response: { schedules: [...] }
|
||||
|
||||
- date: YYYY-MM-DD (optional)
|
||||
- lineId: number (optional)
|
||||
Response: { schedules: [...] }
|
||||
|
||||
```
|
||||
|
||||
#### Get schedule detail
|
||||
|
||||
```
|
||||
|
||||
GET /schedules/:scheduleId
|
||||
Response: { schedule: {...} }
|
||||
|
||||
```
|
||||
|
||||
#### Get stops for a schedule's line
|
||||
|
||||
```
|
||||
|
||||
GET /schedules/:scheduleId/stops
|
||||
Response: { stops: [...] }
|
||||
Shows all stops on the bus line with order, location, and ETA.
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
## Admin UI Features
|
||||
|
||||
The ScheduleMaker component provides:
|
||||
|
||||
1. **Service Creation Form**
|
||||
- Select bus line, vehicle, date, and time
|
||||
- Optional driver ID assignment
|
||||
- Submit to create schedule
|
||||
- Admin-only access
|
||||
1. **Weekly schedule editor**
|
||||
|
||||
- Select a bus line and one of weekdays, Saturday, or Sunday
|
||||
- Define start and end times
|
||||
- Assign drivers through shifts
|
||||
- Admin-only access
|
||||
|
||||
2. **Timetable View**
|
||||
- 24-hour time slots (hourly grouping)
|
||||
@@ -86,12 +169,13 @@ The ScheduleMaker component provides:
|
||||
The TimetableViewer component provides a public-facing schedule display:
|
||||
|
||||
```jsx
|
||||
import TimetableViewer from './components/TimetableViewer'
|
||||
import TimetableViewer from "./components/TimetableViewer";
|
||||
|
||||
<TimetableViewer apiBaseUrl="http://api.transit.local:5001" />
|
||||
```
|
||||
<TimetableViewer apiBaseUrl="http://api.transit.local:5001" />;
|
||||
````
|
||||
|
||||
Features:
|
||||
|
||||
- Filter by date and bus line
|
||||
- Real-time loading state
|
||||
- Error handling
|
||||
@@ -104,6 +188,7 @@ Features:
|
||||
With `DEV_MOCK=1`, all schedule operations work in-memory without a database.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
ADMIN_USER_CODES=42 DEV_MOCK=1 JWT_SECRET=devsecret npm --prefix ./transit_api start
|
||||
```
|
||||
@@ -114,14 +199,19 @@ ADMIN_USER_CODES=42 DEV_MOCK=1 JWT_SECRET=devsecret npm --prefix ./transit_api s
|
||||
CREATE TABLE transit.schedules (
|
||||
id BIGINT PRIMARY KEY,
|
||||
bus_line_id BIGINT REFERENCES transit.bus_lines(id),
|
||||
bus_id BIGINT REFERENCES fleet.bus(id),
|
||||
driver_id INTEGER,
|
||||
start_time TIMESTAMP,
|
||||
end_time TIMESTAMP,
|
||||
start_time TIME,
|
||||
end_time TIME,
|
||||
status VARCHAR(20) DEFAULT 'planned',
|
||||
day_of_week SMALLINT NOT NULL CHECK (day_of_week BETWEEN 0 AND 6),
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE transit.shifts (
|
||||
id BIGINT PRIMARY KEY,
|
||||
schedule_id BIGINT REFERENCES transit.schedules(id) ON DELETE CASCADE,
|
||||
driver_id BIGINT REFERENCES workers.users(id)
|
||||
);
|
||||
```
|
||||
|
||||
## Styling & UX
|
||||
@@ -129,6 +219,7 @@ CREATE TABLE transit.schedules (
|
||||
The schedule manager uses:
|
||||
|
||||
### Admin Timetable Styling
|
||||
|
||||
- Responsive table with hourly time slots
|
||||
- Gradient schedule cards (blue/indigo theme)
|
||||
- Hover effects and smooth transitions
|
||||
@@ -137,6 +228,7 @@ The schedule manager uses:
|
||||
- Confirmation modals with semi-transparent overlay
|
||||
|
||||
### Public Timetable Styling
|
||||
|
||||
- Clean, simple table layout
|
||||
- Status badges (green for active, gray for planned)
|
||||
- Mobile-responsive with scrolling
|
||||
@@ -152,6 +244,7 @@ The schedule manager uses:
|
||||
## Example Usage
|
||||
|
||||
### Create a schedule (Admin)
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:5001/admin/schedules \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
@@ -166,11 +259,13 @@ curl -X POST http://localhost:5001/admin/schedules \
|
||||
```
|
||||
|
||||
### Get today's schedules (Public)
|
||||
|
||||
```bash
|
||||
curl http://localhost:5001/schedules?date=$(date +%Y-%m-%d)
|
||||
```
|
||||
|
||||
### Get schedules for specific line (Public)
|
||||
|
||||
```bash
|
||||
curl http://localhost:5001/schedules?lineId=3
|
||||
```
|
||||
@@ -184,4 +279,3 @@ curl http://localhost:5001/schedules?lineId=3
|
||||
- Schedule conflict detection
|
||||
- Integration with GPS tracking for actual vs scheduled times
|
||||
- Historical schedule analytics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user