GO: implement GET /api/v1/datasets/:dataset_id#14834
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new GET /api/v1/datasets/:dataset_id endpoint returns dataset metadata enriched with total document size and associated connectors via new DAO queries and service orchestration. ChangesFetch Dataset Details Endpoint
Sequence DiagramsequenceDiagram
participant Client
participant Handler
participant Service
participant DocumentDAO
participant ConnectorDAO
Client->>Handler: GET /datasets/:dataset_id
Handler->>Service: GetDataset(datasetID, userID)
Service->>Service: validate and check access
Service->>DocumentDAO: SumSizeByDatasetID(datasetID)
DocumentDAO-->>Service: total_size
Service->>ConnectorDAO: ListByDatasetID(datasetID)
ConnectorDAO-->>Service: [ConnectorDatasetListItem]
Service-->>Handler: enriched dataset map
Handler-->>Client: JSON response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/dao/connector.go (1)
69-73: ⚡ Quick winAdd deterministic ordering for connector list results.
Without
ORDER BY, connector order can vary across calls. Adding a stable sort (e.g., byconnector.id) avoids flaky UI/state diffs.Suggested diff
err := DB.Model(&entity.Connector2Kb{}). Select("connector.id, connector.source, connector.name, connector2kb.auto_parse, connector.status"). Joins("JOIN connector ON connector2kb.connector_id = connector.id"). Where("connector2kb.kb_id = ?", datasetID). + Order("connector.id ASC"). Scan(&connectors).Error🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/dao/connector.go` around lines 69 - 73, The query building in the connector retrieval (the DB.Model(&entity.Connector2Kb{}) ... Joins(...) Where(...) Scan(&connectors) call) lacks a deterministic ORDER BY, causing non‑stable connector lists; add an Order clause (e.g., Order("connector.id ASC") or Order("connector.id")) into that query chain before Scan so results are consistently sorted by connector.id.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/datasets.go`:
- Around line 532-539: Normalize and validate the incoming datasetID before
calling s.kbDAO.Accessible to avoid false permission failures: after trimming
(strings.TrimSpace(datasetID)) run the same normalization/validation used by
other dataset APIs (e.g., call the project’s dataset ID normalizer/validator
function) and if normalization yields an empty or invalid ID return the existing
error (Lack of "Dataset ID" / CodeDataError); only then call
s.kbDAO.Accessible(normalizedDatasetID, userID) so permission checks use the
canonical ID form.
---
Nitpick comments:
In `@internal/dao/connector.go`:
- Around line 69-73: The query building in the connector retrieval (the
DB.Model(&entity.Connector2Kb{}) ... Joins(...) Where(...) Scan(&connectors)
call) lacks a deterministic ORDER BY, causing non‑stable connector lists; add an
Order clause (e.g., Order("connector.id ASC") or Order("connector.id")) into
that query chain before Scan so results are consistently sorted by connector.id.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eca32ef3-2b8f-4e3c-81fa-37c1d34baea7
📒 Files selected for processing (5)
internal/dao/connector.gointernal/dao/document.gointernal/handler/datasets.gointernal/router/router.gointernal/service/datasets.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14834 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
implement GET /api/v1/datasets/:dataset_id
Type of change