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 <noreply@anthropic.com>
This commit is contained in:
Patrick Britton 2026-02-17 16:33:37 -06:00
parent 8c62428556
commit 91ff0dc060
2 changed files with 9 additions and 9 deletions

View file

@ -418,9 +418,9 @@ func main() {
// Follow System (unique routes only — followers/following covered by users group above) // Follow System (unique routes only — followers/following covered by users group above)
followHandler := handlers.NewFollowHandler(dbPool) followHandler := handlers.NewFollowHandler(dbPool)
authorized.POST("/users/:userId/unfollow", followHandler.UnfollowUser) authorized.POST("/users/:id/unfollow", followHandler.UnfollowUser)
authorized.GET("/users/:userId/is-following", followHandler.IsFollowing) authorized.GET("/users/:id/is-following", followHandler.IsFollowing)
authorized.GET("/users/:userId/mutual-followers", followHandler.GetMutualFollowers) authorized.GET("/users/:id/mutual-followers", followHandler.GetMutualFollowers)
authorized.GET("/users/suggested", followHandler.GetSuggestedUsers) authorized.GET("/users/suggested", followHandler.GetSuggestedUsers)
// Notifications // Notifications

View file

@ -19,7 +19,7 @@ func NewFollowHandler(db *pgxpool.Pool) *FollowHandler {
// FollowUser — POST /users/:userId/follow // FollowUser — POST /users/:userId/follow
func (h *FollowHandler) FollowUser(c *gin.Context) { func (h *FollowHandler) FollowUser(c *gin.Context) {
userID := c.GetString("user_id") userID := c.GetString("user_id")
targetUserID := c.Param("userId") targetUserID := c.Param("id")
if userID == "" { if userID == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
@ -46,7 +46,7 @@ func (h *FollowHandler) FollowUser(c *gin.Context) {
// UnfollowUser — POST /users/:userId/unfollow // UnfollowUser — POST /users/:userId/unfollow
func (h *FollowHandler) UnfollowUser(c *gin.Context) { func (h *FollowHandler) UnfollowUser(c *gin.Context) {
userID := c.GetString("user_id") userID := c.GetString("user_id")
targetUserID := c.Param("userId") targetUserID := c.Param("id")
if userID == "" { if userID == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) 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 // IsFollowing — GET /users/:userId/is-following
func (h *FollowHandler) IsFollowing(c *gin.Context) { func (h *FollowHandler) IsFollowing(c *gin.Context) {
userID := c.GetString("user_id") userID := c.GetString("user_id")
targetUserID := c.Param("userId") targetUserID := c.Param("id")
if userID == "" { if userID == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) 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 // GetMutualFollowers — GET /users/:userId/mutual-followers
func (h *FollowHandler) GetMutualFollowers(c *gin.Context) { func (h *FollowHandler) GetMutualFollowers(c *gin.Context) {
userID := c.GetString("user_id") userID := c.GetString("user_id")
targetUserID := c.Param("userId") targetUserID := c.Param("id")
if userID == "" { if userID == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
@ -182,7 +182,7 @@ func (h *FollowHandler) GetSuggestedUsers(c *gin.Context) {
// GetFollowers — GET /users/:userId/followers // GetFollowers — GET /users/:userId/followers
func (h *FollowHandler) GetFollowers(c *gin.Context) { func (h *FollowHandler) GetFollowers(c *gin.Context) {
targetUserID := c.Param("userId") targetUserID := c.Param("id")
rows, err := h.db.Query(context.Background(), ` rows, err := h.db.Query(context.Background(), `
SELECT p.id, p.handle, p.display_name, p.avatar_url, f.created_at 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 // GetFollowing — GET /users/:userId/following
func (h *FollowHandler) GetFollowing(c *gin.Context) { func (h *FollowHandler) GetFollowing(c *gin.Context) {
targetUserID := c.Param("userId") targetUserID := c.Param("id")
rows, err := h.db.Query(context.Background(), ` rows, err := h.db.Query(context.Background(), `
SELECT p.id, p.handle, p.display_name, p.avatar_url, f.created_at SELECT p.id, p.handle, p.display_name, p.avatar_url, f.created_at