feat(go-api): migrate datasets tags aggregation API to Go (#16181)

### Description

Migrates the datasets tags aggregation API `GET
/api/v1/datasets/tags/aggregation` from Python to Go.

### Changes
- Registered the `GET /api/v1/datasets/tags/aggregation` route.
- Implemented `AggregateTags` in datasets `handler` and `service`.
- Added handler and service `unit tests`.

### Test Verification
- Verified by comparing results between Python (9380) and Go (9384)
services.
- Tested scenarios: single dataset, multiple datasets, empty parameters,
and unauthorized/invalid IDs.
- All tests and Go `unit tests` passed.
This commit is contained in:
Hz_
2026-06-24 14:42:10 +08:00
committed by GitHub
parent 68d2ca0ff1
commit 368db6fa58
5 changed files with 579 additions and 0 deletions

View File

@@ -592,6 +592,44 @@ func (h *DatasetsHandler) RemoveTags(c *gin.Context) {
jsonResponse(c, common.CodeSuccess, true, "success")
}
// AggregateTags handles GET /api/v1/datasets/tags/aggregation.
// @Summary Aggregate dataset tags
// @Description Aggregate tags across multiple datasets
// @Tags datasets
// @Produce json
// @Security ApiKeyAuth
// @Param dataset_ids query string true "Comma-separated dataset IDs"
// @Success 200 {object} map[string]interface{}
// @Router /api/v1/datasets/tags/aggregation [get]
func (h *DatasetsHandler) AggregateTags(c *gin.Context) {
user, errorCode, errorMessage := GetUser(c)
if errorCode != common.CodeSuccess {
jsonError(c, errorCode, errorMessage)
return
}
rawIDs := strings.Split(c.Query("dataset_ids"), ",")
datasetIDs := make([]string, 0, len(rawIDs))
for _, rawID := range rawIDs {
tempID := strings.TrimSpace(rawID)
if tempID != "" {
datasetIDs = append(datasetIDs, tempID)
}
}
if len(datasetIDs) == 0 {
jsonError(c, common.CodeDataError, "Lack of dataset_ids in query parameters")
return
}
result, code, err := h.datasetsService.AggregateTags(datasetIDs, user.ID)
if err != nil {
jsonError(c, code, err.Error())
return
}
jsonResponse(c, common.CodeSuccess, result, "success")
}
// RunIndex Run an indexing task (graph/raptor/mindmap) for a dataset.
func (h *DatasetsHandler) RunIndex(c *gin.Context) {
user, errorCode, errorMessage := GetUser(c)