456ca3872f
Test backoffice (smb-crm) / test (push) Successful in 1m46s
Enables multiple barbers/staff bookable at the same location and time -- previously "resource" conflated "location" and "the thing that can't double-book itself" into one row, so a Filiale could only ever have exactly one bookable slot at once. - New `locations` table; `resources.location_id` with a generic, idempotent backfill migration (any resource without a location gets one auto-created matching its name -- not a one-off for any single client, protects any future resource stuck in the old flat shape too) - `resources`/`resource_hours`/services keep everything they already had (hours, min-notice, max-advance, buffer, the no-overlap constraint) scoped to resource_id, not location_id -- two barbers at one location must stay independently bookable at the same time - booking_db.py: new locations CRUD mirroring the existing resources/services pattern; create_resource now requires a location_id, guarded the same way every other tenant check here is (get_location existence check, no real FK -- matches this schema's existing no-FK convention throughout) - app.py: new POST /api/locations provisioning route; POST /api/resources now requires location_id - owner_settings.py + settings.html: new self-service "add a Filiale" / "add a barber" UI -- there was previously no way to create a resource at all outside the CRM/n8n provisioning API - public_booking.py + book.html: new Filiale picker (reuses the existing wireOptionGroup button-group pattern), filtering the Mitarbeiter picker to the selected location -- a single-location client sees no extra click, same as before Filialen existed - owner_booking.py + agenda.html: the Filiale show/hide toggle and hide-cancelled toggle (shipped earlier this session) now key off location_id instead of resource_id, so hiding a Filiale hides every barber's bookings at it; manual-booking dropdown grouped by Filiale - n8n/onboarding.json: default provisioning now creates a "Hauptfiliale" location before its resource (inert until re-imported into the live n8n instance) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
"""Public booking page blueprint (#17): the customer-facing /book/<slug> page,
|
|
embedded via iframe into a client's landing page. This route only resolves a
|
|
slug to a client and renders the slot-grid/booking-form page around it -- all
|
|
booking mutations still go through booking_api.py's JSON API (#16), which the
|
|
page's own JS calls via fetch.
|
|
|
|
IP rate limiting on these public routes is enforced at the Caddy layer (per
|
|
#17's acceptance criteria), not in Flask -- see deploy/booking/RATE_LIMIT.md
|
|
for the Caddy config to apply by hand on the homelab.
|
|
"""
|
|
from flask import Blueprint, abort, render_template, request
|
|
|
|
import booking_db as bdb
|
|
|
|
bp = Blueprint("public_booking", __name__)
|
|
|
|
DEFAULT_BRAND_COLOR = "#0f8a7e"
|
|
|
|
|
|
@bp.get("/book/<slug>")
|
|
def book_page(slug):
|
|
client = bdb.get_client_by_slug(slug)
|
|
if client is None:
|
|
abort(404)
|
|
client_id = client["client_id"]
|
|
locations = bdb.list_active_locations(client_id)
|
|
active_location_ids = {l["location_id"] for l in locations}
|
|
# A resource whose Filiale was deactivated shouldn't stay bookable even if
|
|
# the resource row itself is still active.
|
|
resources = [r for r in bdb.list_active_resources(client_id)
|
|
if r["location_id"] in active_location_ids]
|
|
services = bdb.list_active_services(client_id)
|
|
if not locations or not resources or not services:
|
|
# No bookable services/resources configured yet -- nothing to show a
|
|
# customer rather than a broken/empty booking form.
|
|
abort(404)
|
|
return render_template(
|
|
"book.html",
|
|
client_id=client_id,
|
|
business_name=client.get("business_name") or slug,
|
|
locations=[{"location_id": l["location_id"], "name": l["name"]} for l in locations],
|
|
resources=[{"resource_id": r["resource_id"], "name": r["name"],
|
|
"location_id": r["location_id"]} for r in resources],
|
|
services=[{"service_id": s["service_id"], "name": s["name"],
|
|
"duration_minutes": s["duration_minutes"],
|
|
"price": float(s["price"]) if s["price"] is not None else None}
|
|
for s in services],
|
|
brand_color=request.args.get("color") or DEFAULT_BRAND_COLOR,
|
|
)
|