# 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`