From 91ff0dc060380eb7dd084b508568a5a96b1b4285 Mon Sep 17 00:00:00 2001 From: Patrick Britton Date: Tue, 17 Feb 2026 16:33:37 -0600 Subject: [PATCH] fix: resolve Gin route wildcard conflict (:userId vs :id) causing startup panic Routes POST /users/:userId/unfollow, GET /users/:userId/is-following, and GET /users/:userId/mutual-followers conflicted with /users/:id/* routes. Renamed :userId to :id and updated follow_handler.go accordingly. Co-Authored-By: Claude Sonnet 4.6 --- go-backend/cmd/api/main.go | 6 +++--- go-backend/internal/handlers/follow_handler.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go-backend/cmd/api/main.go b/go-backend/cmd/api/main.go index 4c783ac..f555612 100644 --- a/go-backend/cmd/api/main.go +++ b/go-backend/cmd/api/main.go @@ -418,9 +418,9 @@ func main() { // Follow System (unique routes only — followers/following covered by users group above) followHandler := handlers.NewFollowHandler(dbPool) - authorized.POST("/users/:userId/unfollow", followHandler.UnfollowUser) - authorized.GET("/users/:userId/is-following", followHandler.IsFollowing) - authorized.GET("/users/:userId/mutual-followers", followHandler.GetMutualFollowers) + authorized.POST("/users/:id/unfollow", followHandler.UnfollowUser) + authorized.GET("/users/:id/is-following", followHandler.IsFollowing) + authorized.GET("/users/:id/mutual-followers", followHandler.GetMutualFollowers) authorized.GET("/users/suggested", followHandler.GetSuggestedUsers) // Notifications diff --git a/go-backend/internal/handlers/follow_handler.go b/go-backend/internal/handlers/follow_handler.go index 702cfcc..19d7d05 100644 --- a/go-backend/internal/handlers/follow_handler.go +++ b/go-backend/internal/handlers/follow_handler.go @@ -19,7 +19,7 @@ func NewFollowHandler(db *pgxpool.Pool) *FollowHandler { // FollowUser — POST /users/:userId/follow func (h *FollowHandler) FollowUser(c *gin.Context) { userID := c.GetString("user_id") - targetUserID := c.Param("userId") + targetUserID := c.Param("id") if userID == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) @@ -46,7 +46,7 @@ func (h *FollowHandler) FollowUser(c *gin.Context) { // UnfollowUser — POST /users/:userId/unfollow func (h *FollowHandler) UnfollowUser(c *gin.Context) { userID := c.GetString("user_id") - targetUserID := c.Param("userId") + targetUserID := c.Param("id") if userID == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) @@ -67,7 +67,7 @@ func (h *FollowHandler) UnfollowUser(c *gin.Context) { // IsFollowing — GET /users/:userId/is-following func (h *FollowHandler) IsFollowing(c *gin.Context) { userID := c.GetString("user_id") - targetUserID := c.Param("userId") + targetUserID := c.Param("id") if userID == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) @@ -91,7 +91,7 @@ func (h *FollowHandler) IsFollowing(c *gin.Context) { // GetMutualFollowers — GET /users/:userId/mutual-followers func (h *FollowHandler) GetMutualFollowers(c *gin.Context) { userID := c.GetString("user_id") - targetUserID := c.Param("userId") + targetUserID := c.Param("id") if userID == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) @@ -182,7 +182,7 @@ func (h *FollowHandler) GetSuggestedUsers(c *gin.Context) { // GetFollowers — GET /users/:userId/followers func (h *FollowHandler) GetFollowers(c *gin.Context) { - targetUserID := c.Param("userId") + targetUserID := c.Param("id") rows, err := h.db.Query(context.Background(), ` SELECT p.id, p.handle, p.display_name, p.avatar_url, f.created_at @@ -219,7 +219,7 @@ func (h *FollowHandler) GetFollowers(c *gin.Context) { // GetFollowing — GET /users/:userId/following func (h *FollowHandler) GetFollowing(c *gin.Context) { - targetUserID := c.Param("userId") + targetUserID := c.Param("id") rows, err := h.db.Query(context.Background(), ` SELECT p.id, p.handle, p.display_name, p.avatar_url, f.created_at