From 4acd78988e9e6081b0e7094b0ae2484490709121 Mon Sep 17 00:00:00 2001 From: saani Date: Sun, 23 Nov 2025 12:20:05 +0000 Subject: [PATCH] refactor(api): replace hardcoded URLs with dynamic URL generation Replace hardcoded localhost URLs (http://127.0.0.1:8000) in API root endpoint documentation with request.build_absolute_uri() calls. This makes the API documentation URLs environment-agnostic and ensures they reflect the actual domain/host being used to access the API, improving portability across development, staging, and production environments. --- booking_system/views.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/booking_system/views.py b/booking_system/views.py index 4183912..6e1e8c2 100644 --- a/booking_system/views.py +++ b/booking_system/views.py @@ -105,7 +105,7 @@ def api_root(request, format=None): "endpoints": { "admin_availability": { "description": "Get or update admin weekly availability (Admin only)", - "url": "http://127.0.0.1:8000/api/meetings/admin/availability/", + "url": request.build_absolute_uri("/api/meetings/admin/availability/"), "methods": ["GET", "PUT", "PATCH"], "authentication": "Required (Staff users only)", "response_fields": { @@ -118,14 +118,14 @@ def api_root(request, format=None): }, "available_dates": { "description": "Get available appointment dates for the next 30 days (Public)", - "url": "http://127.0.0.1:8000/api/meetings/appointments/available-dates/", + "url": request.build_absolute_uri("/api/meetings/appointments/available-dates/"), "methods": ["GET"], "authentication": "None required", "response": "List of available dates in YYYY-MM-DD format" }, "create_appointment": { "description": "Create a new appointment request (Public)", - "url": "http://127.0.0.1:8000/api/meetings/appointments/create/", + "url": request.build_absolute_uri("/api/meetings/appointments/create/"), "methods": ["POST"], "authentication": "None required", "required_fields": [ @@ -146,7 +146,7 @@ def api_root(request, format=None): }, "list_appointments": { "description": "List appointment requests (Admin sees all, users see their own)", - "url": "http://127.0.0.1:8000/api/meetings/appointments/", + "url": request.build_absolute_uri("/api/meetings/appointments/"), "methods": ["GET"], "authentication": "Required", "query_parameters": { @@ -162,7 +162,7 @@ def api_root(request, format=None): }, "appointment_detail": { "description": "Get detailed information about a specific appointment", - "url": "http://127.0.0.1:8000/api/meetings/appointments//", + "url": request.build_absolute_uri("/api/meetings/appointments//"), "methods": ["GET"], "authentication": "Required", "url_parameter": "pk (UUID of the appointment)", @@ -170,14 +170,14 @@ def api_root(request, format=None): }, "user_appointments": { "description": "Get appointments for the authenticated user", - "url": "http://127.0.0.1:8000/api/meetings/user/appointments/", + "url": request.build_absolute_uri("/api/meetings/user/appointments/"), "methods": ["GET"], "authentication": "Required", "response": "List of user's appointment requests with Jitsi meeting details" }, "schedule_appointment": { "description": "Schedule an appointment and automatically create Jitsi meeting (Admin only)", - "url": "http://127.0.0.1:8000/api/meetings/appointments//schedule/", + "url": request.build_absolute_uri("/api/meetings/appointments//schedule/"), "methods": ["POST"], "authentication": "Required (Staff users only)", "required_fields": ["scheduled_datetime"], @@ -202,7 +202,7 @@ def api_root(request, format=None): }, "reject_appointment": { "description": "Reject an appointment request (Admin only)", - "url": "http://127.0.0.1:8000/api/meetings/appointments//reject/", + "url": request.build_absolute_uri("/api/meetings/appointments//reject/"), "methods": ["POST"], "authentication": "Required (Staff users only)", "optional_fields": ["rejection_reason"], @@ -219,7 +219,7 @@ def api_root(request, format=None): }, "jitsi_meeting_info": { "description": "Get Jitsi meeting information for a scheduled appointment", - "url": "http://127.0.0.1:8000/api/meetings/appointments//jitsi-meeting/", + "url": request.build_absolute_uri("/api/meetings/appointments//jitsi-meeting/"), "methods": ["GET"], "authentication": "Required", "prerequisites": "Appointment must be in 'scheduled' status", @@ -235,7 +235,7 @@ def api_root(request, format=None): }, "appointment_stats": { "description": "Get appointment statistics and analytics (Admin only)", - "url": "http://127.0.0.1:8000/api/meetings/appointments/stats/", + "url": request.build_absolute_uri("/api/meetings/appointments/stats/"), "methods": ["GET"], "authentication": "Required (Staff users only)", "response_fields": {