Skip to content

Commit 6224497

Browse files
committed
fix(db): use correct context key 'user_id' in document handlers
The middleware sets c.Set("user_id", ...) but the /db/:collection handlers were reading c.GetString("userID") (camelCase mismatch), producing an empty user_id. POST/PUT/DELETE then failed with documents_user_id_fkey FK violations (23503), and GET silently returned []. Tests masked the bug because they pre-set the wrong key. Aligns with every other handler in the repo (auth, admin, buckets, analytics, quota, provisioning, mcp) which all use "user_id".
1 parent 2b00407 commit 6224497

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

internal/api/db/handlers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
3535
// CreateDoc creates a user document.
3636
// POST /db/:collection
3737
func (h *Handler) CreateDoc(c *gin.Context) {
38-
userID := c.GetString("userID")
38+
userID := c.GetString("user_id")
3939
collection := c.Param("collection")
4040

4141
var doc map[string]interface{}
@@ -57,7 +57,7 @@ func (h *Handler) CreateDoc(c *gin.Context) {
5757
// ListDocs lists user documents in a collection.
5858
// GET /db/:collection
5959
func (h *Handler) ListDocs(c *gin.Context) {
60-
userID := c.GetString("userID")
60+
userID := c.GetString("user_id")
6161
collection := c.Param("collection")
6262

6363
docs, err := h.Store.ListDocuments(userID, collection)
@@ -77,7 +77,7 @@ func (h *Handler) ListDocs(c *gin.Context) {
7777
// GetDoc gets a specific user document.
7878
// GET /db/:collection/:id
7979
func (h *Handler) GetDoc(c *gin.Context) {
80-
userID := c.GetString("userID")
80+
userID := c.GetString("user_id")
8181
collection := c.Param("collection")
8282
docID := c.Param("id")
8383

@@ -99,7 +99,7 @@ func (h *Handler) GetDoc(c *gin.Context) {
9999
// UpdateDoc updates a specific user document.
100100
// PUT /db/:collection/:id
101101
func (h *Handler) UpdateDoc(c *gin.Context) {
102-
userID := c.GetString("userID")
102+
userID := c.GetString("user_id")
103103
collection := c.Param("collection")
104104
docID := c.Param("id")
105105

@@ -126,7 +126,7 @@ func (h *Handler) UpdateDoc(c *gin.Context) {
126126
// DeleteDoc deletes a specific user document.
127127
// DELETE /db/:collection/:id
128128
func (h *Handler) DeleteDoc(c *gin.Context) {
129-
userID := c.GetString("userID")
129+
userID := c.GetString("user_id")
130130
collection := c.Param("collection")
131131
docID := c.Param("id")
132132

internal/api/db/handlers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func setupTestEnv(t *testing.T) (*Handler, storage.Provider, func()) {
3232

3333
func userMiddleware(userID string) gin.HandlerFunc {
3434
return func(c *gin.Context) {
35-
c.Set("userID", userID)
35+
c.Set("user_id", userID)
3636
c.Set("user_id", userID)
3737
c.Next()
3838
}

0 commit comments

Comments
 (0)