Files
smb-online/backoffice/docker-compose.yml
T
mivanchenko 2f6e0c1459 Availability engine + booking API: create/cancel/reschedule (#16)
Adds the plumbing that makes "can a customer actually get booked" true
end to end at the API layer, on top of #15's schema/tenancy layer.

- resource_hours table + min_notice_minutes/max_advance_days/buffer_minutes
  on resources -- config #15 didn't include but #16 depends on.
- availability.py: pure slot-generation function, correct across a
  Europe/Berlin DST transition (tested both directions).
- booking_api.py: JSON blueprint for slot listing, booking creation
  (auto_confirm -> confirmed/pending), and signed-JWT cancel/reschedule,
  registered into app.py.
- booking_db.py gains resource-hours CRUD, a tenant-scoped busy-bookings
  query for buffer/slot validation, and a read-only client lookup.

A true concurrent-threads test (not just sequential requests) surfaced a
real gap: Postgres can raise DeadlockDetected instead of ExclusionViolation
when two overlapping inserts race the exclusion constraint directly, which
went uncaught and would have 500'd instead of giving the clean 4xx the
ticket requires -- now caught alongside ExclusionViolation.

Also fixed: reschedule used the request's raw UTC offset to pick the
business day instead of the client's own timezone (could pick the wrong
day's hours/bookings near local midnight); the cancel/reschedule JWT no
longer falls back to reusing CRM_API_TOKEN as its signing secret.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-23 14:52:33 +02:00

45 lines
1.1 KiB
YAML

services:
smb-db:
image: postgres:16-alpine
container_name: smb-db
restart: unless-stopped
environment:
POSTGRES_DB: smbcrm
POSTGRES_USER: smbcrm
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- smb-db-data:/var/lib/postgresql/data
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
networks: [smb-net]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U smbcrm -d smbcrm"]
interval: 10s
timeout: 5s
retries: 5
smb-crm:
build: ./app
container_name: smb-crm
restart: unless-stopped
environment:
DATABASE_URL: postgresql://smbcrm:${DB_PASSWORD}@smb-db:5432/smbcrm
CRM_API_TOKEN: ${CRM_API_TOKEN}
BOOKING_TOKEN_SECRET: ${BOOKING_TOKEN_SECRET}
ICS_TOKEN: ${ICS_TOKEN}
SHEET_ID: ${SHEET_ID}
GOOGLE_SA_JSON: /run/secrets/gcp-sa.json
volumes:
- ./secrets/gcp-sa.json:/run/secrets/gcp-sa.json:ro
depends_on:
smb-db:
condition: service_healthy
networks: [smb-net, proxy]
volumes:
smb-db-data:
networks:
smb-net:
proxy:
external: true