From fe6beeded5361ddf06f9ed163830f9c4ddb5fd90 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 1 Jan 2026 17:40:57 -0400 Subject: [PATCH] feat(api): include booking URL in sync response Enhance the booking sync API to return the full booking URL in the response. The URL is constructed based on the request's scheme and host, supporting both HTTP and HTTPS, and uses the X-Forwarded-Proto header if present. This provides clients with a direct link to the created booking resource. --- internal/server/handle_api_sync.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/server/handle_api_sync.go b/internal/server/handle_api_sync.go index 1cec945..344ce3f 100644 --- a/internal/server/handle_api_sync.go +++ b/internal/server/handle_api_sync.go @@ -6,7 +6,9 @@ import ( "io" "log/slog" "net/http" + "strings" + "github.com/rjNemo/rentease/internal/constant" "github.com/rjNemo/rentease/internal/service/booking" ) @@ -38,9 +40,17 @@ func handleSync(bs *booking.Service) http.HandlerFunc { slog.Info("created booking from API", slog.String("name", b.Name), slog.String("platform", string(b.Platform))) + scheme := "http" + if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { + scheme = strings.TrimSpace(strings.Split(proto, ",")[0]) + } else if r.TLS != nil { + scheme = "https" + } + bookingURL := fmt.Sprintf("%s://%s%s/%d", scheme, r.Host, constant.RouteBooking, b.ID) + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode("👍"); err != nil { + if err := json.NewEncoder(w).Encode(fmt.Sprintf("👍 %s", bookingURL)); err != nil { slog.Error("failed to write response", slog.Any("error", err)) } }