From 0465adbb360dd1b327e6f6bb6687353a1bce6f69 Mon Sep 17 00:00:00 2001 From: wood chen Date: Sat, 14 Jun 2025 19:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0UpdateEndpoint=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E4=BC=98=E5=8C=96=E5=AD=97=E6=AE=B5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D=E8=A6=86?= =?UTF-8?q?=E7=9B=96created=5Fat=E5=92=8Csort=5Forder=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E6=94=AF=E6=8C=81=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0sort=5Forder=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/endpoint_service.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/services/endpoint_service.go b/services/endpoint_service.go index 8c34718..b0ff820 100644 --- a/services/endpoint_service.go +++ b/services/endpoint_service.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "sync" + "time" ) // CachedEndpoint 缓存的端点数据 @@ -93,7 +94,22 @@ func (s *EndpointService) ListEndpoints() ([]*models.APIEndpoint, error) { // UpdateEndpoint 更新API端点 func (s *EndpointService) UpdateEndpoint(endpoint *models.APIEndpoint) error { - if err := database.DB.Save(endpoint).Error; err != nil { + // 只更新指定字段,避免覆盖 created_at 和 sort_order 等字段 + updates := map[string]interface{}{ + "name": endpoint.Name, + "url": endpoint.URL, + "description": endpoint.Description, + "is_active": endpoint.IsActive, + "show_on_homepage": endpoint.ShowOnHomepage, + "updated_at": time.Now(), + } + + // 如果 sort_order 不为 0,则更新它(0 表示未设置) + if endpoint.SortOrder != 0 { + updates["sort_order"] = endpoint.SortOrder + } + + if err := database.DB.Model(&models.APIEndpoint{}).Where("id = ?", endpoint.ID).Updates(updates).Error; err != nil { return fmt.Errorf("failed to update endpoint: %w", err) }