feat[Go]: implement /api/v1/connectors/<connector_id> PATCH (#15512)

### What problem does this PR solve?

As title, all test are passed

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
ちー
2026-06-02 19:34:07 +08:00
committed by GitHub
parent 9f969feb89
commit 5f8926410d
4 changed files with 245 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
package handler
import (
"encoding/json"
"errors"
"net/http"
"strconv"
@@ -37,6 +38,7 @@ type connectorServiceIface interface {
DeleteConnector(connectorID, userID string) (bool, common.ErrorCode, error)
RebuildConnector(connectorID, userID, kbID string) (bool, common.ErrorCode, error)
TestConnector(connectorID, userID string) error
UpdateConnector(connectorID, userID string, req *service.UpdateConnectorRequest) (*entity.Connector, common.ErrorCode, error)
}
// ConnectorHandler connector handler
@@ -133,6 +135,60 @@ func (h *ConnectorHandler) GetConnector(c *gin.Context) {
})
}
// UpdateConnector Update an accessible connector's polling configuration.
func (h *ConnectorHandler) UpdateConnector(c *gin.Context) {
user, errorCode, errorMessage := GetUser(c)
if errorCode != common.CodeSuccess {
jsonError(c, errorCode, errorMessage)
return
}
req, err := decodeUpdateConnectorRequest(c)
if err != nil {
jsonError(c, common.CodeBadRequest, err.Error())
return
}
connector, code, err := h.connectorService.UpdateConnector(c.Param("connector_id"), user.ID, req)
if err != nil {
jsonError(c, code, err.Error())
return
}
c.JSON(http.StatusOK, gin.H{
"code": common.CodeSuccess,
"data": connector,
"message": "success",
})
}
func decodeUpdateConnectorRequest(c *gin.Context) (*service.UpdateConnectorRequest, error) {
var raw map[string]json.RawMessage
if err := c.ShouldBindJSON(&raw); err != nil {
return nil, err
}
payload := raw
if dataRaw, ok := raw["data"]; ok {
var nested map[string]json.RawMessage
if err := json.Unmarshal(dataRaw, &nested); err == nil && nested != nil {
payload = nested
}
}
data, err := json.Marshal(payload)
if err != nil {
return nil, err
}
var req service.UpdateConnectorRequest
if err := json.Unmarshal(data, &req); err != nil {
return nil, err
}
return &req, nil
}
// ListLogs list connector sync logs.
// @Summary List Connector Logs
// @Description List sync logs for a connector the current user can access

View File

@@ -45,6 +45,13 @@ func (s fakeConnectorService) GetConnector(string, string) (*entity.Connector, c
return s.connector, common.CodeSuccess, nil
}
func (s fakeConnectorService) UpdateConnector(string, string, *service.UpdateConnectorRequest) (*entity.Connector, common.ErrorCode, error) {
if s.err != nil {
return nil, s.code, s.err
}
return s.connector, common.CodeSuccess, nil
}
func (s fakeConnectorService) ListLog(string, string, int, int) ([]*entity.ConnectorSyncLog, int64, common.ErrorCode, error) {
if s.err != nil {
return nil, 0, s.code, s.err