From d8479333371e3f921eb4076fb40a7be0b30c81d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=9C=E8=8F=AF?= Date: Sat, 27 May 2023 12:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=95=B8=E6=93=9A=E9=9B=86?= =?UTF-8?q?=E5=9C=96=E5=83=8F=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/datasets.go | 9 +++++++++ test.sh | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/routers/datasets.go b/routers/datasets.go index ac91efc..a224c2c 100644 --- a/routers/datasets.go +++ b/routers/datasets.go @@ -119,6 +119,15 @@ func DatasetsItemPatch(w http.ResponseWriter, r *http.Request) { if info, ok := form["info"].(string); ok { dataset.Info = info } + if images, ok := form["images"].([]interface{}); ok { + var image_list ImageList + for _, image := range images { + if image, ok := image.(string); ok { + image_list = append(image_list, image) + } + } + dataset.Images = image_list + } if err := configs.ORMDB().Save(&dataset).Error; err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("500 - Internal Server Error")) diff --git a/test.sh b/test.sh index 35bd194..c4ee3a3 100755 --- a/test.sh +++ b/test.sh @@ -46,7 +46,7 @@ echo "dataset_id: $dataset_id" # 修改數據集, images 中增加 url (PATCH /api/datasets/:id) -response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":[{"url":"https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"}]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id) +response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":["https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id) [[ ${response: -3} -eq 200 ]] && { echo "修改數據集成功: ${response%???}"; } || exit_service "修改數據集失敗: ${response%???}"