From 53aa54d6c92d7b2aa0a0dc7f92702457c9a657cb Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 22 Dec 2025 09:10:26 +0100 Subject: [PATCH] refactor(backend): clean up router registration pattern Issue #6: Multiple routers per file made main.py verbose. Changes: - Add 'routers' list export to booking.py and invites.py - Update main.py to iterate over router lists for multi-router modules - Keep explicit registration for single-router modules - Cleaner separation between simple and complex route modules --- backend/main.py | 13 +++++++------ backend/routes/booking.py | 4 ++++ backend/routes/invites.py | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/main.py b/backend/main.py index d942800..0ffe8c2 100644 --- a/backend/main.py +++ b/backend/main.py @@ -42,16 +42,17 @@ app.add_middleware( allow_credentials=True, ) -# Include routers +# Include routers - modules with single router app.include_router(auth_routes.router) app.include_router(sum_routes.router) app.include_router(counter_routes.router) app.include_router(audit_routes.router) app.include_router(profile_routes.router) -app.include_router(invites_routes.router) -app.include_router(invites_routes.admin_router) app.include_router(availability_routes.router) -app.include_router(booking_routes.router) -app.include_router(booking_routes.appointments_router) -app.include_router(booking_routes.admin_appointments_router) app.include_router(meta_routes.router) + +# Include routers - modules with multiple routers +for r in invites_routes.routers: + app.include_router(r) +for r in booking_routes.routers: + app.include_router(r) diff --git a/backend/routes/booking.py b/backend/routes/booking.py index b6185ee..d46342d 100644 --- a/backend/routes/booking.py +++ b/backend/routes/booking.py @@ -377,3 +377,7 @@ async def admin_cancel_appointment( await db.refresh(appointment) return _to_appointment_response(appointment) # Uses eager-loaded relationship + + +# All routers from this module for easy registration +routers = [router, appointments_router, admin_appointments_router] diff --git a/backend/routes/invites.py b/backend/routes/invites.py index 5a765e9..06722b4 100644 --- a/backend/routes/invites.py +++ b/backend/routes/invites.py @@ -231,3 +231,7 @@ async def revoke_invite( await db.refresh(invite) return build_invite_response(invite) + + +# All routers from this module for easy registration +routers = [router, admin_router]