From 12ed13b2d665032b9630e3b89acc49580c66f979 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Thu, 1 Jan 2026 18:35:59 +0000 Subject: [PATCH] fix: wrong sql query for drive listing --- apps/backend/internal/drexa/api_integration_test.go | 13 +++++++++++++ apps/backend/internal/drive/service.go | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/backend/internal/drexa/api_integration_test.go b/apps/backend/internal/drexa/api_integration_test.go index b6e484b..2ba49f3 100644 --- a/apps/backend/internal/drexa/api_integration_test.go +++ b/apps/backend/internal/drexa/api_integration_test.go @@ -103,6 +103,19 @@ func TestRegistrationFlow(t *testing.T) { t.Fatalf("expected account.id and drive.id to be set") } + t.Run("drives list", func(t *testing.T) { + var drives []struct { + ID string `json:"id"` + } + doJSON(t, s.app, http.MethodGet, "/api/drives", reg.AccessToken, nil, http.StatusOK, &drives) + if len(drives) != 1 { + t.Fatalf("expected 1 drive, got %d", len(drives)) + } + if drives[0].ID != reg.Drive.ID { + t.Fatalf("unexpected drive id: got %q want %q", drives[0].ID, reg.Drive.ID) + } + }) + t.Run("users/me", func(t *testing.T) { var me struct { ID string `json:"id"` diff --git a/apps/backend/internal/drive/service.go b/apps/backend/internal/drive/service.go index 8c615c4..d256738 100644 --- a/apps/backend/internal/drive/service.go +++ b/apps/backend/internal/drive/service.go @@ -87,10 +87,10 @@ func (s *Service) ListAccessibleDrives(ctx context.Context, db bun.IDB, orgID uu func (s *Service) ListDrivesForUser(ctx context.Context, db bun.IDB, userID uuid.UUID) ([]*Drive, error) { var drives []*Drive err := db.NewSelect().Model(&drives). - Join("JOIN accounts a ON a.org_id = drives.org_id"). + Join("JOIN accounts a ON a.org_id = drive.org_id"). Where("a.user_id = ?", userID). Where("a.status = ?", account.StatusActive). - Where("drives.owner_account_id IS NULL OR drives.owner_account_id = a.id"). + Where("drive.owner_account_id IS NULL OR drive.owner_account_id = a.id"). Scan(ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) {