Files
unsupervised-scheduler/docs/features/lesson-booking.md
James Griffin 0fbafc9d18
Some checks failed
CI / Coding Standards (push) Failing after 2m31s
CI / PHPStan (push) Failing after 50s
CI / Tests (PHP 8.1) (push) Successful in 50s
CI / Tests (PHP 8.2) (push) Successful in 48s
CI / Tests (PHP 8.3) (push) Successful in 40s
CI / No Debug Code (push) Successful in 2s
Initial plugin scaffold: lesson scheduling WordPress plugin
- Custom DB tables for availability slots and lesson bookings
- Instructor (wp-admin) and student (front-end) roles with custom capabilities
- REST API under us-scheduler/v1 for availability CRUD and booking
- [us_booking] and [us_student_login] shortcodes for student front end
- PHPUnit + Brain\Monkey unit test suite (29 tests)
- Gitea Actions CI: lint, PHPStan, tests on PHP 8.1/8.2/8.3, no-debug check
- Feature docs under docs/features/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 12:44:46 -03:00

53 lines
2.8 KiB
Markdown

# Feature: Lesson Booking
## Overview
Students browse available slots and submit a booking. Instructors then confirm or cancel from wp-admin or via the REST API.
## Data Model — `{prefix}us_lessons`
| Column | Type | Notes |
|----------------|------------------|--------------------------------------------------|
| `id` | BIGINT UNSIGNED | Primary key |
| `slot_id` | BIGINT UNSIGNED | FK → `us_availability.id` |
| `student_id` | BIGINT UNSIGNED | WordPress user ID |
| `instructor_id`| BIGINT UNSIGNED | WordPress user ID (denormalised for fast queries) |
| `status` | VARCHAR(20) | `pending` / `confirmed` / `cancelled` |
| `notes` | TEXT | Optional student notes |
| `created_at` | DATETIME | Insertion time |
## Booking Flow
1. Student opens the page with `[us_booking]` shortcode.
2. JS fetches `GET /availability` → renders available slots.
3. Student clicks **Book**`POST /bookings` with `slot_id`.
4. Server creates the lesson row (`status = pending`) and sets `us_availability.is_booked = 1`.
5. Instructor sees the booking under **My Lessons** in wp-admin.
6. Instructor updates status via `PATCH /bookings/{id}/status`.
## REST API
| Method | Endpoint | Permission |
|-----------|------------------------------------------------|-------------------------------|
| `GET` | `/wp-json/us-scheduler/v1/bookings` | Any logged-in user |
| `POST` | `/wp-json/us-scheduler/v1/bookings` | `book_lesson` |
| `PATCH` | `/wp-json/us-scheduler/v1/bookings/{id}/status`| `manage_availability` or admin |
`GET /bookings` returns the caller's own lessons (student view) or upcoming lessons for the instructor if the caller has `manage_availability`.
## Admin Interface
- **Scheduler** (`manage_options` only): all upcoming lessons across all instructors
- **My Lessons** (`view_own_lessons`): upcoming lessons for the logged-in instructor
## Frontend Shortcodes
- `[us_booking]` — student booking form; requires `book_lesson` capability
- `[us_student_login]` — front-end login form for students
## Implementation
- Repository: `Unsupervised\Schedular\Data\BookingRepository`
- Model: `Unsupervised\Schedular\Model\Lesson`
- Admin controller: `Unsupervised\Schedular\Admin\LessonController`
- REST endpoint: `Unsupervised\Schedular\Api\BookingEndpoint`
- Frontend: `Unsupervised\Schedular\Frontend\BookingPage`, `LoginPage`
## Tests
- `tests/Unit/Data/BookingRepositoryTest.php`
- `tests/Unit/Model/LessonTest.php`